libDwm-0.6.0
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 (uint32_t waitNotEmptyMicroseconds=1000)
 Constructs the worker. More...
 
virtual ~Worker ()
 Destructor. Stops the worker thread.
 
void AddWork (ItemT item)
 Adds a work item for the worker.
 
template<typename InputIterator >
void 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). More...
 
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. More...
 
virtual bool ProcessWork (std::deque< ItemT > &items)
 Process a deque of work items. More...
 

Protected Attributes

Thread::Queue< ItemT > _workQueue
 
bool _keepRunning
 
std::thread _thread
 
uint32_t _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 ( uint32_t  waitNotEmptyMicroseconds = 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

◆ 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.

◆ ReadyForWork()

template<typename ItemT >
bool Dwm::LoadBalancer< ItemT >::Worker::ReadyForWork ( ) const
inline

Returns true if the worker is ready for more work (has room in its work queue and is running).

Here is the call graph for this function:

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