Merge pull request #361 from svost/master
[novacoin.git] / src / checkqueue.h
index 36141dd..c4c35e5 100644 (file)
@@ -1,15 +1,19 @@
 // Copyright (c) 2012 The Bitcoin developers
 // Distributed under the MIT/X11 software license, see the accompanying
 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
+
 #ifndef CHECKQUEUE_H
 #define CHECKQUEUE_H
 
-#include <boost/thread/mutex.hpp>
-#include <boost/thread/locks.hpp>
+#include <algorithm>
+#include <vector>
+
+#include <boost/foreach.hpp>
 #include <boost/thread/condition_variable.hpp>
+#include <boost/thread/locks.hpp>
+#include <boost/thread/mutex.hpp>
 
-#include <vector>
-#include <algorithm>
+extern bool fShutdown;
 
 template<typename T> class CCheckQueueControl;
 
@@ -119,7 +123,8 @@ private:
                 if (fOk)
                     fOk = check();
             vChecks.clear();
-        } while(true);
+        } while(true && !fShutdown); // HACK: force queue to shut down
+        return false;
     }
 
 public:
@@ -163,7 +168,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
@@ -178,9 +191,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);
         }
     }