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

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

Collaboration diagram for WorkQueue< WorkItem >:
[legend]

Public Member Functions

 WorkQueue (size_t _maxDepth)
 
 ~WorkQueue ()=default
 Precondition: worker threads have all stopped (they have been joined). More...
 
bool Enqueue (WorkItem *item) EXCLUSIVE_LOCKS_REQUIRED(!cs)
 Enqueue a work item. More...
 
void Run () EXCLUSIVE_LOCKS_REQUIRED(!cs)
 Thread function. More...
 
void Interrupt () EXCLUSIVE_LOCKS_REQUIRED(!cs)
 Interrupt and exit loops. More...
 

Private Member Functions

std::condition_variable cond GUARDED_BY (cs)
 
std::deque< std::unique_ptr< WorkItem > > queue GUARDED_BY (cs)
 
bool running GUARDED_BY (cs)
 

Private Attributes

Mutex cs
 
const size_t maxDepth
 

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 74 of file httpserver.cpp.

Constructor & Destructor Documentation

◆ WorkQueue()

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

Definition at line 84 of file httpserver.cpp.

◆ ~WorkQueue()

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

Precondition: worker threads have all stopped (they have been joined).

Member Function Documentation

◆ Enqueue()

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

Enqueue a work item.

Definition at line 91 of file httpserver.cpp.

◆ GUARDED_BY() [1/3]

template<typename WorkItem >
std::condition_variable cond WorkQueue< WorkItem >::GUARDED_BY ( cs  )
private

◆ GUARDED_BY() [2/3]

template<typename WorkItem >
std::deque< std::unique_ptr< WorkItem > > queue WorkQueue< WorkItem >::GUARDED_BY ( cs  )
private

◆ GUARDED_BY() [3/3]

template<typename WorkItem >
bool running WorkQueue< WorkItem >::GUARDED_BY ( cs  )
inlineprivate

Definition at line 80 of file httpserver.cpp.

◆ Interrupt()

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

Interrupt and exit loops.

Definition at line 119 of file httpserver.cpp.

◆ Run()

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

Thread function.

Definition at line 102 of file httpserver.cpp.

Here is the caller graph for this function:

Member Data Documentation

◆ cs

template<typename WorkItem >
Mutex WorkQueue< WorkItem >::cs
private

Definition at line 77 of file httpserver.cpp.

◆ maxDepth

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

Definition at line 81 of file httpserver.cpp.


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