#include <SynchronizedQueue.h>
Public Types | |
using | CallbackFunction = std::function< bool(T &item)> |
Public Member Functions | |
void | push (T &&data) |
void | push (const T &data) |
bool | pop (T &item, std::chrono::milliseconds timeout) |
virtual void | wakeup () |
bool | empty () const |
size_t | size () const |
void | clear () |
bool | each (const CallbackFunction &callbackFunction) |
Synchronized template queue
Simple thread-safe queue
using sptk::SynchronizedQueue< T >::CallbackFunction = std::function<bool(T& item)> |
Queue callback function used in each() method.
Iterates through queue until false is returned.
item | T&, List item |
data | void*, Optional function-specific data |
|
inline |
Removes all items from the queue
|
inline |
Calls callbackFunction() for every list until false is returned
Current implementation does the job but isn't too efficient due to std::queue class limitations.
callbackFunction | Callback function that is executed for list items |
data | Function-specific data |
|
inline |
Returns true if the queue is empty
|
inline |
Pops a data item from the queue
If queue is empty then waits until timeoutMS milliseconds timeout occurs. Returns false if timeout occurs.
item | T&, A queue item (output) |
timeout | std::chrono::milliseconds, Operation timeout in milliseconds |
References sptk::Semaphore::sleep_for().
|
inline |
Pushes a data item to the queue
Automatically posts internal semaphore to indicate queue item availability.
data | const T&, A data item |
References sptk::Semaphore::post().
|
inline |
Pushes a data item to the queue
Item is moved inside the queue. Automatically posts internal semaphore to indicate queue item availability.
data | T&&, A data item |
References sptk::Semaphore::post().
|
inline |
Returns number of items in the queue
|
inlinevirtual |
Wakes up queue semaphore to interrupt waiting
Any waiting pop() operation immediately returns false.
References sptk::Semaphore::post().