MCPcopy Create free account
hub / github.com/BTCGPU/BTCGPU / LockDirectory

Function LockDirectory

src/util.cpp:148–175  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

146static std::mutex cs_dir_locks;
147
148bool LockDirectory(const fs::path& directory, const std::string lockfile_name, bool probe_only)
149{
150 std::lock_guard<std::mutex> ulock(cs_dir_locks);
151 fs::path pathLockFile = directory / lockfile_name;
152
153 // If a lock for this directory already exists in the map, don't try to re-lock it
154 if (dir_locks.count(pathLockFile.string())) {
155 return true;
156 }
157
158 // Create empty lock file if it doesn't exist.
159 FILE* file = fsbridge::fopen(pathLockFile, "a");
160 if (file) fclose(file);
161
162 try {
163 auto lock = MakeUnique<boost::interprocess::file_lock>(pathLockFile.string().c_str());
164 if (!lock->try_lock()) {
165 return false;
166 }
167 if (!probe_only) {
168 // Lock successful and we're not just probing, put it into the map
169 dir_locks.emplace(pathLockFile.string(), std::move(lock));
170 }
171 } catch (const boost::interprocess::interprocess_exception& e) {
172 return error("Error while attempting to lock directory %s: %s", directory.string(), e.what());
173 }
174 return true;
175}
176
177void ReleaseDirectoryLocks()
178{

Callers 5

LockDataDirectoryFunction · 0.85
OpenMethod · 0.85
TestOtherThreadFunction · 0.85
TestOtherProcessFunction · 0.85
BOOST_AUTO_TEST_CASEFunction · 0.85

Calls 4

fopenFunction · 0.85
errorFunction · 0.85
whatMethod · 0.80
countMethod · 0.45

Tested by 3

TestOtherThreadFunction · 0.68
TestOtherProcessFunction · 0.68
BOOST_AUTO_TEST_CASEFunction · 0.68