Acquire CCheckQueue's lock to avoid race condition
[novacoin.git] / src / checkqueue.h
index 0ae4020..3c30db7 100644 (file)
@@ -165,7 +165,15 @@ public:
             condQuit.wait(lock);
     }
 
-    friend class CCheckQueueControl<T>;
+    ~CCheckQueue() {
+        Quit();
+    }
+
+    bool IsIdle()
+    {
+        boost::unique_lock<boost::mutex> lock(mutex);
+        return (nTotal == nIdle && nTodo == 0 && fAllOk == true);
+    }
 };
 
 /** RAII-style controller object for a CCheckQueue that guarantees the passed
@@ -180,9 +188,8 @@ public:
     CCheckQueueControl(CCheckQueue<T> *pqueueIn) : pqueue(pqueueIn), fDone(false) {
         // passed queue is supposed to be unused, or NULL
         if (pqueue != NULL) {
-            assert(pqueue->nTotal == pqueue->nIdle);
-            assert(pqueue->nTodo == 0);
-            assert(pqueue->fAllOk == true);
+            bool isIdle = pqueue->IsIdle();
+            assert(isIdle);
         }
     }