UCommon
Public Member Functions | Static Public Member Functions
ucommon::barrier Class Reference

A portable implimentation of "barrier" thread sychronization. More...

#include <thread.h>

Inheritance diagram for ucommon::barrier:
Inheritance graph
[legend]
Collaboration diagram for ucommon::barrier:
Collaboration graph
[legend]

Public Member Functions

 barrier (unsigned count)
 Construct a barrier with an initial size.
void dec (void)
 Reduce the number of threads required.
void inc (void)
 Dynamically increment the number of threads required.
unsigned operator++ (void)
 Alternative prefix form of the same increment operation.
unsigned operator-- (void)
void set (unsigned count)
 Dynamically alter the number of threads required.
void wait (void)
 Wait at the barrier until the count of threads waiting is reached.
bool wait (timeout_t timeout)
 Wait at the barrier until either the count of threads waiting is reached or a timeout has occurred.
 ~barrier ()
 Destroy barrier and release pending threads.

Static Public Member Functions

static void set (barrier &sync, unsigned count)
 Convenience function to set a barrier count.
static void wait (barrier &sync)
 Convenience function to wait at a barrier.
static bool wait (barrier &sync, timeout_t timeout)
 Convenience function to wait at a barrier with a timeout.

Detailed Description

A portable implimentation of "barrier" thread sychronization.

A barrier waits until a specified number of threads have all reached the barrier, and then releases all the threads together. This implimentation works regardless of whether the thread library supports barriers since it is built from conditional. It also differs in that the number of threads required can be changed dynamically at runtime, unlike pthread barriers which, when supported, have a fixed limit defined at creation time. Since we use conditionals, another feature we can add is optional support for a wait with timeout.

Author:
David Sugar <dyfet@gnutelephony.org>

Definition at line 933 of file thread.h.


Constructor & Destructor Documentation

ucommon::barrier::barrier ( unsigned  count)

Construct a barrier with an initial size.

Parameters:
countof threads required.

Member Function Documentation

unsigned ucommon::barrier::operator++ ( void  )

Alternative prefix form of the same increment operation.

Returns:
the current amount of threads.
void ucommon::barrier::set ( unsigned  count)

Dynamically alter the number of threads required.

If the size is set below the currently waiting threads, then the barrier releases.

Parameters:
countof threads required.
static void ucommon::barrier::set ( barrier sync,
unsigned  count 
) [inline, static]

Convenience function to set a barrier count.

Parameters:
syncobject to set.
countof threads to set.

Definition at line 1011 of file thread.h.

bool ucommon::barrier::wait ( timeout_t  timeout)

Wait at the barrier until either the count of threads waiting is reached or a timeout has occurred.

Parameters:
timeoutto wait in milliseconds.
Returns:
true if barrier reached, false if timer expired.

Reimplemented from ucommon::Conditional.

static void ucommon::barrier::wait ( barrier sync) [inline, static]

Convenience function to wait at a barrier.

Parameters:
syncobject to wait at.

Definition at line 993 of file thread.h.

Here is the call graph for this function:

static bool ucommon::barrier::wait ( barrier sync,
timeout_t  timeout 
) [inline, static]

Convenience function to wait at a barrier with a timeout.

Parameters:
syncobject to wait at.
timeoutto wait in milliseconds.
Returns:
false if timer expired.

Definition at line 1002 of file thread.h.

Here is the call graph for this function:


The documentation for this class was generated from the following file: