ONPOSIX
2.0
|
Thread-safe FIFO priority queue class. More...
#include <PosixPrioritySharedQueue.hpp>
Public Member Functions | |
PosixPrioritySharedQueue () | |
Constructor. Initialize the queue. | |
~PosixPrioritySharedQueue () | |
Destructor. Clean up the resources. | |
void | addQueue (const _Priority &prio) |
Adds new priority. | |
void | push (const T &data, const _Priority &prio) |
Insert an new element in the queue. | |
T | pop () |
Extract an element from the queue. | |
void | clear () |
Empties the queue. | |
size_t | size () const |
The current size of the queue. |
Private Member Functions | |
PosixPrioritySharedQueue (const PosixPrioritySharedQueue &) | |
PosixPrioritySharedQueue & | operator= (const PosixPrioritySharedQueue &) |
Private Attributes | |
std::map< _Priority, std::queue< T > > | queues_ |
pthread_cond_t | empty_ |
pthread_mutex_t | mutex_ |
size_t | globalSize_ |
Thread-safe FIFO priority queue class.
No aging techniques are implemented, so that the low priority elements can starve. The class is noncopyable.
The template paramaters are:
Definition at line 24 of file PosixPrioritySharedQueue.hpp.
|
private |
Constructor. Initialize the queue.
runtime_error | if the initialization fails. |
Definition at line 56 of file PosixPrioritySharedQueue.hpp.
Destructor. Clean up the resources.
Definition at line 72 of file PosixPrioritySharedQueue.hpp.
void addQueue | ( | const _Priority & | prio | ) |
Adds new priority.
If the priority already exists does nothing.
prio | The priority to be added. |
Definition at line 85 of file PosixPrioritySharedQueue.hpp.
void clear | ( | ) |
Empties the queue.
In order to efficiently accomplish its task, this function exchanges its content with an empty queue using the specialized version of swap() implemented for the STL container std::map.
Definition at line 151 of file PosixPrioritySharedQueue.hpp.
|
private |
T pop | ( | ) |
Extract an element from the queue.
If the queue is empty the calling thread is blocked.
Definition at line 121 of file PosixPrioritySharedQueue.hpp.
void push | ( | const T & | data, |
const _Priority & | prio | ||
) |
Insert an new element in the queue.
data | The element to be added. |
prio | The priority of the element. |
Definition at line 100 of file PosixPrioritySharedQueue.hpp.
size_t size | ( | ) | const |
The current size of the queue.
Definition at line 165 of file PosixPrioritySharedQueue.hpp.
|
private |
Definition at line 27 of file PosixPrioritySharedQueue.hpp.
|
private |
Definition at line 29 of file PosixPrioritySharedQueue.hpp.
|
mutableprivate |
Definition at line 28 of file PosixPrioritySharedQueue.hpp.
|
private |
Definition at line 26 of file PosixPrioritySharedQueue.hpp.