Wefts::Barrier Class Reference
[Advanced Syncronization constructs]

#include <wefts_barrier.h>

Collaboration diagram for Wefts::Barrier:

Collaboration graph
[legend]
List of all members.

Detailed Description

Programmable fence object.

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


Constructor & Destructor Documentation

Wefts::Barrier::Barrier unsigned int  treshold = 0,
bool  open = false
 

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.

Parameters:
treshold 0 or the count of threads that are blocked before release.
open true to disable the barrier, false to have it operational


Member Function Documentation

bool Wefts::Barrier::blocking  )  [inline]
 

Return true if the barrier is blocking the threads, or false if the barrier is currently open.

void Wefts::Barrier::close  ) 
 

Closes the barrier.

All the threads willing to enter the barrier will now be blocked.

void Wefts::Barrier::open  ) 
 

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

void Wefts::Barrier::release  ) 
 

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

void Wefts::Barrier::treshold unsigned int  th  ) 
 

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.

unsigned int Wefts::Barrier::treshold  )  [inline]
 

Returns the current treshold count.

void Wefts::Barrier::wait  ) 
 

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.

unsigned int Wefts::Barrier::waiting  )  [inline]
 

Returns the count of subscribing threads.


Member Data Documentation

FastCondition Wefts::Barrier::m_cond [private]
 

volatile bool Wefts::Barrier::m_open [private]
 

volatile bool Wefts::Barrier::m_release [private]
 

volatile unsigned int Wefts::Barrier::m_subscribed [private]
 

volatile unsigned int Wefts::Barrier::m_treshold [private]
 


The documentation for this class was generated from the following files:
Generated on Tue Oct 5 14:57:01 2004 for Wefts by doxygen 1.3.7