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