merge #11599: Small locking rename

This commit is contained in:
Kittywhiskers Van Gogh 2021-06-05 00:56:33 +05:30
parent c5c3dee308
commit 944aea8753
10 changed files with 22 additions and 25 deletions

View File

@ -74,7 +74,7 @@ class WorkQueue
{ {
private: private:
/** Mutex protects entire object */ /** Mutex protects entire object */
CWaitableCriticalSection cs; Mutex cs;
std::condition_variable cond; std::condition_variable cond;
std::deque<std::unique_ptr<WorkItem>> queue; std::deque<std::unique_ptr<WorkItem>> queue;
bool running; bool running;

View File

@ -702,17 +702,17 @@ static void BlockNotifyCallback(bool initialSync, const CBlockIndex *pBlockIndex
} }
static bool fHaveGenesis = false; static bool fHaveGenesis = false;
static CWaitableCriticalSection cs_GenesisWait; static Mutex g_genesis_wait_mutex;
static CConditionVariable condvar_GenesisWait; static std::condition_variable g_genesis_wait_cv;
static void BlockNotifyGenesisWait(bool, const CBlockIndex *pBlockIndex) static void BlockNotifyGenesisWait(bool, const CBlockIndex *pBlockIndex)
{ {
if (pBlockIndex != nullptr) { if (pBlockIndex != nullptr) {
{ {
LOCK(cs_GenesisWait); LOCK(g_genesis_wait_mutex);
fHaveGenesis = true; fHaveGenesis = true;
} }
condvar_GenesisWait.notify_all(); g_genesis_wait_cv.notify_all();
} }
} }
@ -2377,12 +2377,12 @@ bool AppInitMain()
// Wait for genesis block to be processed // Wait for genesis block to be processed
{ {
WAIT_LOCK(cs_GenesisWait, lock); WAIT_LOCK(g_genesis_wait_mutex, lock);
// We previously could hang here if StartShutdown() is called prior to // We previously could hang here if StartShutdown() is called prior to
// ThreadImport getting started, so instead we just wait on a timer to // ThreadImport getting started, so instead we just wait on a timer to
// check ShutdownRequested() regularly. // check ShutdownRequested() regularly.
while (!fHaveGenesis && !ShutdownRequested()) { while (!fHaveGenesis && !ShutdownRequested()) {
condvar_GenesisWait.wait_for(lock, std::chrono::milliseconds(500)); g_genesis_wait_cv.wait_for(lock, std::chrono::milliseconds(500));
} }
uiInterface.NotifyBlockTip.disconnect(BlockNotifyGenesisWait); uiInterface.NotifyBlockTip.disconnect(BlockNotifyGenesisWait);
} }

View File

@ -620,7 +620,7 @@ private:
bool fMsgProcWake; bool fMsgProcWake;
std::condition_variable condMsgProc; std::condition_variable condMsgProc;
CWaitableCriticalSection mutexMsgProc; Mutex mutexMsgProc;
std::atomic<bool> flagInterruptMsgProc; std::atomic<bool> flagInterruptMsgProc;
CThreadInterrupt interruptNet; CThreadInterrupt interruptNet;

View File

@ -296,7 +296,7 @@ void RandAddSeedSleep()
} }
static CWaitableCriticalSection cs_rng_state; static Mutex cs_rng_state;
static unsigned char rng_state[32] = {0}; static unsigned char rng_state[32] = {0};
static uint64_t rng_counter = 0; static uint64_t rng_counter = 0;

View File

@ -53,7 +53,7 @@ struct CUpdatedBlock
int height; int height;
}; };
static CWaitableCriticalSection cs_blockchange; static Mutex cs_blockchange;
static std::condition_variable cond_blockchange; static std::condition_variable cond_blockchange;
static CUpdatedBlock latestblock; static CUpdatedBlock latestblock;

View File

@ -107,10 +107,7 @@ public:
typedef AnnotatedMixin<std::recursive_mutex> CCriticalSection; typedef AnnotatedMixin<std::recursive_mutex> CCriticalSection;
/** Wrapped mutex: supports waiting but not recursive locking */ /** Wrapped mutex: supports waiting but not recursive locking */
typedef AnnotatedMixin<std::mutex> CWaitableCriticalSection; typedef AnnotatedMixin<std::mutex> Mutex;
/** Just a typedef for std::condition_variable, can be wrapped later if desired */
typedef std::condition_variable CConditionVariable;
#ifdef DEBUG_LOCKCONTENTION #ifdef DEBUG_LOCKCONTENTION
void PrintLockContention(const char* pszName, const char* pszFile, int nLine); void PrintLockContention(const char* pszName, const char* pszFile, int nLine);
@ -118,7 +115,7 @@ void PrintLockContention(const char* pszName, const char* pszFile, int nLine);
/** Wrapper around std::unique_lock style lock for Mutex. */ /** Wrapper around std::unique_lock style lock for Mutex. */
template <typename Mutex, typename Base = typename Mutex::UniqueLock> template <typename Mutex, typename Base = typename Mutex::UniqueLock>
class SCOPED_LOCKABLE CCriticalBlock : public Base class SCOPED_LOCKABLE UniqueLock : public Base
{ {
private: private:
void Enter(const char* pszName, const char* pszFile, int nLine) void Enter(const char* pszName, const char* pszFile, int nLine)
@ -144,7 +141,7 @@ private:
} }
public: public:
CCriticalBlock(Mutex& mutexIn, const char* pszName, const char* pszFile, int nLine, bool fTry = false) EXCLUSIVE_LOCK_FUNCTION(mutexIn) : Base(mutexIn, std::defer_lock) UniqueLock(Mutex& mutexIn, const char* pszName, const char* pszFile, int nLine, bool fTry = false) EXCLUSIVE_LOCK_FUNCTION(mutexIn) : Base(mutexIn, std::defer_lock)
{ {
if (fTry) if (fTry)
TryEnter(pszName, pszFile, nLine); TryEnter(pszName, pszFile, nLine);
@ -152,7 +149,7 @@ public:
Enter(pszName, pszFile, nLine); Enter(pszName, pszFile, nLine);
} }
CCriticalBlock(Mutex* pmutexIn, const char* pszName, const char* pszFile, int nLine, bool fTry = false) EXCLUSIVE_LOCK_FUNCTION(pmutexIn) UniqueLock(Mutex* pmutexIn, const char* pszName, const char* pszFile, int nLine, bool fTry = false) EXCLUSIVE_LOCK_FUNCTION(pmutexIn)
{ {
if (!pmutexIn) return; if (!pmutexIn) return;
@ -163,7 +160,7 @@ public:
Enter(pszName, pszFile, nLine); Enter(pszName, pszFile, nLine);
} }
~CCriticalBlock() UNLOCK_FUNCTION() ~UniqueLock() UNLOCK_FUNCTION()
{ {
if (Base::owns_lock()) if (Base::owns_lock())
LeaveCritical(); LeaveCritical();
@ -176,7 +173,7 @@ public:
}; };
template<typename MutexArg> template<typename MutexArg>
using DebugLock = CCriticalBlock<typename std::remove_reference<typename std::remove_pointer<MutexArg>::type>::type>; using DebugLock = UniqueLock<typename std::remove_reference<typename std::remove_pointer<MutexArg>::type>::type>;
#define PASTE(x, y) x ## y #define PASTE(x, y) x ## y
#define PASTE2(x, y) PASTE(x, y) #define PASTE2(x, y) PASTE(x, y)

View File

@ -41,7 +41,7 @@ BOOST_AUTO_TEST_CASE(potential_deadlock_detected)
CCriticalSection rmutex1, rmutex2; CCriticalSection rmutex1, rmutex2;
TestPotentialDeadLockDetected(rmutex1, rmutex2); TestPotentialDeadLockDetected(rmutex1, rmutex2);
CWaitableCriticalSection mutex1, mutex2; Mutex mutex1, mutex2;
TestPotentialDeadLockDetected(mutex1, mutex2); TestPotentialDeadLockDetected(mutex1, mutex2);
#ifdef DEBUG_LOCKORDER #ifdef DEBUG_LOCKORDER

View File

@ -30,7 +30,7 @@ public:
private: private:
std::condition_variable cond; std::condition_variable cond;
CWaitableCriticalSection mut; Mutex mut;
std::atomic<bool> flag; std::atomic<bool> flag;
}; };

View File

@ -223,8 +223,8 @@ BlockMap& mapBlockIndex = g_chainstate.mapBlockIndex;
PrevBlockMap& mapPrevBlockIndex = g_chainstate.mapPrevBlockIndex; PrevBlockMap& mapPrevBlockIndex = g_chainstate.mapPrevBlockIndex;
CChain& chainActive = g_chainstate.chainActive; CChain& chainActive = g_chainstate.chainActive;
CBlockIndex *pindexBestHeader = nullptr; CBlockIndex *pindexBestHeader = nullptr;
CWaitableCriticalSection g_best_block_mutex; Mutex g_best_block_mutex;
CConditionVariable g_best_block_cv; std::condition_variable g_best_block_cv;
uint256 g_best_block; uint256 g_best_block;
int nScriptCheckThreads = 0; int nScriptCheckThreads = 0;
std::atomic_bool fImporting(false); std::atomic_bool fImporting(false);

View File

@ -157,8 +157,8 @@ extern PrevBlockMap& mapPrevBlockIndex;
extern uint64_t nLastBlockTx; extern uint64_t nLastBlockTx;
extern uint64_t nLastBlockSize; extern uint64_t nLastBlockSize;
extern const std::string strMessageMagic; extern const std::string strMessageMagic;
extern CWaitableCriticalSection g_best_block_mutex; extern Mutex g_best_block_mutex;
extern CConditionVariable g_best_block_cv; extern std::condition_variable g_best_block_cv;
extern uint256 g_best_block; extern uint256 g_best_block;
extern std::atomic_bool fImporting; extern std::atomic_bool fImporting;
extern std::atomic_bool fReindex; extern std::atomic_bool fReindex;