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)
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 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)