 |
PRCYCoin
2.0.0.7rc1
P2P Digital Currency
|
Go to the documentation of this file.
5 #ifndef BITCOIN_CHECKQUEUE_H
6 #define BITCOIN_CHECKQUEUE_H
11 #include <boost/thread/condition_variable.hpp>
12 #include <boost/thread/locks.hpp>
13 #include <boost/thread/mutex.hpp>
68 bool Loop(
bool fMaster =
false)
71 std::vector<T> vChecks;
73 unsigned int nNow = 0;
77 boost::unique_lock<boost::mutex> lock(
mutex);
82 if (
nTodo == 0 && !fMaster)
90 while (
queue.empty()) {
110 vChecks.resize(nNow);
111 for (
unsigned int i = 0; i < nNow; i++) {
114 vChecks[i].swap(
queue.back());
121 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)
165 boost::unique_lock<boost::mutex> lock(
mutex);
174 template <
typename T>
186 bool isIdle =
pqueue->IsIdle();
195 bool fRet =
pqueue->Wait();
200 void Add(std::vector<T>& vChecks)
213 #endif // BITCOIN_CHECKQUEUE_H
bool Loop(bool fMaster=false)
Internal function that does bulk of the verification work.
unsigned int nTodo
Number of verifications that haven't completed yet.
CCheckQueue< T > * pqueue
void Thread()
Worker thread.
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.
boost::condition_variable condWorker
Worker threads block on this when out of work.
void Add(std::vector< T > &vChecks)
bool fQuit
Whether we're shutting down.
Queue for verifications that have to be performed.
boost::mutex mutex
Mutex to protect the inner state.
RAII-style controller object for a CCheckQueue that guarantees the passed queue is finished before co...
int nTotal
The total number of workers (including the master).
CCheckQueueControl(CCheckQueue< T > *pqueueIn)
unsigned int nBatchSize
The maximum number of elements to be processed in one batch.
void Add(std::vector< T > &vChecks)
Add a batch of checks to the queue.
int nIdle
The number of workers (including the master) that are idle.
boost::condition_variable condMaster
Master thread blocks on this when out of work.
bool Wait()
Wait until execution finishes, and return whether all evaluations where successful.