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) {
108 vChecks.resize(nNow);
109 for (
unsigned int i = 0; i < nNow; i++) {
112 vChecks[i].swap(
queue.back());
119 for (T& check : vChecks)
146 void Add(std::vector<T>& vChecks)
148 boost::unique_lock<boost::mutex> lock(
mutex);
149 for (T& check : vChecks) {
150 queue.push_back(T());
151 check.swap(
queue.back());
153 nTodo += vChecks.size();
154 if (vChecks.size() == 1)
156 else if (vChecks.size() > 1)
170 template <
typename T>
193 bool fRet =
pqueue->Wait();
198 void Add(std::vector<T>& vChecks)
214 #endif // BITCOIN_CHECKQUEUE_H void Add(std::vector< T > &vChecks)
Add a batch of checks to the queue.
Definition: checkqueue.h:146
void Thread()
Worker thread.
Definition: checkqueue.h:134
void Add(std::vector< T > &vChecks)
Definition: checkqueue.h:198
CCheckQueue< T > *const pqueue
Definition: checkqueue.h:174
unsigned int nBatchSize
The maximum number of elements to be processed in one batch.
Definition: checkqueue.h:63
boost::mutex mutex
Mutex to protect the inner state.
Definition: checkqueue.h:34
~CCheckQueue()
Definition: checkqueue.h:160
CCheckQueueControl & operator=(const CCheckQueueControl &)=delete
#define LEAVE_CRITICAL_SECTION(cs)
Definition: sync.h:195
bool fAllOk
The temporary evaluation result.
Definition: checkqueue.h:53
~CCheckQueueControl()
Definition: checkqueue.h:204
#define ENTER_CRITICAL_SECTION(cs)
Definition: sync.h:189
CCheckQueueControl(CCheckQueue< T > *const pqueueIn)
Definition: checkqueue.h:181
int nIdle
The number of workers (including the master) that are idle.
Definition: checkqueue.h:47
unsigned int nTodo
Definition: checkqueue.h:60
bool fDone
Definition: checkqueue.h:175
CCheckQueueControl()=delete
Definition: checkqueue.h:30
std::vector< T > queue
Definition: checkqueue.h:44
int nTotal
The total number of workers (including the master).
Definition: checkqueue.h:50
boost::condition_variable condMaster
Master thread blocks on this when out of work.
Definition: checkqueue.h:40
bool Wait()
Definition: checkqueue.h:189
CCheckQueue(unsigned int nBatchSizeIn)
Create a new check queue.
Definition: checkqueue.h:131
bool Loop(bool fMaster=false)
Definition: checkqueue.h:66
boost::mutex ControlMutex
Mutex to ensure only one concurrent CCheckQueueControl.
Definition: checkqueue.h:128
boost::condition_variable condWorker
Worker threads block on this when out of work.
Definition: checkqueue.h:37
bool Wait()
Wait until execution finishes, and return whether all evaluations were successful.
Definition: checkqueue.h:140
Definition: checkqueue.h:17