7 #include <boost/thread/mutex.hpp>
8 #include <boost/thread/locks.hpp>
9 #include <boost/thread/condition_variable.hpp>
61 bool Loop(
bool fMaster =
false) {
62 boost::condition_variable &cond = fMaster ? condMaster :
condWorker;
63 std::vector<T> vChecks;
64 vChecks.reserve(nBatchSize);
65 unsigned int nNow = 0;
69 boost::unique_lock<boost::mutex> lock(mutex);
74 if (nTodo == 0 && !fMaster)
76 condMaster.notify_one();
82 while (queue.empty()) {
83 if ((fMaster || fQuit) && nTodo == 0) {
101 nNow = std::max(1U, std::min(nBatchSize, (
unsigned int)queue.size() / (nTotal + nIdle + 1)));
102 vChecks.resize(nNow);
103 for (
unsigned int i = 0; i < nNow; i++) {
106 vChecks[i].swap(queue.back());
113 BOOST_FOREACH(T &check, vChecks)
123 nIdle(0), nTotal(0), fAllOk(true), nTodo(0), fQuit(false), nBatchSize(nBatchSizeIn) {}
136 void Add(std::vector<T> &vChecks) {
137 boost::unique_lock<boost::mutex> lock(mutex);
138 BOOST_FOREACH(T &check, vChecks) {
139 queue.push_back(T());
140 check.swap(queue.back());
142 nTodo += vChecks.size();
143 if (vChecks.size() == 1)
144 condWorker.notify_one();
145 else if (vChecks.size() > 1)
146 condWorker.notify_all();
166 if (pqueue != NULL) {
168 assert(pqueue->
nTodo == 0);
169 assert(pqueue->
fAllOk ==
true);
176 bool fRet = pqueue->
Wait();
181 void Add(std::vector<T> &vChecks) {
183 pqueue->
Add(vChecks);
boost::condition_variable condWorker
boost::condition_variable condMaster
bool Loop(bool fMaster=false)
CCheckQueue(unsigned int nBatchSizeIn)
CCheckQueue< T > * pqueue
CCheckQueueControl(CCheckQueue< T > *pqueueIn)
Queue for verifications that have to be performed.
void Add(std::vector< T > &vChecks)
void Add(std::vector< T > &vChecks)
RAII-style controller object for a CCheckQueue that guarantees the passed queue is finished before co...