#include <wefts_barrier.h>
Collaboration diagram for Wefts::Barrier:
A Barrier is a synchronization object that blocks calling threads until a certain amount of them has been blocked, or until another thread releases them. This construct is useful in process made by steps where a given amount of threads has to complete their processing before continuing to the next phase. Also, the construct is useful when there is a "blocking condition" that must be solved by another thread before processing can continue. Then the controlling thread can rise a barrier, and lower it temporarily or definitively when the blocking condition is solved.
Public Member Functions | |
Barrier (unsigned int treshold=0, bool open=false) | |
Creates a barrier with a given treshold. | |
void | wait () |
Waits for treshold to have reach a certain count. | |
unsigned int | waiting () |
Returns the count of subscribing threads. | |
unsigned int | treshold () |
Returns the current treshold count. | |
bool | blocking () |
Return true if the barrier is blocking the threads, or false if the barrier is currently open. | |
void | treshold (unsigned int th) |
Changes the current treshold count. | |
void | release () |
Release all currently blocked threads. | |
void | open () |
Opens the barrier. | |
void | close () |
Closes the barrier. | |
Private Attributes | |
volatile unsigned int | m_treshold |
volatile unsigned int | m_subscribed |
FastCondition | m_cond |
volatile bool | m_release |
volatile bool | m_open |
|
Creates a barrier with a given treshold. The barrier is initially created with gate closed (blocking threads), and with a given treshold. If treshold is == 0, then all the threads must be released with the release() method, or opening the barrier.
|
|
Return true if the barrier is blocking the threads, or false if the barrier is currently open.
|
|
Closes the barrier. All the threads willing to enter the barrier will now be blocked. |
|
Opens the barrier. Opens the barrier, releasing all the currently held threads AND allowing all the threads to pass the barrier without blocking from now on |
|
Release all currently blocked threads. If the barrier is currently open, this call is ignored. If the barrier is currently closed, only the threads that are waiting in the moment of the call are released; the status of the barrier is not changed |
|
Changes the current treshold count. If the new treshold value is lower than the currently held threads, then the threads are immediately released, unless the value passed is 0. |
|
Returns the current treshold count.
|
|
Waits for treshold to have reach a certain count. When a number of threads equal to m_treshold have called this method, all the waiting threads are released. |
|
Returns the count of subscribing threads.
|
|
|
|
|
|
|
|
|
|
|