aboutsummaryrefslogtreecommitdiff
path: root/src/checkqueue.h
diff options
context:
space:
mode:
authorWladimir J. van der Laan <laanwj@gmail.com>2017-03-14 12:22:54 +0100
committerWladimir J. van der Laan <laanwj@gmail.com>2017-03-14 12:23:41 +0100
commit2c781fb920269036080bce69743259b01bc0edde (patch)
tree5695138e7f0c960ccd96858007cfac884824e12d /src/checkqueue.h
parent3cc13eac40a0d65f7b4c8d1bc74cb7060b5e1eb1 (diff)
parent96c7f2c3458950061b057fcd3daaf47b57e6bac7 (diff)
downloadbitcoin-2c781fb920269036080bce69743259b01bc0edde.tar.xz
Merge #9497: CCheckQueue Unit Tests
96c7f2c Add CheckQueue Tests (Jeremy Rubin) e207342 Fix CCheckQueue IsIdle (potential) race condition and remove dangerous constructors. (Jeremy Rubin) Tree-SHA512: 5989743ad0f8b08998335e7ca9256e168fa319053f91b9dece9dbb134885bef7753b567b591acc7135785f23d19799ed7e6375917f59fe0178d389e961633d62
Diffstat (limited to 'src/checkqueue.h')
-rw-r--r--src/checkqueue.h22
1 files changed, 12 insertions, 10 deletions
diff --git a/src/checkqueue.h b/src/checkqueue.h
index 32e25d5c8c..ea12df66dd 100644
--- a/src/checkqueue.h
+++ b/src/checkqueue.h
@@ -127,6 +127,9 @@ private:
}
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) {}
@@ -161,12 +164,6 @@ public:
{
}
- bool IsIdle()
- {
- boost::unique_lock<boost::mutex> lock(mutex);
- return (nTotal == nIdle && nTodo == 0 && fAllOk == true);
- }
-
};
/**
@@ -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);
}
}
@@ -209,6 +208,9 @@ public:
{
if (!fDone)
Wait();
+ if (pqueue != NULL) {
+ LEAVE_CRITICAL_SECTION(pqueue->ControlMutex);
+ }
}
};