Merge #11640: Make LOCK, LOCK2, TRY_LOCK work with CWaitableCriticalSection
9c4dc597ddUse LOCK macros for non-recursive locks (Russell Yanofsky)1382913e61Make LOCK, LOCK2, TRY_LOCK work with CWaitableCriticalSection (Russell Yanofsky)ba1f095aadMOVEONLY Move AnnotatedMixin declaration (Russell Yanofsky)41b88e9337Add unit test for DEBUG_LOCKORDER code (Russell Yanofsky) Pull request description: Make LOCK macros work with non-recursive mutexes, and use wherever possible for better deadlock detection. Also add unit test for DEBUG_LOCKORDER code. Tree-SHA512: 64ef209307f28ecd0813a283f15c6406138c6ffe7f6cbbd084161044db60e2c099a7d0d2edcd1c5e7770a115e9b931b486e86c9a777bdc96d2e8a9f4dc192942
This commit is contained in:
@@ -50,7 +50,7 @@ struct CUpdatedBlock
|
||||
int height;
|
||||
};
|
||||
|
||||
static std::mutex cs_blockchange;
|
||||
static CWaitableCriticalSection cs_blockchange;
|
||||
static std::condition_variable cond_blockchange;
|
||||
static CUpdatedBlock latestblock;
|
||||
|
||||
@@ -225,7 +225,7 @@ static UniValue waitfornewblock(const JSONRPCRequest& request)
|
||||
|
||||
CUpdatedBlock block;
|
||||
{
|
||||
std::unique_lock<std::mutex> lock(cs_blockchange);
|
||||
WAIT_LOCK(cs_blockchange, lock);
|
||||
block = latestblock;
|
||||
if(timeout)
|
||||
cond_blockchange.wait_for(lock, std::chrono::milliseconds(timeout), [&block]{return latestblock.height != block.height || latestblock.hash != block.hash || !IsRPCRunning(); });
|
||||
@@ -267,7 +267,7 @@ static UniValue waitforblock(const JSONRPCRequest& request)
|
||||
|
||||
CUpdatedBlock block;
|
||||
{
|
||||
std::unique_lock<std::mutex> lock(cs_blockchange);
|
||||
WAIT_LOCK(cs_blockchange, lock);
|
||||
if(timeout)
|
||||
cond_blockchange.wait_for(lock, std::chrono::milliseconds(timeout), [&hash]{return latestblock.hash == hash || !IsRPCRunning();});
|
||||
else
|
||||
@@ -310,7 +310,7 @@ static UniValue waitforblockheight(const JSONRPCRequest& request)
|
||||
|
||||
CUpdatedBlock block;
|
||||
{
|
||||
std::unique_lock<std::mutex> lock(cs_blockchange);
|
||||
WAIT_LOCK(cs_blockchange, lock);
|
||||
if(timeout)
|
||||
cond_blockchange.wait_for(lock, std::chrono::milliseconds(timeout), [&height]{return latestblock.height >= height || !IsRPCRunning();});
|
||||
else
|
||||
|
||||
Reference in New Issue
Block a user