scripted-diff: Small locking rename
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 is 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. -BEGIN VERIFY SCRIPT- set -x set -e ren() { git grep -l $1 | xargs sed -i s/$1/$2/; } ren CCriticalBlock UniqueLock ren CWaitableCriticalSection Mutex ren CConditionVariable std::condition_variable ren cs_GenesisWait g_genesis_wait_mutex ren condvar_GenesisWait g_genesis_wait_cv perl -0777 -pi -e 's/.*typedef.*condition_variable.*\n\n?//g' src/sync.h -END VERIFY SCRIPT- (cherry picked from commit bitcoin/bitcoin@190bf62be1)
This commit is contained in:
parent
f17e43d61e
commit
fcd0b28616
|
@ -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
|
@ -555,17 +555,17 @@ static void TxExpiryNotifyCallback(const uint256& txid)
|
|||
}
|
||||
|
||||
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 != NULL) {
|
||||
{
|
||||
LOCK(cs_GenesisWait);
|
||||
LOCK(g_genesis_wait_mutex);
|
||||
fHaveGenesis = true;
|
||||
}
|
||||
condvar_GenesisWait.notify_all();
|
||||
g_genesis_wait_cv.notify_all();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1905,12 +1905,12 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler)
|
|||
|
||||
// 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);
|
||||
}
|
||||
|
|
|
@ -66,8 +66,8 @@ BlockMap mapBlockIndex;
|
|||
CChain chainActive;
|
||||
CBlockIndex *pindexBestHeader = NULL;
|
||||
static std::atomic<int64_t> nTimeBestReceived(0); // Used only to inform the wallet of when we last received a block
|
||||
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 g_best_block_height;
|
||||
int nScriptCheckThreads = 0;
|
||||
|
|
|
@ -169,8 +169,8 @@ extern const std::string strMessageMagic;
|
|||
//! (and cannot) hold cs_main. So the g_best_block_height and g_best_block variables
|
||||
//! (protected by g_best_block_mutex) provide the needed height and block
|
||||
//! hash respectively to getblocktemplate without it requiring cs_main.
|
||||
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 int g_best_block_height;
|
||||
extern uint256 g_best_block;
|
||||
|
||||
|
|
15
src/sync.h
15
src/sync.h
|
@ -108,10 +108,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);
|
||||
|
@ -119,7 +116,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)
|
||||
|
@ -145,7 +142,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);
|
||||
|
@ -153,7 +150,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;
|
||||
|
||||
|
@ -164,7 +161,7 @@ public:
|
|||
Enter(pszName, pszFile, nLine);
|
||||
}
|
||||
|
||||
~CCriticalBlock() UNLOCK_FUNCTION()
|
||||
~UniqueLock() UNLOCK_FUNCTION()
|
||||
{
|
||||
if (Base::owns_lock())
|
||||
LeaveCritical();
|
||||
|
@ -177,7 +174,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
|
||||
|
|
Loading…
Reference in New Issue