Nebula
Loading...
Searching...
No Matches
Posix::PosixThreadBarrier Class Reference

#include <posixthreadbarrier.h>

Detailed Description

Block until all thread have arrived at the barrier.

(C) 2013-2018 Individual contributors, see AUTHORS file

Public Member Functions

 PosixThreadBarrier ()
 constructor
 
 ~PosixThreadBarrier ()
 destructor
 
void Setup (SizeT numThreads)
 setup the object with the number of threads
 
bool IsValid () const
 return true if the object has been setup
 
bool Arrive ()
 enter thread barrier, return false if not all threads have arrived yet
 
void Wait ()
 call after Arrive() returns false to wait for other threads
 
void SignalContinue ()
 call after Arrive() returns true to resume all threads
 
 PosixThreadBarrier ()
 constructor
 
 ~PosixThreadBarrier ()
 destructor
 
void Setup (SizeT numThreads)
 setup the object with the number of threads
 
bool IsValid () const
 return true if the object has been setup
 
bool Arrive ()
 enter thread barrier, return false if not all threads have arrived yet
 
void Wait ()
 call after Arrive() returns false to wait for other threads
 
void SignalContinue ()
 call after Arrive() returns true to resume all threads
 

Private Attributes

Threading::CriticalSection critSect
 
long numThreads
 
volatile long outstandingThreads
 
sem_t * semaphore
 
bool isValid
 
pthread_cond_t cond
 
pthread_mutex_t mutex
 
timespec ts
 

Constructor & Destructor Documentation

◆ PosixThreadBarrier() [1/2]

Posix::PosixThreadBarrier::PosixThreadBarrier ( )
inline

constructor

◆ ~PosixThreadBarrier() [1/2]

Posix::PosixThreadBarrier::~PosixThreadBarrier ( )
inline

destructor

◆ PosixThreadBarrier() [2/2]

Posix::PosixThreadBarrier::PosixThreadBarrier ( )

constructor

◆ ~PosixThreadBarrier() [2/2]

Posix::PosixThreadBarrier::~PosixThreadBarrier ( )

destructor

Member Function Documentation

◆ Arrive() [1/2]

bool Posix::PosixThreadBarrier::Arrive ( )
inline

enter thread barrier, return false if not all threads have arrived yet

Notify arrival at thread-sync point, return false if not all threads have arrived yet, and true if all threads have arrived.

If the method returns false, you should immediately call Wait(), if the method returns true, the caller has a chance to perform some actions which should happen before threads continue, and then call the SignalContinue() method.

◆ Arrive() [2/2]

bool Posix::PosixThreadBarrier::Arrive ( )

enter thread barrier, return false if not all threads have arrived yet

◆ IsValid() [1/2]

bool Posix::PosixThreadBarrier::IsValid ( ) const
inline

return true if the object has been setup

◆ IsValid() [2/2]

bool Posix::PosixThreadBarrier::IsValid ( ) const

return true if the object has been setup

◆ Setup() [1/2]

void Posix::PosixThreadBarrier::Setup ( SizeT numThreads)
inline

setup the object with the number of threads

◆ Setup() [2/2]

void Posix::PosixThreadBarrier::Setup ( SizeT numThreads)

setup the object with the number of threads

◆ SignalContinue() [1/2]

void Posix::PosixThreadBarrier::SignalContinue ( )
inline

call after Arrive() returns true to resume all threads

This method should be called after Arrive() returns true.

This means that all threads have arrived at the sync point and execution of all threads may resume.

◆ SignalContinue() [2/2]

void Posix::PosixThreadBarrier::SignalContinue ( )

call after Arrive() returns true to resume all threads

◆ Wait() [1/2]

void Posix::PosixThreadBarrier::Wait ( )
inline

call after Arrive() returns false to wait for other threads

This method should be called when Arrive() returns false.

It will put the thread to sleep because not all threads have arrived yet. When the method returns, all threads have arrived at the sync point.

NOTE: sometimes both the render and the main thread arrive here with the outstandingThreads member set to 1 (from two) causing both thread to be waiting idefinitely.

◆ Wait() [2/2]

void Posix::PosixThreadBarrier::Wait ( )

call after Arrive() returns false to wait for other threads

Member Data Documentation

◆ cond

pthread_cond_t Posix::PosixThreadBarrier::cond
private

◆ critSect

Threading::CriticalSection Posix::PosixThreadBarrier::critSect
private

◆ isValid

bool Posix::PosixThreadBarrier::isValid
private

◆ mutex

pthread_mutex_t Posix::PosixThreadBarrier::mutex
private

◆ numThreads

long Posix::PosixThreadBarrier::numThreads
private

◆ outstandingThreads

volatile long Posix::PosixThreadBarrier::outstandingThreads
private

◆ semaphore

sem_t* Posix::PosixThreadBarrier::semaphore
private

◆ ts

timespec Posix::PosixThreadBarrier::ts
private

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