#include <wefts_queue.h>
Collaboration diagram for Wefts::Queue< T >:
Public Member Functions | |
Queue (unsigned int maxLen=0) | |
Creates a queue. | |
bool | push (T elem, const bool wait=false) |
Pushes data in the queue. | |
bool | pop (T &elem, const bool wait=true) |
Pops data from the queue. | |
Protected Attributes | |
FastCondition | m_cond |
unsigned long | m_maxLen |
std::list< T > | m_list |
Private Member Functions | |
void | p_waitForFree () |
void | p_waitForFull () |
A Queue, in Wefts++ context, is an object where one or more thread are posting data, and one or more thread are waiting for data to become available to process it.
Queue is a fast and clean way to pass arbitrary data in a 1:1 scheme from a producer to a consumer (or from a master to a worker) even if there are more producer/masters and consumer/workers running at the same time.
Queues have not any scheduling poicies; the first thread that is able to wake up will take the first element available.
By default, queues have infinite lenght. You can set a maximum lenght and in that case, a thread willing to post a new data will be blocked until the queue becomes free again, or will immediately return an error (depending on user preferences).
|
Creates a queue. If the parameter is zero, the queue will have infinite lenght; if it is not zero, push() method will block or return immediately false when the maximum lenght is reached.
|
|
|
|
|
|
Pops data from the queue. Queues are FIFO, that is First in, First out. The first element you push will be served first to the waiters. Note that the default behavior of pop() is to wait until there is some data to be placed in the parameter, but you can also set wait parameter to false to have an immediate return in case of the queue being empty in that moment. A blocking pop() is a cancelation point; be sure you have a proper cleanup scheme set up before to call a blocking pop.
|
|
Pushes data in the queue. Queues are FIFO, that is First in, First out. The first element you push will be served first to the waiters.
|
|
|
|
|
|
|