#include <wefts_stack.h>
Collaboration diagram for Wefts::Stack< T >:
A Stack, in Wefts++ context, is an Last-in first-out synchronization object, where one or more thread are posting data, and one or more thread are waiting for data to become available to process it. The last data posted will be retreived by the first thread coming in search for data.
Stack 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.
Stacks have not any scheduling poicies; the first thread that is able to wake up will take the first element available.
By default, stacks have infinite size. You can set a maximum length and in that case, a thread willing to post a new data will be blocked until the stack becomes free again, or will immediately return an error (depending on user preferences).
Public Member Functions | |
Stack (unsigned int maxLen=0) | |
Creates a stack. | |
bool | push (T elem, const bool wait=false) |
Pushes data in the stack. | |
bool | pop (T &elem, const bool wait=true) |
Pops data from the stack. | |
Protected Attributes | |
FastCondition | m_cond |
unsigned long | m_maxLen |
std::list< T > | m_list |
Private Member Functions | |
void | p_waitForFree () |
void | p_waitForFull () |
|
Creates a stack. If the parameter is zero, the stack will have infinite length; if it is not zero, push() method will block or return immediately false when the maximum length is reached.
|
|
|
|
|
|
Pops data from the stack. Stacks are LIFO, that is Last in, First out. The last 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 stack 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 stack. Stacks are LIFO, that is Last in, First out. The last element you push will be served first to the waiters.
|
|
|
|
|
|
|