aboutsummaryrefslogtreecommitdiff
path: root/src/checkqueue.h
diff options
context:
space:
mode:
authorPieter Wuille <pieter.wuille@gmail.com>2014-09-19 19:21:46 +0200
committerPieter Wuille <pieter.wuille@gmail.com>2014-09-19 19:21:46 +0200
commit20e01b1a03819d843a860284033b48a5e3b65ff7 (patch)
tree5b390722b053ce5b448919bda2695d173980ffb5 /src/checkqueue.h
parent2fc6c67400e91846ca1c1c57011e57491013f9bd (diff)
downloadbitcoin-20e01b1a03819d843a860284033b48a5e3b65ff7.tar.xz
Apply clang-format on some infrequently-updated files
Diffstat (limited to 'src/checkqueue.h')
-rw-r--r--src/checkqueue.h59
1 files changed, 36 insertions, 23 deletions
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 <boost/thread/locks.hpp>
#include <boost/thread/mutex.hpp>
-template<typename T> class CCheckQueueControl;
+template <typename T>
+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<typename T> 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<typename T> class CCheckQueue {
+template <typename T>
+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<T> 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<T> &vChecks) {
+ void Add(std::vector<T>& vChecks)
+ {
boost::unique_lock<boost::mutex> 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<T>;
@@ -157,13 +164,16 @@ public:
/** RAII-style controller object for a CCheckQueue that guarantees the passed
* queue is finished before continuing.
*/
-template<typename T> class CCheckQueueControl {
+template <typename T>
+class CCheckQueueControl
+{
private:
- CCheckQueue<T> *pqueue;
+ CCheckQueue<T>* pqueue;
bool fDone;
public:
- CCheckQueueControl(CCheckQueue<T> *pqueueIn) : pqueue(pqueueIn), fDone(false) {
+ 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);
@@ -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<T> &vChecks) {
+ void Add(std::vector<T>& vChecks)
+ {
if (pqueue != NULL)
pqueue->Add(vChecks);
}
- ~CCheckQueueControl() {
+ ~CCheckQueueControl()
+ {
if (!fDone)
Wait();
}