5#ifndef BITCOIN_CHECKQUEUE_H
6#define BITCOIN_CHECKQUEUE_H
70 unsigned int nNow = 0;
116 1U, std::min(
nBatchSize, (
unsigned int)queue.size() /
120 std::make_move_iterator(queue.end()));
170 queue.insert(queue.end(), std::make_move_iterator(
vChecks.begin()),
171 std::make_move_iterator(
vChecks.end()));
175 }
else if (
vChecks.size() > 1) {
RAII-style controller object for a CCheckQueue that guarantees the passed queue is finished before co...
CCheckQueueControl & operator=(const CCheckQueueControl &)=delete
CCheckQueue< T > *const pqueue
CCheckQueueControl(CCheckQueue< T > *const pqueueIn)
CCheckQueueControl()=delete
void Add(std::vector< T > &&vChecks)
CCheckQueueControl(const CCheckQueueControl &)=delete
Queue for verifications that have to be performed.
const unsigned int nBatchSize
The maximum number of elements to be processed in one batch.
std::condition_variable m_master_cv
Master thread blocks on this when out of work.
bool fAllOk GUARDED_BY(m_mutex)
The temporary evaluation result.
bool m_request_stop GUARDED_BY(m_mutex)
bool Loop(bool fMaster) EXCLUSIVE_LOCKS_REQUIRED(!m_mutex)
Internal function that does bulk of the verification work.
int nTotal GUARDED_BY(m_mutex)
The total number of workers (including the master).
std::vector< std::thread > m_worker_threads
Mutex m_control_mutex
Mutex to ensure only one concurrent CCheckQueueControl.
std::condition_variable m_worker_cv
Worker threads block on this when out of work.
Mutex m_mutex
Mutex to protect the inner state.
bool Wait() EXCLUSIVE_LOCKS_REQUIRED(!m_mutex)
Wait until execution finishes, and return whether all evaluations were successful.
void StartWorkerThreads(const int threads_num) EXCLUSIVE_LOCKS_REQUIRED(!m_mutex)
Create a pool of new worker threads.
CCheckQueue(unsigned int nBatchSizeIn)
Create a new check queue.
void Add(std::vector< T > &&vChecks) EXCLUSIVE_LOCKS_REQUIRED(!m_mutex)
Add a batch of checks to the queue.
int nIdle GUARDED_BY(m_mutex)
The number of workers (including the master) that are idle.
unsigned int nTodo GUARDED_BY(m_mutex)
Number of verifications that haven't completed yet.
void StopWorkerThreads() EXCLUSIVE_LOCKS_REQUIRED(!m_mutex)
Stop all of the worker threads.
std::vector< T > queue GUARDED_BY(m_mutex)
The queue of elements to be processed.
void ThreadRename(std::string &&)
Rename a thread both in terms of an internal (in-memory) name as well as its system thread name.
T GetRand(T nMax=std::numeric_limits< T >::max()) noexcept
Generate a uniform random integer of type T in the range [0..nMax) nMax defaults to std::numeric_limi...
#define WAIT_LOCK(cs, name)
#define ENTER_CRITICAL_SECTION(cs)
#define LEAVE_CRITICAL_SECTION(cs)
#define WITH_LOCK(cs, code)
Run code while locking a mutex.
#define EXCLUSIVE_LOCKS_REQUIRED(...)