X-Git-Url: https://git.novaco.in/?a=blobdiff_plain;f=src%2Fcheckqueue.h;h=43895739409d83f73f03d6de60ae35a913609ae1;hb=HEAD;hp=c4c35e5f80f7cab56c324a32f447854a7ceba395;hpb=0a7d6c34393639170a541b9d8acf89f158489b8c;p=novacoin.git diff --git a/src/checkqueue.h b/src/checkqueue.h index c4c35e5..4389573 100644 --- a/src/checkqueue.h +++ b/src/checkqueue.h @@ -7,11 +7,10 @@ #include #include +#include +#include +#include -#include -#include -#include -#include extern bool fShutdown; @@ -29,16 +28,16 @@ template class CCheckQueueControl; template class CCheckQueue { private: // Mutex to protect the inner state - boost::mutex mutex; + std::mutex mutex; // Worker threads block on this when out of work - boost::condition_variable condWorker; + std::condition_variable condWorker; // Master thread blocks on this when out of work - boost::condition_variable condMaster; + std::condition_variable condMaster; // Quit method blocks on this until all workers are gone - boost::condition_variable condQuit; + std::condition_variable condQuit; // The queue of elements to be processed. // As the order of booleans doesn't matter, it is used as a LIFO (stack) @@ -66,14 +65,14 @@ private: // Internal function that does bulk of the verification work. bool Loop(bool fMaster = false) { - boost::condition_variable &cond = fMaster ? condMaster : condWorker; + std::condition_variable &cond = fMaster ? condMaster : condWorker; std::vector vChecks; vChecks.reserve(nBatchSize); unsigned int nNow = 0; bool fOk = true; do { { - boost::unique_lock lock(mutex); + std::unique_lock lock(mutex); // first do the clean-up of the previous loop run (allowing us to do it in the same critsect) if (nNow) { fAllOk &= fOk; @@ -119,7 +118,7 @@ private: fOk = fAllOk; } // execute work - BOOST_FOREACH(T &check, vChecks) + for (T &check : vChecks) if (fOk) fOk = check(); vChecks.clear(); @@ -144,8 +143,8 @@ public: // Add a batch of checks to the queue void Add(std::vector &vChecks) { - boost::unique_lock lock(mutex); - BOOST_FOREACH(T &check, vChecks) { + std::unique_lock lock(mutex); + for (T &check : vChecks) { queue.push_back(T()); check.swap(queue.back()); } @@ -158,7 +157,7 @@ public: // Shut the queue down void Quit() { - boost::unique_lock lock(mutex); + std::unique_lock lock(mutex); fQuit = true; // No need to wake the master, as he will quit automatically when all jobs are // done. @@ -174,7 +173,7 @@ public: bool IsIdle() { - boost::unique_lock lock(mutex); + std::unique_lock lock(mutex); return (nTotal == nIdle && nTodo == 0 && fAllOk == true); } }; @@ -190,14 +189,14 @@ private: public: CCheckQueueControl(CCheckQueue *pqueueIn) : pqueue(pqueueIn), fDone(false) { // passed queue is supposed to be unused, or NULL - if (pqueue != NULL) { + if (pqueue != nullptr) { bool isIdle = pqueue->IsIdle(); assert(isIdle); } } bool Wait() { - if (pqueue == NULL) + if (pqueue == nullptr) return true; bool fRet = pqueue->Wait(); fDone = true; @@ -205,7 +204,7 @@ public: } void Add(std::vector &vChecks) { - if (pqueue != NULL) + if (pqueue != nullptr) pqueue->Add(vChecks); }