5 #ifndef BITCOIN_CHECKQUEUE_H 6 #define BITCOIN_CHECKQUEUE_H 71 std::vector<T> vChecks;
73 unsigned int nNow = 0;
82 if (nTodo == 0 && !fMaster)
90 while (queue.empty() && !m_request_stop) {
91 if (fMaster && nTodo == 0) {
103 if (m_request_stop) {
112 nNow = std::max(1U, std::min(
nBatchSize, (
unsigned int)queue.size() / (nTotal + nIdle + 1)));
113 vChecks.resize(nNow);
114 for (
unsigned int i = 0; i < nNow; i++) {
117 vChecks[i].swap(queue.back());
124 for (T& check : vChecks)
151 for (
int n = 0; n < threads_num; ++n) {
166 void Add(std::vector<T>& vChecks)
169 for (T& check : vChecks) {
170 queue.push_back(T());
171 check.swap(queue.back());
173 nTodo += vChecks.size();
174 if (vChecks.size() == 1)
176 else if (vChecks.size() > 1)
203 template <
typename T>
226 bool fRet =
pqueue->Wait();
231 void Add(std::vector<T>& vChecks)
247 #endif // BITCOIN_CHECKQUEUE_H std::vector< T > queue GUARDED_BY(m_mutex)
The queue of elements to be processed.
void Add(std::vector< T > &vChecks)
std::condition_variable m_worker_cv
Worker threads block on this when out of work.
std::vector< std::thread > m_worker_threads
bool fAllOk GUARDED_BY(m_mutex)
The temporary evaluation result.
void ThreadRename(std::string &&)
Rename a thread both in terms of an internal (in-memory) name as well as its system thread name...
CCheckQueueControl(CCheckQueue< T > *const pqueueIn)
RAII-style controller object for a CCheckQueue that guarantees the passed queue is finished before co...
CCheckQueueControl()=delete
void StopWorkerThreads()
Stop all of the worker threads.
std::condition_variable m_master_cv
Master thread blocks on this when out of work.
int nTotal GUARDED_BY(m_mutex)
The total number of workers (including the master).
bool Loop(bool fMaster)
Internal function that does bulk of the verification work.
CCheckQueue(unsigned int nBatchSizeIn)
Create a new check queue.
bool m_request_stop GUARDED_BY(m_mutex)
#define LEAVE_CRITICAL_SECTION(cs)
Mutex m_mutex
Mutex to protect the inner state.
#define WAIT_LOCK(cs, name)
Queue for verifications that have to be performed.
Mutex m_control_mutex
Mutex to ensure only one concurrent CCheckQueueControl.
#define WITH_LOCK(cs, code)
Run code while locking a mutex.
CCheckQueue< T > *const pqueue
#define ENTER_CRITICAL_SECTION(cs)
bool Wait()
Wait until execution finishes, and return whether all evaluations were successful.
void Add(std::vector< T > &vChecks)
Add a batch of checks to the queue.
int nIdle GUARDED_BY(m_mutex)
The number of workers (including the master) that are idle.
CCheckQueueControl & operator=(const CCheckQueueControl &)=delete
const unsigned int nBatchSize
The maximum number of elements to be processed in one batch.
void StartWorkerThreads(const int threads_num)
Create a pool of new worker threads.