rpc/blockchain.cpp: thread safety annotations for latestblock
This commit is contained in:
1 parent
8b5af3d4c1
commit
479c5846f7
1 file changed
+8
-8
@@ -51,7 +51,7 @@ struct CUpdatedBlock
|
|||||||
|
|
||||||
static Mutex cs_blockchange;
|
static Mutex cs_blockchange;
|
||||||
static std::condition_variable cond_blockchange;
|
static std::condition_variable cond_blockchange;
|
||||||
static CUpdatedBlock latestblock;
|
static CUpdatedBlock latestblock GUARDED_BY(cs_blockchange);
|
||||||
|
|
||||||
CTxMemPool& EnsureMemPool()
|
CTxMemPool& EnsureMemPool()
|
||||||
{
|
{
|
||||||
@@ -208,7 +208,7 @@ static UniValue getbestblockhash(const JSONRPCRequest& request)
|
|||||||
void RPCNotifyBlockChange(bool ibd, const CBlockIndex * pindex)
|
void RPCNotifyBlockChange(bool ibd, const CBlockIndex * pindex)
|
||||||
{
|
{
|
||||||
if(pindex) {
|
if(pindex) {
|
||||||
std::lock_guard<std::mutex> lock(cs_blockchange);
|
LOCK(cs_blockchange);
|
||||||
latestblock.hash = pindex->GetBlockHash();
|
latestblock.hash = pindex->GetBlockHash();
|
||||||
latestblock.height = pindex->nHeight;
|
latestblock.height = pindex->nHeight;
|
||||||
}
|
}
|
||||||
@@ -243,9 +243,9 @@ static UniValue waitfornewblock(const JSONRPCRequest& request)
|
|||||||
WAIT_LOCK(cs_blockchange, lock);
|
WAIT_LOCK(cs_blockchange, lock);
|
||||||
block = latestblock;
|
block = latestblock;
|
||||||
if(timeout)
|
if(timeout)
|
||||||
cond_blockchange.wait_for(lock, std::chrono::milliseconds(timeout), [&block]{return latestblock.height != block.height || latestblock.hash != block.hash || !IsRPCRunning(); });
|
cond_blockchange.wait_for(lock, std::chrono::milliseconds(timeout), [&block]() EXCLUSIVE_LOCKS_REQUIRED(cs_blockchange) {return latestblock.height != block.height || latestblock.hash != block.hash || !IsRPCRunning(); });
|
||||||
else
|
else
|
||||||
cond_blockchange.wait(lock, [&block]{return latestblock.height != block.height || latestblock.hash != block.hash || !IsRPCRunning(); });
|
cond_blockchange.wait(lock, [&block]() EXCLUSIVE_LOCKS_REQUIRED(cs_blockchange) {return latestblock.height != block.height || latestblock.hash != block.hash || !IsRPCRunning(); });
|
||||||
block = latestblock;
|
block = latestblock;
|
||||||
}
|
}
|
||||||
UniValue ret(UniValue::VOBJ);
|
UniValue ret(UniValue::VOBJ);
|
||||||
@@ -285,9 +285,9 @@ static UniValue waitforblock(const JSONRPCRequest& request)
|
|||||||
{
|
{
|
||||||
WAIT_LOCK(cs_blockchange, lock);
|
WAIT_LOCK(cs_blockchange, lock);
|
||||||
if(timeout)
|
if(timeout)
|
||||||
cond_blockchange.wait_for(lock, std::chrono::milliseconds(timeout), [&hash]{return latestblock.hash == hash || !IsRPCRunning();});
|
cond_blockchange.wait_for(lock, std::chrono::milliseconds(timeout), [&hash]() EXCLUSIVE_LOCKS_REQUIRED(cs_blockchange) {return latestblock.hash == hash || !IsRPCRunning();});
|
||||||
else
|
else
|
||||||
cond_blockchange.wait(lock, [&hash]{return latestblock.hash == hash || !IsRPCRunning(); });
|
cond_blockchange.wait(lock, [&hash]() EXCLUSIVE_LOCKS_REQUIRED(cs_blockchange) {return latestblock.hash == hash || !IsRPCRunning(); });
|
||||||
block = latestblock;
|
block = latestblock;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -329,9 +329,9 @@ static UniValue waitforblockheight(const JSONRPCRequest& request)
|
|||||||
{
|
{
|
||||||
WAIT_LOCK(cs_blockchange, lock);
|
WAIT_LOCK(cs_blockchange, lock);
|
||||||
if(timeout)
|
if(timeout)
|
||||||
cond_blockchange.wait_for(lock, std::chrono::milliseconds(timeout), [&height]{return latestblock.height >= height || !IsRPCRunning();});
|
cond_blockchange.wait_for(lock, std::chrono::milliseconds(timeout), [&height]() EXCLUSIVE_LOCKS_REQUIRED(cs_blockchange) {return latestblock.height >= height || !IsRPCRunning();});
|
||||||
else
|
else
|
||||||
cond_blockchange.wait(lock, [&height]{return latestblock.height >= height || !IsRPCRunning(); });
|
cond_blockchange.wait(lock, [&height]() EXCLUSIVE_LOCKS_REQUIRED(cs_blockchange) {return latestblock.height >= height || !IsRPCRunning(); });
|
||||||
block = latestblock;
|
block = latestblock;
|
||||||
}
|
}
|
||||||
UniValue ret(UniValue::VOBJ);
|
UniValue ret(UniValue::VOBJ);
|
||||||
|
|||||||
Reference in new issue
Block a user