mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-10 22:18:54 +01:00
Merge #16127: More thread safety annotation coverage
5478d6c099logging: thread safety annotations (Anthony Towns)e685ca1992util/system.cpp: add thread safety annotations for dir_locks (Anthony Towns)a788789948test/checkqueue_tests: thread safety annotations (Anthony Towns)479c5846f7rpc/blockchain.cpp: thread safety annotations for latestblock (Anthony Towns)8b5af3d4c1net: fMsgProcWake use LOCK instead of lock_guard (Anthony Towns)de7c5f41abwallet/wallet.h: Remove mutexScanning which was only protecting a single atomic bool (Anthony Towns)c3cf2f5501rpc/blockchain.cpp: Remove g_utxosetscan mutex that is only protecting a single atomic variable (Anthony Towns) Pull request description: In a few cases we need to use `std::mutex` rather than the sync.h primitives. But `std::lock_guard<std::mutex>` doesn't include the clang thread safety annotations unless you also use clang's C library, which means you can't indicate when variables should be guarded by `std::mutex` mutexes. This adds an annotated version of `std::lock_guard<std::mutex>` to threadsafety.h to fix that, and modifies places where `std::mutex` is used to take advantage of the annotations. It's based on top of #16112, and turns the thread safety comments included there into annotations. It also changes the RAII classes in wallet/wallet.h and rpc/blockchain.cpp to just use the atomic<bool> flag for synchronisation rather than having a mutex that doesn't actually guard anything as well. ACKs for top commit: MarcoFalke: ACK5478d6c099🗾 hebasto: re-ACK5478d6c099, only renamed s/`MutexGuard`/`LockGuard`/, and dropped the commit "test/util_threadnames_tests: add thread safety annotations" since the [previous](https://github.com/bitcoin/bitcoin/pull/16127#pullrequestreview-414184113) review. ryanofsky: Code review ACK5478d6c099. Thanks for taking suggestions! Only changes since last review are dropping thread rename test commit d53072ec730d8eec5a5b72f7e65a54b141e62b19 and renaming mutex guard to lock guard Tree-SHA512: 7b00d31f6f2b5a222ec69431eb810a74abf0542db3a65d1bbad54e354c40df2857ec89c00b4a5e466c81ba223267ca95f3f98d5fbc1a1d052a2c3a7d2209790a
This commit is contained in:
@@ -41,7 +41,7 @@ static int FileWriteStr(const std::string &str, FILE *fp)
|
||||
|
||||
bool BCLog::Logger::StartLogging()
|
||||
{
|
||||
std::lock_guard<std::mutex> scoped_lock(m_cs);
|
||||
LockGuard scoped_lock(m_cs);
|
||||
|
||||
assert(m_buffering);
|
||||
assert(m_fileout == nullptr);
|
||||
@@ -80,7 +80,7 @@ bool BCLog::Logger::StartLogging()
|
||||
|
||||
void BCLog::Logger::DisconnectTestLogger()
|
||||
{
|
||||
std::lock_guard<std::mutex> scoped_lock(m_cs);
|
||||
LockGuard scoped_lock(m_cs);
|
||||
m_buffering = true;
|
||||
if (m_fileout != nullptr) fclose(m_fileout);
|
||||
m_fileout = nullptr;
|
||||
@@ -246,7 +246,7 @@ namespace BCLog {
|
||||
|
||||
void BCLog::Logger::LogPrintStr(const std::string& str)
|
||||
{
|
||||
std::lock_guard<std::mutex> scoped_lock(m_cs);
|
||||
LockGuard scoped_lock(m_cs);
|
||||
std::string str_prefixed = LogEscapeMessage(str);
|
||||
|
||||
if (m_log_threadnames && m_started_new_line) {
|
||||
|
||||
Reference in New Issue
Block a user