Worker class for LoadBalancer. More...
#include <DwmLoadBalancer.hh>

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 |
Worker class for LoadBalancer.
|
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.
|
inline |
Adds a work item for the worker.
Returns true on success, false on failure. A reason for failure: the work queue is full.

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

|
pure virtual |
Pure virtual member to process a single work item.
Obviously must be implemented by derived classes.
|
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.
|
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.