Permalink
Browse files

Fix CCheckQueue IsIdle (potential) race condition and remove dangerou…

…s constructors.
  • Loading branch information...
1 parent 25720fc commit e2073424fd5a185781750347fbfbb0c108ef66fd @JeremyRubin JeremyRubin committed Jan 9, 2017
Showing with 12 additions and 10 deletions.
  1. +12 −10 src/checkqueue.h
View
@@ -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) {}
@@ -161,12 +164,6 @@ class CCheckQueue
{
}
- 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 @@ class CCheckQueueControl
{
if (!fDone)
Wait();
+ if (pqueue != NULL) {
+ LEAVE_CRITICAL_SECTION(pqueue->ControlMutex);
+ }
}
};

0 comments on commit e207342

Please sign in to comment.