38 #include "blocxx/BLOCXX_config.h"
45 #if defined(BLOCXX_USE_PTHREAD) && defined(BLOCXX_HAVE_PTHREAD_BARRIER) && !defined(BLOCXX_VALGRIND_SUPPORT)
56 namespace BLOCXX_NAMESPACE
61 #if defined(BLOCXX_USE_PTHREAD) && defined(BLOCXX_HAVE_PTHREAD_BARRIER) && !defined(BLOCXX_VALGRIND_SUPPORT) // valgrind doesn't support pthread_barrier_*()
68 memset(&barrier, 0,
sizeof(barrier));
69 int res = pthread_barrier_init(&barrier, NULL, threshold);
77 int res = pthread_barrier_destroy(&barrier);
86 int res = pthread_barrier_wait(&barrier);
87 if (res != 0 && res != PTHREAD_BARRIER_SERIAL_THREAD)
89 BLOCXX_THROW(ThreadBarrierException, Format(
"pthread_barrier_wait failed: %1(%2)", res, strerror(res)).c_str());
93 pthread_barrier_t barrier;
ThreadBarrier & operator=(const ThreadBarrier &x)
void wait(NonRecursiveMutexLock &lock)
Atomically unlock a given mutex and wait for the this Condition object to get signalled.
void wait()
Synchronize participating threads at the barrier.
#define BLOCXX_ASSERT(CON)
BLOCXX_ASSERT works similar to the assert() macro, but instead of calling abort(), it throws an AssertionException.
UInt32 m_waitingCount
The number of waiting threads.
void notifyAll()
Signal all threads that are currently waiting on the Condition object.
#define BLOCXX_DEFINE_EXCEPTION_WITH_ID(NAME)
Define a new exception class named <NAME>Exception that derives from Exception.
Condition m_cond
Condition for threads to wait on.
UInt32 m_threshold
The number of threads to synchronize.
IntrusiveReference< ThreadBarrierImpl > m_impl
int m_curSubBarrier
Either 0 or 1, depending on whether we are the first generation of waiters or the next generation of ...
ThreadBarrierImpl(UInt32 threshold)
ThreadBarrier(UInt32 threshold)
Constructor.
This code is inspired by ACE, by Douglas C.
#define BLOCXX_THROW(exType, msg)
Throw an exception using FILE and LINE.
Note that descriptions of what exceptions may be thrown assumes that object is used correctly...
Note that descriptions of what exceptions may be thrown assumes that object is used correctly...
NonRecursiveMutex m_mutex
The ThreadBarrier class is used to synchronize threads.
The Condition class represents a synchronization device that allows threads to suspend execution and ...