From 20e01b1a03819d843a860284033b48a5e3b65ff7 Mon Sep 17 00:00:00 2001 From: Pieter Wuille Date: Fri, 19 Sep 2014 19:21:46 +0200 Subject: Apply clang-format on some infrequently-updated files --- src/checkqueue.h | 59 ++++++++++++++++++++++++++++++++++---------------------- 1 file changed, 36 insertions(+), 23 deletions(-) (limited to 'src/checkqueue.h') diff --git a/src/checkqueue.h b/src/checkqueue.h index c2c7d8ca24..b2a713e646 100644 --- a/src/checkqueue.h +++ b/src/checkqueue.h @@ -13,7 +13,8 @@ #include #include -template class CCheckQueueControl; +template +class CCheckQueueControl; /** Queue for verifications that have to be performed. * The verifications are represented by a type T, which must provide an @@ -24,7 +25,9 @@ template class CCheckQueueControl; * the master is done adding work, it temporarily joins the worker pool * as an N'th worker, until all jobs are done. */ -template class CCheckQueue { +template +class CCheckQueue +{ private: // Mutex to protect the inner state boost::mutex mutex; @@ -60,8 +63,9 @@ private: unsigned int nBatchSize; // Internal function that does bulk of the verification work. - bool Loop(bool fMaster = false) { - boost::condition_variable &cond = fMaster ? condMaster : condWorker; + bool Loop(bool fMaster = false) + { + boost::condition_variable& cond = fMaster ? condMaster : condWorker; std::vector vChecks; vChecks.reserve(nBatchSize); unsigned int nNow = 0; @@ -103,41 +107,43 @@ private: nNow = std::max(1U, std::min(nBatchSize, (unsigned int)queue.size() / (nTotal + nIdle + 1))); vChecks.resize(nNow); for (unsigned int i = 0; i < nNow; i++) { - // We want the lock on the mutex to be as short as possible, so swap jobs from the global - // queue to the local batch vector instead of copying. - vChecks[i].swap(queue.back()); - queue.pop_back(); + // We want the lock on the mutex to be as short as possible, so swap jobs from the global + // queue to the local batch vector instead of copying. + vChecks[i].swap(queue.back()); + queue.pop_back(); } // Check whether we need to do work at all fOk = fAllOk; } // execute work - BOOST_FOREACH(T &check, vChecks) + BOOST_FOREACH (T& check, vChecks) if (fOk) fOk = check(); vChecks.clear(); - } while(true); + } while (true); } public: // Create a new check queue - CCheckQueue(unsigned int nBatchSizeIn) : - nIdle(0), nTotal(0), fAllOk(true), nTodo(0), fQuit(false), nBatchSize(nBatchSizeIn) {} + CCheckQueue(unsigned int nBatchSizeIn) : nIdle(0), nTotal(0), fAllOk(true), nTodo(0), fQuit(false), nBatchSize(nBatchSizeIn) {} // Worker thread - void Thread() { + void Thread() + { Loop(); } // Wait until execution finishes, and return whether all evaluations where succesful. - bool Wait() { + bool Wait() + { return Loop(true); } // Add a batch of checks to the queue - void Add(std::vector &vChecks) { + void Add(std::vector& vChecks) + { boost::unique_lock lock(mutex); - BOOST_FOREACH(T &check, vChecks) { + BOOST_FOREACH (T& check, vChecks) { queue.push_back(T()); check.swap(queue.back()); } @@ -148,7 +154,8 @@ public: condWorker.notify_all(); } - ~CCheckQueue() { + ~CCheckQueue() + { } friend class CCheckQueueControl; @@ -157,13 +164,16 @@ public: /** RAII-style controller object for a CCheckQueue that guarantees the passed * queue is finished before continuing. */ -template class CCheckQueueControl { +template +class CCheckQueueControl +{ private: - CCheckQueue *pqueue; + CCheckQueue* pqueue; bool fDone; public: - CCheckQueueControl(CCheckQueue *pqueueIn) : pqueue(pqueueIn), fDone(false) { + CCheckQueueControl(CCheckQueue* pqueueIn) : pqueue(pqueueIn), fDone(false) + { // passed queue is supposed to be unused, or NULL if (pqueue != NULL) { assert(pqueue->nTotal == pqueue->nIdle); @@ -172,7 +182,8 @@ public: } } - bool Wait() { + bool Wait() + { if (pqueue == NULL) return true; bool fRet = pqueue->Wait(); @@ -180,12 +191,14 @@ public: return fRet; } - void Add(std::vector &vChecks) { + void Add(std::vector& vChecks) + { if (pqueue != NULL) pqueue->Add(vChecks); } - ~CCheckQueueControl() { + ~CCheckQueueControl() + { if (!fDone) Wait(); } -- cgit v1.2.3