11 #ifndef TLX_THREAD_BARRIER_SPIN_HEADER
12 #define TLX_THREAD_BARRIER_SPIN_HEADER
29 class ThreadBarrierSpin
46 template <
typename Lambda = NoOperation<
void> >
47 void wait(Lambda lambda = Lambda()) {
49 size_t this_step =
step_.load(std::memory_order_acquire);
53 waiting_.store(0, std::memory_order_release);
57 step_.fetch_add(1, std::memory_order_acq_rel);
61 while (
step_.load(std::memory_order_acquire) == this_step) {
75 template <
typename Lambda = NoOperation<
void> >
78 size_t this_step =
step_.load(std::memory_order_acquire);
82 waiting_.store(0, std::memory_order_release);
86 step_.fetch_add(1, std::memory_order_acq_rel);
90 while (
step_.load(std::memory_order_acquire) == this_step) {
91 std::this_thread::yield();
98 return step_.load(std::memory_order_acquire);
109 std::atomic<size_t>
step_ { 0 };
114 #endif // !TLX_THREAD_BARRIER_SPIN_HEADER