OpenLibrary
|
Thread safe queue. More...
#include <ts_queue.hpp>
Public Member Functions | |
TS_Queue (size_t max_size) | |
virtual | ~TS_Queue () |
Destructor. More... | |
void | push (const T &item) |
Write data to TS_Queue. More... | |
void | push_front (const T &item) |
void | push (T &&item) |
Write data to TS_Queue. More... | |
void | push_back (T &&item) |
Optional< T > | pop () |
Get data. More... | |
Optional< T > | pop_front () |
Optional< T > | pop_for (const std::chrono::milliseconds &timeout) |
Get data. More... | |
size_t | size () const |
Take objects count. | |
bool | empty () const |
Check if TS_Queue is empty. | |
void | stop () |
Release all threads waiting in TS_Queue::pop(). More... | |
void | wait_for_data () |
Wait until data is available. | |
Thread safe queue.
TS_Queue is a thread safe queue based on std::deque. It differs however from default containers: TS_Queue is meant to be used as a pipe. There is one side where one or many threads can safely write and there is other side from where one or many threads can read.
Use TS_Queue::push_back() for writing objects, and TS_Queue::pop_front() for reading objects. TS_Queue has it maximum capacity defined on construction. When TS_Queue is full any attempt of pushing data will cause in wait operation.
Thread which destroys TS_Queue will be suspended until TS_Queue becomes empty. No pushes are allowed at that time.
based on: http://en.wikipedia.org/wiki/Producer-consumer_problem
|
inline |
Constructor.
|
inlinevirtual |
|
inline |
Get data.
When there is no data in queue, current thread will wait until data appear. Returned type is Optional which can be empty in one situation: when thread was waiting for data and TS_Queue::stop() or TS_Queue's destructor were called.
|
inline |
Get data.
When there is no data in queue, current thread will wait until data appear.
|
inline |
|
inline |
Write data to TS_Queue.
Behaves as TS_Queue::push(const T &), but uses move semantics
|
inline |
Release all threads waiting in TS_Queue::pop().
No writes allowed since this moment.