libhomegear-base
0.7
Base library for Homegear and Homegear family modules.
|
This class implements a queue after the producer-consumer paradigm. More...
#include <IQueue.h>
Public Member Functions | |
IQueue (SharedObjects *baseLib, uint32_t queueCount, uint32_t bufferSize) | |
Constructor. More... | |
virtual | ~IQueue () |
void | startQueue (int32_t index, bool waitWhenFull, uint32_t processingThreadCount, int32_t threadPriority=0, int32_t threadPolicy=SCHED_OTHER) |
Starts the threads of a queue. More... | |
void | startQueue (int32_t index, bool waitWhenFull, uint32_t initialProcessingThreadCount, uint32_t maxProcessingThreadCount) |
Starts the threads of a queue using a thread count that can be increased later. More... | |
void | stopQueue (int32_t index) |
Stops the threads of a queue previously started with startQueue() . More... | |
bool | queueIsStarted (int32_t index) |
Checks if the specified queue has been started. More... | |
bool | addThread (int32_t index) |
Start an additional thread. More... | |
bool | enqueue (int32_t index, std::shared_ptr< IQueueEntry > &entry, bool waitWhenFull=false) |
Enqueues an item. More... | |
virtual void | processQueueEntry (int32_t index, std::shared_ptr< IQueueEntry > &entry)=0 |
This method is called by the processing threads for each item to process. More... | |
bool | queueEmpty (int32_t index) |
Checks if a queue is empty. More... | |
uint32_t | processingThreadCount (int32_t index) |
Returns the number of processing threads. More... | |
uint32_t | maxProcessingThreadCount (int32_t index) |
Returns the maximum number of processing threads. More... | |
int32_t | queueSize (int32_t index) |
Returns the number of items queued in a queue. More... | |
double | threadLoad (int32_t index) |
double | maxThreadLoad (int32_t index) |
double | maxThreadLoad1m (int32_t index) |
double | maxThreadLoad10m (int32_t index) |
double | maxThreadLoad1h (int32_t index) |
int64_t | maxWait (int32_t index) |
int64_t | maxWait1m (int32_t index) |
int64_t | maxWait10m (int32_t index) |
int64_t | maxWait1h (int32_t index) |
Public Member Functions inherited from BaseLib::IQueueBase | |
IQueueBase (SharedObjects *baseLib, uint32_t queueCount) | |
virtual | ~IQueueBase () |
void | printQueueFullError (BaseLib::Output &out, const std::string &message) |
Prints a rate limited (1 output per 10 seconds) error message and keeps count of error messages. More... | |
Additional Inherited Members | |
Protected Attributes inherited from BaseLib::IQueueBase | |
SharedObjects * | _bl = nullptr |
int32_t | _queueCount = 2 |
std::unique_ptr< std::atomic_bool[]> | _stopProcessingThread |
std::atomic< uint32_t > | _droppedEntries {0} |
std::atomic< int64_t > | _lastQueueFullError {0} |
This class implements a queue after the producer-consumer paradigm.
It can manage one or more queues. Your class needs to be derived from IQueue
to use it.
BaseLib::IQueue::IQueue | ( | SharedObjects * | baseLib, |
uint32_t | queueCount, | ||
uint32_t | bufferSize | ||
) |
Constructor.
baseLib | A base library object. |
queueCount | The number of queues to initialize. |
bufferSize | The maximum number of items allowed to be queued. |
|
virtual |
bool BaseLib::IQueue::addThread | ( | int32_t | index | ) |
Start an additional thread.
index | The index of the queue to add the new thread. |
bool BaseLib::IQueue::enqueue | ( | int32_t | index, |
std::shared_ptr< IQueueEntry > & | entry, | ||
bool | waitWhenFull = false |
||
) |
Enqueues an item.
index | The index of the queue to enqueue the item into. |
entry | The item to queue. |
waitWhenFull | When set to true the method waits until the queue is empty enough to queue the item. When waitWhenFull is set to true in startQueue() , this argument is ignored. |
true
if the item was successfully queued and false
otherwise. uint32_t BaseLib::IQueue::maxProcessingThreadCount | ( | int32_t | index | ) |
Returns the maximum number of processing threads.
double BaseLib::IQueue::maxThreadLoad | ( | int32_t | index | ) |
double BaseLib::IQueue::maxThreadLoad10m | ( | int32_t | index | ) |
double BaseLib::IQueue::maxThreadLoad1h | ( | int32_t | index | ) |
double BaseLib::IQueue::maxThreadLoad1m | ( | int32_t | index | ) |
int64_t BaseLib::IQueue::maxWait | ( | int32_t | index | ) |
int64_t BaseLib::IQueue::maxWait10m | ( | int32_t | index | ) |
int64_t BaseLib::IQueue::maxWait1h | ( | int32_t | index | ) |
int64_t BaseLib::IQueue::maxWait1m | ( | int32_t | index | ) |
uint32_t BaseLib::IQueue::processingThreadCount | ( | int32_t | index | ) |
Returns the number of processing threads.
|
pure virtual |
This method is called by the processing threads for each item to process.
It needs to be implemented by the derived class.
index | The index of the queue. |
entry | The queued item to process. |
bool BaseLib::IQueue::queueEmpty | ( | int32_t | index | ) |
Checks if a queue is empty.
index | The index of the queue to check. |
true
if the queue is empty. bool BaseLib::IQueue::queueIsStarted | ( | int32_t | index | ) |
Checks if the specified queue has been started.
int32_t BaseLib::IQueue::queueSize | ( | int32_t | index | ) |
Returns the number of items queued in a queue.
index | The index of the queue to check. |
void BaseLib::IQueue::startQueue | ( | int32_t | index, |
bool | waitWhenFull, | ||
uint32_t | processingThreadCount, | ||
int32_t | threadPriority = 0 , |
||
int32_t | threadPolicy = SCHED_OTHER |
||
) |
Starts the threads of a queue.
index | The index of the queue to start. The number of queues is defined by queueCount in the constructor. |
waitWhenFull | When set to true , enqueue() waits until the queue is empty enough to queue the provided item. This takes precedence over the argument waitWhenFull of enqueue() . |
processingThreadCount | The number of processing threads to start. |
threadPriority | The thread priority to set. Default is 0 (= disabled). The thread priority values depends on threadPolicy . See man sched for more details. |
threadPolicy | The thread policy to use. Default is SCHED_OTHER (= disabled). See man sched for more details. |
void BaseLib::IQueue::startQueue | ( | int32_t | index, |
bool | waitWhenFull, | ||
uint32_t | initialProcessingThreadCount, | ||
uint32_t | maxProcessingThreadCount | ||
) |
Starts the threads of a queue using a thread count that can be increased later.
index | The index of the queue to start. The number of queues is defined by queueCount in the constructor. |
waitWhenFull | When set to true , enqueue() waits until the queue is empty enough to queue the provided item. This takes precedence over the argument waitWhenFull of enqueue() . |
initialProcessingThreadCount | The number of processing threads to start with the call of this method. |
maxProcessingThreadCount | The number maximum number of processing threads that can be started. |
void BaseLib::IQueue::stopQueue | ( | int32_t | index | ) |
Stops the threads of a queue previously started with startQueue()
.
index | The index of the queue to stop. |
double BaseLib::IQueue::threadLoad | ( | int32_t | index | ) |