Merge #11599: scripted-diff: Small locking rename
190bf62be1
scripted-diff: Small locking rename (Russell Yanofsky)
Pull request description:
Call sync.h primitives "locks" and "mutexes" instead of "blocks" and "waitable critical sections" to match current coding conventions and c++11 standard names.
This PR does not rename the "CCriticalSection" class (though this could be done as a followup) because it's used everywhere and would swamp the other changes in this PR. Plain mutexes should mostly be preferred instead of recursive mutexes in new code anyway.
Tree-SHA512: 39b5b2be8f7a98227be8ab0648bdbb1b620944659bdc1eb9a15b0fcc0c930457fa0c03170cfedaeee0007ea716c526b31a8d84a86dd2333ce9d8bfabd773fe45
This commit is contained in:
commit
59ecacfc84
10 changed files with 22 additions and 25 deletions
|
@ -69,7 +69,7 @@ class WorkQueue
|
|||
{
|
||||
private:
|
||||
/** Mutex protects entire object */
|
||||
CWaitableCriticalSection cs;
|
||||
Mutex cs;
|
||||
std::condition_variable cond;
|
||||
std::deque<std::unique_ptr<WorkItem>> queue;
|
||||
bool running;
|
||||
|
|
12
src/init.cpp
12
src/init.cpp
|
@ -561,17 +561,17 @@ static void BlockNotifyCallback(bool initialSync, const CBlockIndex *pBlockIndex
|
|||
}
|
||||
|
||||
static bool fHaveGenesis = false;
|
||||
static CWaitableCriticalSection cs_GenesisWait;
|
||||
static CConditionVariable condvar_GenesisWait;
|
||||
static Mutex g_genesis_wait_mutex;
|
||||
static std::condition_variable g_genesis_wait_cv;
|
||||
|
||||
static void BlockNotifyGenesisWait(bool, const CBlockIndex *pBlockIndex)
|
||||
{
|
||||
if (pBlockIndex != nullptr) {
|
||||
{
|
||||
LOCK(cs_GenesisWait);
|
||||
LOCK(g_genesis_wait_mutex);
|
||||
fHaveGenesis = true;
|
||||
}
|
||||
condvar_GenesisWait.notify_all();
|
||||
g_genesis_wait_cv.notify_all();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1661,12 +1661,12 @@ bool AppInitMain()
|
|||
|
||||
// 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
|
||||
// ThreadImport getting started, so instead we just wait on a timer to
|
||||
// check ShutdownRequested() regularly.
|
||||
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);
|
||||
}
|
||||
|
|
|
@ -427,7 +427,7 @@ private:
|
|||
bool fMsgProcWake;
|
||||
|
||||
std::condition_variable condMsgProc;
|
||||
CWaitableCriticalSection mutexMsgProc;
|
||||
Mutex mutexMsgProc;
|
||||
std::atomic<bool> flagInterruptMsgProc;
|
||||
|
||||
CThreadInterrupt interruptNet;
|
||||
|
|
|
@ -296,7 +296,7 @@ void RandAddSeedSleep()
|
|||
}
|
||||
|
||||
|
||||
static CWaitableCriticalSection cs_rng_state;
|
||||
static Mutex cs_rng_state;
|
||||
static unsigned char rng_state[32] = {0};
|
||||
static uint64_t rng_counter = 0;
|
||||
|
||||
|
|
|
@ -50,7 +50,7 @@ struct CUpdatedBlock
|
|||
int height;
|
||||
};
|
||||
|
||||
static CWaitableCriticalSection cs_blockchange;
|
||||
static Mutex cs_blockchange;
|
||||
static std::condition_variable cond_blockchange;
|
||||
static CUpdatedBlock latestblock;
|
||||
|
||||
|
|
15
src/sync.h
15
src/sync.h
|
@ -107,10 +107,7 @@ public:
|
|||
typedef AnnotatedMixin<std::recursive_mutex> CCriticalSection;
|
||||
|
||||
/** Wrapped mutex: supports waiting but not recursive locking */
|
||||
typedef AnnotatedMixin<std::mutex> CWaitableCriticalSection;
|
||||
|
||||
/** Just a typedef for std::condition_variable, can be wrapped later if desired */
|
||||
typedef std::condition_variable CConditionVariable;
|
||||
typedef AnnotatedMixin<std::mutex> Mutex;
|
||||
|
||||
#ifdef DEBUG_LOCKCONTENTION
|
||||
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. */
|
||||
template <typename Mutex, typename Base = typename Mutex::UniqueLock>
|
||||
class SCOPED_LOCKABLE CCriticalBlock : public Base
|
||||
class SCOPED_LOCKABLE UniqueLock : public Base
|
||||
{
|
||||
private:
|
||||
void Enter(const char* pszName, const char* pszFile, int nLine)
|
||||
|
@ -144,7 +141,7 @@ private:
|
|||
}
|
||||
|
||||
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)
|
||||
TryEnter(pszName, pszFile, nLine);
|
||||
|
@ -152,7 +149,7 @@ public:
|
|||
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;
|
||||
|
||||
|
@ -163,7 +160,7 @@ public:
|
|||
Enter(pszName, pszFile, nLine);
|
||||
}
|
||||
|
||||
~CCriticalBlock() UNLOCK_FUNCTION()
|
||||
~UniqueLock() UNLOCK_FUNCTION()
|
||||
{
|
||||
if (Base::owns_lock())
|
||||
LeaveCritical();
|
||||
|
@ -176,7 +173,7 @@ public:
|
|||
};
|
||||
|
||||
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 PASTE2(x, y) PASTE(x, y)
|
||||
|
|
|
@ -41,7 +41,7 @@ BOOST_AUTO_TEST_CASE(potential_deadlock_detected)
|
|||
CCriticalSection rmutex1, rmutex2;
|
||||
TestPotentialDeadLockDetected(rmutex1, rmutex2);
|
||||
|
||||
CWaitableCriticalSection mutex1, mutex2;
|
||||
Mutex mutex1, mutex2;
|
||||
TestPotentialDeadLockDetected(mutex1, mutex2);
|
||||
|
||||
#ifdef DEBUG_LOCKORDER
|
||||
|
|
|
@ -30,7 +30,7 @@ public:
|
|||
|
||||
private:
|
||||
std::condition_variable cond;
|
||||
CWaitableCriticalSection mut;
|
||||
Mutex mut;
|
||||
std::atomic<bool> flag;
|
||||
};
|
||||
|
||||
|
|
|
@ -217,8 +217,8 @@ CCriticalSection cs_main;
|
|||
BlockMap& mapBlockIndex = g_chainstate.mapBlockIndex;
|
||||
CChain& chainActive = g_chainstate.chainActive;
|
||||
CBlockIndex *pindexBestHeader = nullptr;
|
||||
CWaitableCriticalSection g_best_block_mutex;
|
||||
CConditionVariable g_best_block_cv;
|
||||
Mutex g_best_block_mutex;
|
||||
std::condition_variable g_best_block_cv;
|
||||
uint256 g_best_block;
|
||||
int nScriptCheckThreads = 0;
|
||||
std::atomic_bool fImporting(false);
|
||||
|
|
|
@ -151,8 +151,8 @@ extern BlockMap& mapBlockIndex;
|
|||
extern uint64_t nLastBlockTx;
|
||||
extern uint64_t nLastBlockWeight;
|
||||
extern const std::string strMessageMagic;
|
||||
extern CWaitableCriticalSection g_best_block_mutex;
|
||||
extern CConditionVariable g_best_block_cv;
|
||||
extern Mutex g_best_block_mutex;
|
||||
extern std::condition_variable g_best_block_cv;
|
||||
extern uint256 g_best_block;
|
||||
extern std::atomic_bool fImporting;
|
||||
extern std::atomic_bool fReindex;
|
||||
|
|
Loading…
Reference in a new issue