Skip to content

Commit e685ca1

Browse files
committed
util/system.cpp: add thread safety annotations for dir_locks
1 parent a788789 commit e685ca1

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

src/util/system.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// Distributed under the MIT software license, see the accompanying
44
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
55

6+
#include <sync.h>
67
#include <util/system.h>
78

89
#include <chainparamsbase.h>
@@ -75,18 +76,18 @@ const char * const BITCOIN_CONF_FILENAME = "bitcoin.conf";
7576

7677
ArgsManager gArgs;
7778

79+
/** Mutex to protect dir_locks. */
80+
static Mutex cs_dir_locks;
7881
/** A map that contains all the currently held directory locks. After
7982
* successful locking, these will be held here until the global destructor
8083
* cleans them up and thus automatically unlocks them, or ReleaseDirectoryLocks
8184
* is called.
8285
*/
83-
static std::map<std::string, std::unique_ptr<fsbridge::FileLock>> dir_locks;
84-
/** Mutex to protect dir_locks. */
85-
static std::mutex cs_dir_locks;
86+
static std::map<std::string, std::unique_ptr<fsbridge::FileLock>> dir_locks GUARDED_BY(cs_dir_locks);
8687

8788
bool LockDirectory(const fs::path& directory, const std::string lockfile_name, bool probe_only)
8889
{
89-
std::lock_guard<std::mutex> ulock(cs_dir_locks);
90+
LOCK(cs_dir_locks);
9091
fs::path pathLockFile = directory / lockfile_name;
9192

9293
// If a lock for this directory already exists in the map, don't try to re-lock it
@@ -110,13 +111,13 @@ bool LockDirectory(const fs::path& directory, const std::string lockfile_name, b
110111

111112
void UnlockDirectory(const fs::path& directory, const std::string& lockfile_name)
112113
{
113-
std::lock_guard<std::mutex> lock(cs_dir_locks);
114+
LOCK(cs_dir_locks);
114115
dir_locks.erase((directory / lockfile_name).string());
115116
}
116117

117118
void ReleaseDirectoryLocks()
118119
{
119-
std::lock_guard<std::mutex> ulock(cs_dir_locks);
120+
LOCK(cs_dir_locks);
120121
dir_locks.clear();
121122
}
122123

0 commit comments

Comments
 (0)