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 flag for synchronisation rather than having a mutex that doesn’t actually guard anything as well.