Raven Core  3.0.0
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>

Public Member Functions

 CCheckQueue (unsigned int nBatchSizeIn)
 Create a new check queue. More...
 
void Thread ()
 Worker thread. More...
 
bool Wait ()
 Wait until execution finishes, and return whether all evaluations were successful. More...
 
void Add (std::vector< T > &vChecks)
 Add a batch of checks to the queue. More...
 
 ~CCheckQueue ()
 

Public Attributes

boost::mutex ControlMutex
 Mutex to ensure only one concurrent CCheckQueueControl. More...
 

Private Member Functions

bool Loop (bool fMaster=false)
 Internal function that does bulk of the verification work. More...
 

Private Attributes

boost::mutex mutex
 Mutex to protect the inner state. More...
 
boost::condition_variable condWorker
 Worker threads block on this when out of work. More...
 
boost::condition_variable condMaster
 Master thread blocks on this when out of work. More...
 
std::vector< T > queue
 The queue of elements to be processed. More...
 
int nIdle
 The number of workers (including the master) that are idle. More...
 
int nTotal
 The total number of workers (including the master). More...
 
bool fAllOk
 The temporary evaluation result. More...
 
unsigned int nTodo
 Number of verifications that haven't completed yet. More...
 
bool fQuit
 Whether we're shutting down. More...
 
unsigned int nBatchSize
 The maximum number of elements to be processed in one batch. More...
 

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 31 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 135 of file checkqueue.h.

◆ ~CCheckQueue()

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

Definition at line 164 of file checkqueue.h.

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 150 of file checkqueue.h.

Here is the caller graph for this function:

◆ Loop()

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

Internal function that does bulk of the verification work.

Definition at line 70 of file checkqueue.h.

Here is the caller graph for this function:

◆ Thread()

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

Worker thread.

Definition at line 138 of file checkqueue.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Wait()

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

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

Definition at line 144 of file checkqueue.h.

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ condMaster

template<typename T>
boost::condition_variable CCheckQueue< T >::condMaster
private

Master thread blocks on this when out of work.

Definition at line 41 of file checkqueue.h.

◆ condWorker

template<typename T>
boost::condition_variable CCheckQueue< T >::condWorker
private

Worker threads block on this when out of work.

Definition at line 38 of file checkqueue.h.

◆ ControlMutex

template<typename T>
boost::mutex CCheckQueue< T >::ControlMutex

Mutex to ensure only one concurrent CCheckQueueControl.

Definition at line 132 of file checkqueue.h.

◆ fAllOk

template<typename T>
bool CCheckQueue< T >::fAllOk
private

The temporary evaluation result.

Definition at line 54 of file checkqueue.h.

◆ fQuit

template<typename T>
bool CCheckQueue< T >::fQuit
private

Whether we're shutting down.

Definition at line 64 of file checkqueue.h.

◆ mutex

template<typename T>
boost::mutex CCheckQueue< T >::mutex
private

Mutex to protect the inner state.

Definition at line 35 of file checkqueue.h.

◆ nBatchSize

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

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

Definition at line 67 of file checkqueue.h.

◆ nIdle

template<typename T>
int CCheckQueue< T >::nIdle
private

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

Definition at line 48 of file checkqueue.h.

◆ nTodo

template<typename T>
unsigned int CCheckQueue< T >::nTodo
private

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 61 of file checkqueue.h.

◆ nTotal

template<typename T>
int CCheckQueue< T >::nTotal
private

The total number of workers (including the master).

Definition at line 51 of file checkqueue.h.

◆ queue

template<typename T>
std::vector<T> CCheckQueue< T >::queue
private

The queue of elements to be processed.

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

Definition at line 45 of file checkqueue.h.


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