5 #ifndef BITCOIN_CHECKQUEUE_H
6 #define BITCOIN_CHECKQUEUE_H
11 #include <boost/foreach.hpp>
12 #include <boost/thread/condition_variable.hpp>
13 #include <boost/thread/locks.hpp>
14 #include <boost/thread/mutex.hpp>
69 bool Loop(
bool fMaster =
false)
72 std::vector<T> vChecks;
74 unsigned int nNow = 0;
78 boost::unique_lock<boost::mutex> lock(
mutex);
83 if (
nTodo == 0 && !fMaster)
91 while (
queue.empty()) {
111 vChecks.resize(nNow);
112 for (
unsigned int i = 0; i < nNow; i++) {
115 vChecks[i].swap(
queue.back());
122 BOOST_FOREACH (T& check, vChecks)
149 void Add(std::vector<T>& vChecks)
151 boost::unique_lock<boost::mutex> lock(
mutex);
152 BOOST_FOREACH (T& check, vChecks) {
153 queue.push_back(T());
154 check.swap(
queue.back());
156 nTodo += vChecks.size();
157 if (vChecks.size() == 1)
159 else if (vChecks.size() > 1)
173 template <
typename T>
196 bool fRet =
pqueue->Wait();
201 void Add(std::vector<T>& vChecks)
RAII-style controller object for a CCheckQueue that guarantees the passed queue is finished before co...
CCheckQueue< T > *const pqueue
CCheckQueueControl(CCheckQueue< T > *const pqueueIn)
CCheckQueueControl()=delete
CCheckQueueControl & operator=(const CCheckQueueControl &)=delete
void Add(std::vector< T > &vChecks)
CCheckQueueControl(const CCheckQueueControl &)=delete
Queue for verifications that have to be performed.
unsigned int nTodo
Number of verifications that haven't completed yet.
bool fAllOk
The temporary evaluation result.
int nIdle
The number of workers (including the master) that are idle.
bool Loop(bool fMaster=false)
Internal function that does bulk of the verification work.
std::vector< T > queue
The queue of elements to be processed.
bool fQuit
Whether we're shutting down.
bool Wait()
Wait until execution finishes, and return whether all evaluations were successful.
boost::mutex ControlMutex
Mutex to ensure only one concurrent CCheckQueueControl.
boost::condition_variable condMaster
Master thread blocks on this when out of work.
int nTotal
The total number of workers (including the master).
boost::condition_variable condWorker
Worker threads block on this when out of work.
CCheckQueue(unsigned int nBatchSizeIn)
Create a new check queue.
void Thread()
Worker thread.
unsigned int nBatchSize
The maximum number of elements to be processed in one batch.
boost::mutex mutex
Mutex to protect the inner state.
void Add(std::vector< T > &vChecks)
Add a batch of checks to the queue.
#define ENTER_CRITICAL_SECTION(cs)
#define LEAVE_CRITICAL_SECTION(cs)