5 #ifndef BITCOIN_CHECKQUEUE_H 6 #define BITCOIN_CHECKQUEUE_H 11 #include <boost/foreach.hpp> 12 #include <boost/thread/condition_variable.hpp> 13 #include <boost/thread/locks.hpp> 14 #include <boost/thread/mutex.hpp> 69 bool Loop(
bool fMaster =
false)
72 std::vector<T> vChecks;
74 unsigned int nNow = 0;
78 boost::unique_lock<boost::mutex> lock(
mutex);
83 if (
nTodo == 0 && !fMaster)
91 while (
queue.empty()) {
111 vChecks.resize(nNow);
112 for (
unsigned int i = 0; i < nNow; i++) {
115 vChecks[i].swap(
queue.back());
122 BOOST_FOREACH (T& check, vChecks)
146 void Add(std::vector<T>& vChecks)
148 boost::unique_lock<boost::mutex> lock(
mutex);
149 BOOST_FOREACH (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)
166 boost::unique_lock<boost::mutex> lock(
mutex);
176 template <
typename T>
188 bool isIdle =
pqueue->IsIdle();
197 bool fRet =
pqueue->Wait();
202 void Add(std::vector<T>& vChecks)
215 #endif // BITCOIN_CHECKQUEUE_H CCheckQueue< T > * pqueue
void Add(std::vector< T > &vChecks)
Add a batch of checks to the queue.
void Thread()
Worker thread.
void Add(std::vector< T > &vChecks)
unsigned int nBatchSize
The maximum number of elements to be processed in one batch.
boost::mutex mutex
Mutex to protect the inner state.
bool fAllOk
The temporary evaluation result.
int nIdle
The number of workers (including the master) that are idle.
bool fQuit
Whether we're shutting down.
int nTotal
The total number of workers (including the master).
boost::condition_variable condMaster
Master thread blocks on this when out of work.
CCheckQueueControl(CCheckQueue< T > *pqueueIn)
CCheckQueue(unsigned int nBatchSizeIn)
Create a new check queue.
bool Loop(bool fMaster=false)
boost::condition_variable condWorker
Worker threads block on this when out of work.
bool Wait()
Wait until execution finishes, and return whether all evaluations were successful.