12 #include <boost/foreach.hpp>
13 #include <boost/thread/condition_variable.hpp>
14 #include <boost/thread/locks.hpp>
15 #include <boost/thread/mutex.hpp>
64 bool Loop(
bool fMaster =
false) {
65 boost::condition_variable &cond = fMaster ? condMaster :
condWorker;
66 std::vector<T> vChecks;
67 vChecks.reserve(nBatchSize);
68 unsigned int nNow = 0;
72 boost::unique_lock<boost::mutex> lock(mutex);
77 if (nTodo == 0 && !fMaster)
79 condMaster.notify_one();
85 while (queue.empty()) {
86 if ((fMaster || fQuit) && nTodo == 0) {
104 nNow = std::max(1U, std::min(nBatchSize, (
unsigned int)queue.size() / (nTotal + nIdle + 1)));
105 vChecks.resize(nNow);
106 for (
unsigned int i = 0; i < nNow; i++) {
109 vChecks[i].swap(queue.back());
116 BOOST_FOREACH(T &check, vChecks)
126 nIdle(0), nTotal(0), fAllOk(true), nTodo(0), fQuit(false), nBatchSize(nBatchSizeIn) {}
139 void Add(std::vector<T> &vChecks) {
140 boost::unique_lock<boost::mutex> lock(mutex);
141 BOOST_FOREACH(T &check, vChecks) {
142 queue.push_back(T());
143 check.swap(queue.back());
145 nTodo += vChecks.size();
146 if (vChecks.size() == 1)
147 condWorker.notify_one();
148 else if (vChecks.size() > 1)
149 condWorker.notify_all();
169 if (pqueue != NULL) {
171 assert(pqueue->
nTodo == 0);
172 assert(pqueue->
fAllOk ==
true);
179 bool fRet = pqueue->
Wait();
184 void Add(std::vector<T> &vChecks) {
186 pqueue->
Add(vChecks);
void Add(std::vector< T > &vChecks)
boost::condition_variable condWorker
boost::condition_variable condMaster
bool Loop(bool fMaster=false)
RAII-style controller object for a CCheckQueue that guarantees the passed queue is finished before co...
CCheckQueueControl(CCheckQueue< T > *pqueueIn)
CCheckQueue(unsigned int nBatchSizeIn)
Queue for verifications that have to be performed.
void Add(std::vector< T > &vChecks)
CCheckQueue< T > * pqueue