15 #if (defined(unix) || defined(__unix) || defined(__unix__)) && !defined(__APPLE__)
18 #elif defined(__APPLE__) || defined(__MINGW32__) || defined(__MINGW64__)
19 #include <condition_variable>
21 #elif defined(_WIN32) || defined(_WIN64)
34 assert((
threads > 0) &&
"Barrier threads counter must be greater than zero!");
36 #if (defined(unix) || defined(__unix) || defined(__unix__)) && !defined(__APPLE__)
37 int result = pthread_barrier_init(&_barrier,
nullptr,
threads);
39 throwex SystemException(
"Failed to initialize a synchronization barrier!", result);
40 #elif defined(__APPLE__) || defined(__MINGW32__) || defined(__MINGW64__)
43 #elif defined(_WIN32) || defined(_WIN64)
44 if (!InitializeSynchronizationBarrier(&_barrier,
threads, -1))
45 throwex SystemException(
"Failed to initialize a synchronization barrier!");
51 #if (defined(unix) || defined(__unix) || defined(__unix__)) && !defined(__APPLE__)
52 int result = pthread_barrier_destroy(&_barrier);
54 fatality(SystemException(
"Failed to destroy a synchronization barrier!", result));
55 #elif defined(__APPLE__) || defined(__MINGW32__) || defined(__MINGW64__)
57 #elif defined(_WIN32) || defined(_WIN64)
58 DeleteSynchronizationBarrier(&_barrier);
69 #if (defined(unix) || defined(__unix) || defined(__unix__)) && !defined(__APPLE__)
70 int result = pthread_barrier_wait(&_barrier);
71 if ((result != PTHREAD_BARRIER_SERIAL_THREAD) && (result != 0))
72 throwex SystemException(
"Failed to wait at a synchronization barrier!", result);
73 return (result == PTHREAD_BARRIER_SERIAL_THREAD);
74 #elif defined(__APPLE__) || defined(__MINGW32__) || defined(__MINGW64__)
75 std::unique_lock<std::mutex> lock(_mutex);
78 int generation = _generation;
97 _cond.wait(lock, [&,
this]() {
return generation != _generation; });
101 #elif defined(_WIN32) || defined(_WIN64)
102 return (EnterSynchronizationBarrier(&_barrier, 0) == TRUE);
108 #if (defined(unix) || defined(__unix) || defined(__unix__)) && !defined(__APPLE__)
109 pthread_barrier_t _barrier;
110 #elif defined(__APPLE__) || defined(__MINGW32__) || defined(__MINGW64__)
112 std::condition_variable _cond;
115 #elif defined(_WIN32) || defined(_WIN64)
116 SYNCHRONIZATION_BARRIER _barrier;
126 static_assert((StorageSize >=
sizeof(Impl)),
"Barrier::StorageSize must be increased!");
127 static_assert(((StorageAlign %
alignof(Impl)) == 0),
"Barrier::StorageAlign must be adjusted!");
136 reinterpret_cast<Impl*
>(&_storage)->~Impl();
Barrier synchronization primitive definition.
int threads() const noexcept
Get the count of threads to wait at the barrier.
Barrier(int threads)
Default class constructor.
bool Wait()
Wait at the barrier until all other threads reach this barrier.
Aligned storage validator.
#define throwex
Throw extended exception macro.
Fatal abort execution definition.
#define fatality(...)
Fatal abort execution extended macro.
C++ Common project definitions.
Aligned storage validator definition.