Fabcoin Core  0.16.2
P2P Digital Currency
Classes | Public Member Functions | Private Attributes | List of all members
WorkQueue< WorkItem > Class Template Reference

Simple work queue for distributing work over multiple threads. More...

Classes

class  ThreadCounter
 RAII object to keep track of number of running worker threads. More...
 

Public Member Functions

 WorkQueue (size_t _maxDepth)
 
 ~WorkQueue ()
 Precondition: worker threads have all stopped (call WaitExit) More...
 
bool Enqueue (WorkItem *item)
 Enqueue a work item. More...
 
void Run ()
 Thread function. More...
 
void Interrupt ()
 Interrupt and exit loops. More...
 
void WaitExit ()
 Wait for worker threads to exit. More...
 

Private Attributes

std::mutex cs
 Mutex protects entire object. More...
 
std::condition_variable cond
 
std::deque< std::unique_ptr< WorkItem > > queue
 
bool running
 
size_t maxDepth
 
int numThreads
 

Detailed Description

template<typename WorkItem>
class WorkQueue< WorkItem >

Simple work queue for distributing work over multiple threads.

Work items are simply callable objects.

Definition at line 68 of file httpserver.cpp.

Constructor & Destructor Documentation

template<typename WorkItem>
WorkQueue< WorkItem >::WorkQueue ( size_t  _maxDepth)
inline

Definition at line 98 of file httpserver.cpp.

template<typename WorkItem>
WorkQueue< WorkItem >::~WorkQueue ( )
inline

Precondition: worker threads have all stopped (call WaitExit)

Definition at line 106 of file httpserver.cpp.

Member Function Documentation

template<typename WorkItem>
bool WorkQueue< WorkItem >::Enqueue ( WorkItem *  item)
inline

Enqueue a work item.

Definition at line 110 of file httpserver.cpp.

template<typename WorkItem>
void WorkQueue< WorkItem >::Interrupt ( )
inline

Interrupt and exit loops.

Definition at line 139 of file httpserver.cpp.

Here is the caller graph for this function:

template<typename WorkItem>
void WorkQueue< WorkItem >::Run ( )
inline

Thread function.

Definition at line 121 of file httpserver.cpp.

template<typename WorkItem>
void WorkQueue< WorkItem >::WaitExit ( )
inline

Wait for worker threads to exit.

Definition at line 146 of file httpserver.cpp.

Here is the caller graph for this function:

Member Data Documentation

template<typename WorkItem>
std::condition_variable WorkQueue< WorkItem >::cond
private

Definition at line 73 of file httpserver.cpp.

template<typename WorkItem>
std::mutex WorkQueue< WorkItem >::cs
private

Mutex protects entire object.

Definition at line 72 of file httpserver.cpp.

template<typename WorkItem>
size_t WorkQueue< WorkItem >::maxDepth
private

Definition at line 76 of file httpserver.cpp.

template<typename WorkItem>
int WorkQueue< WorkItem >::numThreads
private

Definition at line 77 of file httpserver.cpp.

template<typename WorkItem>
std::deque<std::unique_ptr<WorkItem> > WorkQueue< WorkItem >::queue
private

Definition at line 74 of file httpserver.cpp.

template<typename WorkItem>
bool WorkQueue< WorkItem >::running
private

Definition at line 75 of file httpserver.cpp.


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