5 #ifndef PIVX_CHECKQUEUE_H
6 #define PIVX_CHECKQUEUE_H
11 #include <boost/thread/condition_variable.hpp>
12 #include <boost/thread/mutex.hpp>
64 bool Loop(
bool fMaster =
false)
67 std::vector<T> vChecks;
69 unsigned int nNow = 0;
73 boost::unique_lock<boost::mutex> lock(
mutex);
78 if (
nTodo == 0 && !fMaster)
86 while (
queue.empty()) {
87 if (fMaster &&
nTodo == 0) {
106 vChecks.resize(nNow);
107 for (
unsigned int i = 0; i < nNow; i++) {
110 vChecks[i].swap(
queue.back());
117 for (
T& check : vChecks)
141 void Add(std::vector<T>& vChecks)
143 boost::unique_lock<boost::mutex> lock(
mutex);
144 for (
T& check : vChecks) {
146 check.swap(
queue.back());
148 nTodo += vChecks.size();
149 if (vChecks.size() == 1)
151 else if (vChecks.size() > 1)
161 boost::unique_lock<boost::mutex> lock(
mutex);
170 template <
typename T>
182 bool isIdle =
pqueue->IsIdle();
191 bool fRet =
pqueue->Wait();
196 void Add(std::vector<T>& vChecks)
RAII-style controller object for a CCheckQueue that guarantees the passed queue is finished before co...
CCheckQueue< T > * pqueue
void Add(std::vector< T > &vChecks)
CCheckQueueControl(CCheckQueue< T > *pqueueIn)
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 where successful.
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 T(expected, seed, data)