Use LOCK macros for non-recursive locks

Instead of std::unique_lock.

Zcash: Excluding locks in code we haven't backported yet.

(cherry picked from commit bitcoin/bitcoin@9c4dc597dd)
This commit is contained in:
Russell Yanofsky 2017-11-08 17:07:40 -05:00 committed by Jack Grigg
parent 28adc47fcd
commit f17e43d61e
5 changed files with 8 additions and 11 deletions

View File

@ -69,7 +69,7 @@ class WorkQueue
{
private:
/** Mutex protects entire object */
std::mutex cs;
CWaitableCriticalSection cs;
std::condition_variable cond;
std::deque<std::unique_ptr<WorkItem>> queue;
bool running;
@ -88,7 +88,7 @@ public:
/** Enqueue a work item */
bool Enqueue(WorkItem* item)
{
std::unique_lock<std::mutex> lock(cs);
LOCK(cs);
if (queue.size() >= maxDepth) {
return false;
}
@ -102,7 +102,7 @@ public:
while (true) {
std::unique_ptr<WorkItem> i;
{
std::unique_lock<std::mutex> lock(cs);
WAIT_LOCK(cs, lock);
while (running && queue.empty())
cond.wait(lock);
if (!running)
@ -116,7 +116,7 @@ public:
/** Interrupt and exit loops */
void Interrupt()
{
std::unique_lock<std::mutex> lock(cs);
LOCK(cs);
running = false;
cond.notify_all();
}

View File

@ -562,7 +562,7 @@ static void BlockNotifyGenesisWait(bool, const CBlockIndex *pBlockIndex)
{
if (pBlockIndex != NULL) {
{
WaitableLock lock_GenesisWait(cs_GenesisWait);
LOCK(cs_GenesisWait);
fHaveGenesis = true;
}
condvar_GenesisWait.notify_all();
@ -1905,7 +1905,7 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler)
// Wait for genesis block to be processed
{
WaitableLock lock(cs_GenesisWait);
WAIT_LOCK(cs_GenesisWait, 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.

View File

@ -3863,7 +3863,7 @@ void static UpdateTip(CBlockIndex *pindexNew, const CChainParams& chainParams) {
RenderPoolMetrics("transparent", transparentPool);
{
WaitableLock lock(g_best_block_mutex);
WAIT_LOCK(g_best_block_mutex, lock);
g_best_block = pindexNew->GetBlockHash();
g_best_block_height = pindexNew->nHeight;
g_best_block_cv.notify_all();

View File

@ -625,7 +625,7 @@ UniValue getblocktemplate(const UniValue& params, bool fHelp)
{
checktxtime = std::chrono::steady_clock::now() + std::chrono::seconds(10);
WaitableLock lock(g_best_block_mutex);
WAIT_LOCK(g_best_block_mutex, lock);
while (g_best_block == hashWatchedChain && IsRPCRunning())
{
// Before waiting, generate the coinbase for the block following the next

View File

@ -113,9 +113,6 @@ typedef AnnotatedMixin<std::mutex> CWaitableCriticalSection;
/** Just a typedef for std::condition_variable, can be wrapped later if desired */
typedef std::condition_variable CConditionVariable;
/** Just a typedef for std::unique_lock, can be wrapped later if desired */
typedef std::unique_lock<std::mutex> WaitableLock;
#ifdef DEBUG_LOCKCONTENTION
void PrintLockContention(const char* pszName, const char* pszFile, int nLine);
#endif