RSC
0.16.0
|
A queue with synchronized access and interruption support. More...
#include <SynchronizedQueue.h>
Public Types | |
typedef boost::function< void(const M &drop)> | dropHandlerType |
Public Member Functions | |
SynchronizedQueue (const unsigned int &sizeLimit=0, dropHandlerType dropHandler=0) | |
Creates a new queue. More... | |
virtual | ~SynchronizedQueue () |
void | push (const M &message) |
Pushes a new element on the queue and wakes up one waiting client if there is one. More... | |
M | peek (const boost::uint32_t &timeoutMs=0) |
Returns the element at the front of the queue without removing it, waiting until there is such an element if necessary. More... | |
M | pop (const boost::uint32_t &timeoutMs=0) |
Returns the next element form the queue and wait until there is such an element. More... | |
M | tryPop () |
Tries to pop an element from the queue but does not wait if there is no element on the queue. More... | |
bool | empty () const |
Checks whether this queue is empty. More... | |
std::size_t | size () const |
Return element count of the queue. More... | |
void | clear () |
Remove all elements from the queue. More... | |
void | interrupt () |
Interrupts the processing on this queue for every current call to pop and any later call. More... | |
Private Attributes | |
volatile bool | interrupted |
std::queue< M > | queue |
boost::recursive_mutex | mutex |
boost::condition | condition |
unsigned int | sizeLimit |
dropHandlerType | dropHandler |
A queue with synchronized access and interruption support.
On push operations only one waiting thread is woken up.
M | message type handled in this queue |
Definition at line 62 of file SynchronizedQueue.h.
typedef boost::function<void(const M& drop)> rsc::threading::SynchronizedQueue< M >::dropHandlerType |
Definition at line 65 of file SynchronizedQueue.h.
|
inlineexplicit |
Creates a new queue.
sizeLimit | max allowed size of the queue. If the limit is reached and another element is added to the queue, the oldest element is removed. 0 means unlimited |
Definition at line 86 of file SynchronizedQueue.h.
|
inlinevirtual |
Definition at line 91 of file SynchronizedQueue.h.
|
inline |
Remove all elements from the queue.
Definition at line 250 of file SynchronizedQueue.h.
|
inline |
Checks whether this queue is empty.
Is not affected by the interruption flag.
true
if empty, else false
Definition at line 232 of file SynchronizedQueue.h.
|
inline |
Interrupts the processing on this queue for every current call to pop and any later call.
All of them will return with an exception.
Definition at line 262 of file SynchronizedQueue.h.
|
inline |
Returns the element at the front of the queue without removing it, waiting until there is such an element if necessary.
timeoutMs | maximum time spent waiting for a new element in milliseconds. Zero indicates to wait endlessly. |
InterruptedException | if interrupt was called before a call to this method or while waiting for an element |
QueueEmptyException | thrown if |
timeoutMs | was > 0 and no element was found on the queue in the specified time |
Definition at line 134 of file SynchronizedQueue.h.
|
inline |
Returns the next element form the queue and wait until there is such an element.
The returned element is removed from the queue immediately.
timeoutMs | maximum time spent waiting for a new element in milliseconds. Zero indicates to wait endlessly. Use tryPop if you want to get a result without waiting |
InterruptedException | if interrupt was called before a call to this method or while waiting for an element |
QueueEmptyException | thrown if |
timeoutMs | was > 0 and no element was found on the queue in the specified time |
Definition at line 175 of file SynchronizedQueue.h.
|
inline |
Pushes a new element on the queue and wakes up one waiting client if there is one.
message | element to push on the queue |
Definition at line 104 of file SynchronizedQueue.h.
|
inline |
Return element count of the queue.
Definition at line 242 of file SynchronizedQueue.h.
|
inline |
Tries to pop an element from the queue but does not wait if there is no element on the queue.
QueueEmptyException | the queue was empty |
Definition at line 212 of file SynchronizedQueue.h.
|
private |
Definition at line 72 of file SynchronizedQueue.h.
|
private |
Definition at line 74 of file SynchronizedQueue.h.
|
private |
Definition at line 69 of file SynchronizedQueue.h.
|
mutableprivate |
Definition at line 71 of file SynchronizedQueue.h.
|
private |
Definition at line 70 of file SynchronizedQueue.h.
|
private |
Definition at line 73 of file SynchronizedQueue.h.