#include <wefts_queue.h>
Collaboration diagram for Wefts::Queue< T >:
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 length. You can set a maximum length 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).
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. | |
bool | empty () const |
Check wether a queue is empty or not. | |
int | size () const |
Protected Attributes | |
FastCondition | m_cond |
unsigned long | m_maxLen |
int | m_size |
std::list< T > | m_list |
Private Member Functions | |
void | p_waitForFree () |
void | p_waitForFull () |
|
Creates a queue. If the parameter is zero, the queue will have infinite length; if it is not zero, push() method will block or return immediately false when the maximum length is reached.
|
|
Check wether a queue is empty or not. Notice that this operation has no sense if the queue is currently used in various threads. This is meant to be used by applications that are able to demonstrate that no thread is currently helding the queue, or by subclasses.
|
|
|
|
|
|
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 cancellation 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.
|
|
|
|
|
|
|
|
|
|
|