Bitcoin ABC 0.30.3
P2P Digital Currency
Public Member Functions | Public Attributes | Private Member Functions | Private Attributes | List of all members
CCheckQueue< T > Class Template Reference

Queue for verifications that have to be performed. More...

#include <checkqueue.h>

Collaboration diagram for CCheckQueue< T >:
[legend]

Public Member Functions

 CCheckQueue (unsigned int nBatchSizeIn)
 Create a new check queue. More...
 
void StartWorkerThreads (const int threads_num) EXCLUSIVE_LOCKS_REQUIRED(!m_mutex)
 Create a pool of new worker threads. More...
 
bool Wait () EXCLUSIVE_LOCKS_REQUIRED(!m_mutex)
 Wait until execution finishes, and return whether all evaluations were successful. More...
 
void Add (std::vector< T > &&vChecks) EXCLUSIVE_LOCKS_REQUIRED(!m_mutex)
 Add a batch of checks to the queue. More...
 
void StopWorkerThreads () EXCLUSIVE_LOCKS_REQUIRED(!m_mutex)
 Stop all of the worker threads. More...
 
 ~CCheckQueue ()
 

Public Attributes

Mutex m_control_mutex
 Mutex to ensure only one concurrent CCheckQueueControl. More...
 

Private Member Functions

std::vector< T > queue GUARDED_BY (m_mutex)
 The queue of elements to be processed. More...
 
int nIdle GUARDED_BY (m_mutex)
 The number of workers (including the master) that are idle. More...
 
int nTotal GUARDED_BY (m_mutex)
 The total number of workers (including the master). More...
 
bool fAllOk GUARDED_BY (m_mutex)
 The temporary evaluation result. More...
 
unsigned int nTodo GUARDED_BY (m_mutex)
 Number of verifications that haven't completed yet. More...
 
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. More...
 

Private Attributes

Mutex m_mutex
 Mutex to protect the inner state. More...
 
std::condition_variable m_worker_cv
 Worker threads block on this when out of work. More...
 
std::condition_variable m_master_cv
 Master thread blocks on this when out of work. More...
 
const unsigned int nBatchSize
 The maximum number of elements to be processed in one batch. More...
 
std::vector< std::thread > m_worker_threads
 

Detailed Description

template<typename T>
class CCheckQueue< T >

Queue for verifications that have to be performed.

The verifications are represented by a type T, which must provide an operator(), returning a bool.

One thread (the master) is assumed to push batches of verifications onto the queue, where they are processed by N-1 worker threads. When the master is done adding work, it temporarily joins the worker pool as an N'th worker, until all jobs are done.

Definition at line 28 of file checkqueue.h.

Constructor & Destructor Documentation

◆ CCheckQueue()

template<typename T >
CCheckQueue< T >::CCheckQueue ( unsigned int  nBatchSizeIn)
inlineexplicit

Create a new check queue.

Definition at line 140 of file checkqueue.h.

◆ ~CCheckQueue()

template<typename T >
CCheckQueue< T >::~CCheckQueue ( )
inline

Definition at line 191 of file checkqueue.h.

Here is the call graph for this function:

Member Function Documentation

◆ Add()

template<typename T >
void CCheckQueue< T >::Add ( std::vector< T > &&  vChecks)
inline

Add a batch of checks to the queue.

Definition at line 168 of file checkqueue.h.

◆ GUARDED_BY() [1/6]

template<typename T >
std::vector< T > queue CCheckQueue< T >::GUARDED_BY ( m_mutex  )
private

The queue of elements to be processed.

As the order of booleans doesn't matter, it is used as a LIFO (stack)

◆ GUARDED_BY() [2/6]

template<typename T >
int nIdle CCheckQueue< T >::GUARDED_BY ( m_mutex  )
inlineprivate

The number of workers (including the master) that are idle.

Definition at line 44 of file checkqueue.h.

◆ GUARDED_BY() [3/6]

template<typename T >
int nTotal CCheckQueue< T >::GUARDED_BY ( m_mutex  )
inlineprivate

The total number of workers (including the master).

Definition at line 47 of file checkqueue.h.

◆ GUARDED_BY() [4/6]

template<typename T >
bool fAllOk CCheckQueue< T >::GUARDED_BY ( m_mutex  )
inlineprivate

The temporary evaluation result.

Definition at line 50 of file checkqueue.h.

◆ GUARDED_BY() [5/6]

template<typename T >
unsigned int nTodo CCheckQueue< T >::GUARDED_BY ( m_mutex  )
inlineprivate

Number of verifications that haven't completed yet.

This includes elements that are no longer queued, but still in the worker's own batches.

Definition at line 57 of file checkqueue.h.

◆ GUARDED_BY() [6/6]

template<typename T >
bool m_request_stop CCheckQueue< T >::GUARDED_BY ( m_mutex  )
inlineprivate

Definition at line 63 of file checkqueue.h.

◆ Loop()

template<typename T >
bool CCheckQueue< T >::Loop ( bool  fMaster)
inlineprivate

Internal function that does bulk of the verification work.

Definition at line 66 of file checkqueue.h.

Here is the caller graph for this function:

◆ StartWorkerThreads()

template<typename T >
void CCheckQueue< T >::StartWorkerThreads ( const int  threads_num)
inline

Create a pool of new worker threads.

Definition at line 144 of file checkqueue.h.

Here is the call graph for this function:

◆ StopWorkerThreads()

template<typename T >
void CCheckQueue< T >::StopWorkerThreads ( )
inline

Stop all of the worker threads.

Definition at line 181 of file checkqueue.h.

◆ Wait()

template<typename T >
bool CCheckQueue< T >::Wait ( )
inline

Wait until execution finishes, and return whether all evaluations were successful.

Definition at line 163 of file checkqueue.h.

Here is the call graph for this function:

Member Data Documentation

◆ m_control_mutex

template<typename T >
Mutex CCheckQueue< T >::m_control_mutex

Mutex to ensure only one concurrent CCheckQueueControl.

Definition at line 137 of file checkqueue.h.

◆ m_master_cv

template<typename T >
std::condition_variable CCheckQueue< T >::m_master_cv
private

Master thread blocks on this when out of work.

Definition at line 37 of file checkqueue.h.

◆ m_mutex

template<typename T >
Mutex CCheckQueue< T >::m_mutex
private

Mutex to protect the inner state.

Definition at line 31 of file checkqueue.h.

◆ m_worker_cv

template<typename T >
std::condition_variable CCheckQueue< T >::m_worker_cv
private

Worker threads block on this when out of work.

Definition at line 34 of file checkqueue.h.

◆ m_worker_threads

template<typename T >
std::vector<std::thread> CCheckQueue< T >::m_worker_threads
private

Definition at line 62 of file checkqueue.h.

◆ nBatchSize

template<typename T >
const unsigned int CCheckQueue< T >::nBatchSize
private

The maximum number of elements to be processed in one batch.

Definition at line 60 of file checkqueue.h.


The documentation for this class was generated from the following file: