5 #ifndef BITCOIN_CHECKQUEUE_H
6 #define BITCOIN_CHECKQUEUE_H
13 #include <boost/thread/condition_variable.hpp>
14 #include <boost/thread/mutex.hpp>
66 bool Loop(
bool fMaster =
false)
69 std::vector<T> vChecks;
71 unsigned int nNow = 0;
75 boost::unique_lock<boost::mutex> lock(
mutex);
80 if (
nTodo == 0 && !fMaster)
88 while (
queue.empty()) {
89 if (fMaster &&
nTodo == 0) {
107 vChecks.resize(nNow);
108 for (
unsigned int i = 0; i < nNow; i++) {
111 vChecks[i].swap(
queue.back());
118 for (T& check : vChecks)
145 void Add(std::vector<T>& vChecks)
147 boost::unique_lock<boost::mutex> lock(
mutex);
148 for (T& check : vChecks) {
149 queue.push_back(T());
150 check.swap(
queue.back());
152 nTodo += vChecks.size();
153 if (vChecks.size() == 1)
155 else if (vChecks.size() > 1)
169 template <
typename T>
192 bool fRet =
pqueue->Wait();
197 void Add(std::vector<T>& vChecks)
213 #endif // BITCOIN_CHECKQUEUE_H
void Add(std::vector< T > &vChecks)
boost::condition_variable condWorker
Worker threads block on this when out of work.
boost::mutex mutex
Mutex to protect the inner state.
boost::condition_variable condMaster
Master thread blocks on this when out of work.
bool Loop(bool fMaster=false)
Internal function that does bulk of the verification work.
CCheckQueueControl(CCheckQueue< T > *const pqueueIn)
void Thread()
Worker thread.
RAII-style controller object for a CCheckQueue that guarantees the passed queue is finished before co...
CCheckQueueControl()=delete
CCheckQueue(unsigned int nBatchSizeIn)
Create a new check queue.
std::vector< T > queue
The queue of elements to be processed.
bool fAllOk
The temporary evaluation result.
#define LEAVE_CRITICAL_SECTION(cs)
int nTotal
The total number of workers (including the master).
Queue for verifications that have to be performed.
CCheckQueue< T > *const pqueue
#define ENTER_CRITICAL_SECTION(cs)
bool Wait()
Wait until execution finishes, and return whether all evaluations were successful.
int nIdle
The number of workers (including the master) that are idle.
unsigned int nTodo
Number of verifications that haven't completed yet.
void Add(std::vector< T > &vChecks)
Add a batch of checks to the queue.
unsigned int nBatchSize
The maximum number of elements to be processed in one batch.
CCheckQueueControl & operator=(const CCheckQueueControl &)=delete
boost::mutex ControlMutex
Mutex to ensure only one concurrent CCheckQueueControl.