Skip to content

Commit

Permalink
Merge bitcoin#9497 via remote-tracking branch 'origin-pull/9497/head'…
Browse files Browse the repository at this point in the history
… into 0.14.2_fixes
  • Loading branch information
luke-jr committed Jun 5, 2017
2 parents 77de9bb + 96c7f2c commit 1b864c9
Show file tree
Hide file tree
Showing 3 changed files with 455 additions and 10 deletions.
1 change: 1 addition & 0 deletions src/Makefile.test.include
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ BITCOIN_TESTS =\
test/blockencodings_tests.cpp \
test/bloom_tests.cpp \
test/bswap_tests.cpp \
test/checkqueue_tests.cpp \
test/coins_tests.cpp \
test/compress_tests.cpp \
test/crypto_tests.cpp \
Expand Down
22 changes: 12 additions & 10 deletions src/checkqueue.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,9 @@ class CCheckQueue
}

public:
//! Mutex to ensure only one concurrent CCheckQueueControl
boost::mutex ControlMutex;

//! Create a new check queue
CCheckQueue(unsigned int nBatchSizeIn) : nIdle(0), nTotal(0), fAllOk(true), nTodo(0), fQuit(false), nBatchSize(nBatchSizeIn) {}

Expand Down Expand Up @@ -161,12 +164,6 @@ class CCheckQueue
{
}

bool IsIdle()
{
boost::unique_lock<boost::mutex> lock(mutex);
return (nTotal == nIdle && nTodo == 0 && fAllOk == true);
}

};

/**
Expand All @@ -177,16 +174,18 @@ template <typename T>
class CCheckQueueControl
{
private:
CCheckQueue<T>* pqueue;
CCheckQueue<T> * const pqueue;
bool fDone;

public:
CCheckQueueControl(CCheckQueue<T>* pqueueIn) : pqueue(pqueueIn), fDone(false)
CCheckQueueControl() = delete;
CCheckQueueControl(const CCheckQueueControl&) = delete;
CCheckQueueControl& operator=(const CCheckQueueControl&) = delete;
explicit CCheckQueueControl(CCheckQueue<T> * const pqueueIn) : pqueue(pqueueIn), fDone(false)
{
// passed queue is supposed to be unused, or NULL
if (pqueue != NULL) {
bool isIdle = pqueue->IsIdle();
assert(isIdle);
ENTER_CRITICAL_SECTION(pqueue->ControlMutex);
}
}

Expand All @@ -209,6 +208,9 @@ class CCheckQueueControl
{
if (!fDone)
Wait();
if (pqueue != NULL) {
LEAVE_CRITICAL_SECTION(pqueue->ControlMutex);
}
}
};

Expand Down
Loading

0 comments on commit 1b864c9

Please sign in to comment.