11 #include <boost/foreach.hpp>
12 #include <boost/thread/condition_variable.hpp>
13 #include <boost/thread/locks.hpp>
14 #include <boost/thread/mutex.hpp>
63 bool Loop(
bool fMaster =
false) {
64 boost::condition_variable &cond = fMaster ? condMaster :
condWorker;
65 std::vector<T> vChecks;
66 vChecks.reserve(nBatchSize);
67 unsigned int nNow = 0;
71 boost::unique_lock<boost::mutex> lock(mutex);
76 if (nTodo == 0 && !fMaster)
78 condMaster.notify_one();
84 while (queue.empty()) {
85 if ((fMaster || fQuit) && nTodo == 0) {
103 nNow = std::max(1U, std::min(nBatchSize, (
unsigned int)queue.size() / (nTotal + nIdle + 1)));
104 vChecks.resize(nNow);
105 for (
unsigned int i = 0; i < nNow; i++) {
108 vChecks[i].swap(queue.back());
115 BOOST_FOREACH(T &check, vChecks)
125 nIdle(0), nTotal(0), fAllOk(true), nTodo(0), fQuit(false), nBatchSize(nBatchSizeIn) {}
138 void Add(std::vector<T> &vChecks) {
139 boost::unique_lock<boost::mutex> lock(mutex);
140 BOOST_FOREACH(T &check, vChecks) {
141 queue.push_back(T());
142 check.swap(queue.back());
144 nTodo += vChecks.size();
145 if (vChecks.size() == 1)
146 condWorker.notify_one();
147 else if (vChecks.size() > 1)
148 condWorker.notify_all();
168 if (pqueue != NULL) {
170 assert(pqueue->
nTodo == 0);
171 assert(pqueue->
fAllOk ==
true);
178 bool fRet = pqueue->
Wait();
183 void Add(std::vector<T> &vChecks) {
185 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