libDwm-0.9.45
Dwm::LoadBalancer< ItemT >::Worker Class Referenceabstract

Worker class for LoadBalancer. More...

#include <DwmLoadBalancer.hh>

Collaboration diagram for Dwm::LoadBalancer< ItemT >::Worker:

Public Member Functions

 Worker (std::chrono::microseconds waitNotEmptyMicroseconds=std::chrono::microseconds(1000))
 Constructs the worker.
 
virtual ~Worker ()
 Destructor. Stops the worker thread.
 
bool AddWork (const ItemT &item)
 Adds a work item for the worker.
 
template<typename InputIterator >
bool AddWork (InputIterator firstIter, InputIterator lastIter)
 Adds work items for the worker.
 
uint32_t QueueLength () const
 Returns the current length of the worker's work queue.
 
bool ReadyForWork () const
 Returns true if the worker is ready for more work (has room in its work queue and is running).
 
bool ReadyForWork (size_t numEntries) const
 Returns true if the worker is ready for numEntries units of work.
 
void MaxWork (uint32_t maxItems)
 Sets the maximum length of the worker's work queue.
 
bool Start ()
 Starts the worker.
 
void Stop ()
 Stops the worker.
 
bool IsRunning ()
 Returns true if the worker's thread is running.
 
void Run ()
 Runs the worker thread.
 
virtual void ProcessWork (ItemT &item)=0
 Pure virtual member to process a single work item.
 
virtual bool ProcessWork (std::deque< ItemT > &items)
 Process a deque of work items.
 
std::chrono::microseconds WaitUsecs () const
 Returns the microseconds we'll wait for queue to be non-empty in our worker thread.
 

Protected Attributes

Thread::Queue< ItemT > _workQueue
 
std::atomic< bool > _keepRunning
 
std::thread _thread
 
std::atomic< std::chrono::microseconds > _waitUsecs
 

Detailed Description

template<typename ItemT>
class Dwm::LoadBalancer< ItemT >::Worker

Worker class for LoadBalancer.

Constructor & Destructor Documentation

◆ Worker()

template<typename ItemT >
Dwm::LoadBalancer< ItemT >::Worker::Worker ( std::chrono::microseconds waitNotEmptyMicroseconds = std::chrono::microseconds(1000))
inline

Constructs the worker.

waitForNotEmptyMicroseconds is the period of time to wait for the work queue to become non-empty before checking again whether or not to continue.

Member Function Documentation

◆ AddWork() [1/2]

template<typename ItemT >
bool Dwm::LoadBalancer< ItemT >::Worker::AddWork ( const ItemT & item)
inline

Adds a work item for the worker.

Returns true on success, false on failure. A reason for failure: the work queue is full.

Here is the call graph for this function:

◆ AddWork() [2/2]

template<typename ItemT >
template<typename InputIterator >
bool Dwm::LoadBalancer< ItemT >::Worker::AddWork ( InputIterator firstIter,
InputIterator lastIter )
inline

Adds work items for the worker.

Returns true on success, false
on failure. Reasons for failure: the work queue is full, or lastIter is equal to firstIter.

Here is the call graph for this function:

◆ ProcessWork() [1/2]

template<typename ItemT >
virtual void Dwm::LoadBalancer< ItemT >::Worker::ProcessWork ( ItemT & item)
pure virtual

Pure virtual member to process a single work item.

Obviously must be implemented by derived classes.

◆ ProcessWork() [2/2]

template<typename ItemT >
virtual bool Dwm::LoadBalancer< ItemT >::Worker::ProcessWork ( std::deque< ItemT > & items)
inlinevirtual

Process a deque of work items.

The default implementation does nothing and returns false. If you impelement this in your derived class, it should return true.

◆ WaitUsecs()

template<typename ItemT >
std::chrono::microseconds Dwm::LoadBalancer< ItemT >::Worker::WaitUsecs ( ) const
inline

Returns the microseconds we'll wait for queue to be non-empty in our worker thread.

This is basically the longest possible time that our worker thread will be idle.


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