3
3
// Distributed under the MIT software license, see the accompanying
4
4
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
5
5
6
+ #include < sync.h>
6
7
#include < util/system.h>
7
8
8
9
#include < chainparamsbase.h>
@@ -75,18 +76,18 @@ const char * const BITCOIN_CONF_FILENAME = "bitcoin.conf";
75
76
76
77
ArgsManager gArgs ;
77
78
79
+ /* * Mutex to protect dir_locks. */
80
+ static Mutex cs_dir_locks;
78
81
/* * A map that contains all the currently held directory locks. After
79
82
* successful locking, these will be held here until the global destructor
80
83
* cleans them up and thus automatically unlocks them, or ReleaseDirectoryLocks
81
84
* is called.
82
85
*/
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);
86
87
87
88
bool LockDirectory (const fs::path& directory, const std::string lockfile_name, bool probe_only)
88
89
{
89
- std::lock_guard<std::mutex> ulock (cs_dir_locks);
90
+ LOCK (cs_dir_locks);
90
91
fs::path pathLockFile = directory / lockfile_name;
91
92
92
93
// 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
110
111
111
112
void UnlockDirectory (const fs::path& directory, const std::string& lockfile_name)
112
113
{
113
- std::lock_guard<std::mutex> lock (cs_dir_locks);
114
+ LOCK (cs_dir_locks);
114
115
dir_locks.erase ((directory / lockfile_name).string ());
115
116
}
116
117
117
118
void ReleaseDirectoryLocks ()
118
119
{
119
- std::lock_guard<std::mutex> ulock (cs_dir_locks);
120
+ LOCK (cs_dir_locks);
120
121
dir_locks.clear ();
121
122
}
122
123
0 commit comments