CppCommon 1.0.5.0
C++ Common Library
Loading...
Searching...
No Matches
spin_barrier.h
Go to the documentation of this file.
1
9#ifndef CPPCOMMON_THREADS_SPIN_BARRIER_H
10#define CPPCOMMON_THREADS_SPIN_BARRIER_H
11
12#include <atomic>
13#include <cassert>
14
15namespace CppCommon {
16
18
31{
32public:
34
37 explicit SpinBarrier(int threads) noexcept;
38 SpinBarrier(const SpinBarrier&) = delete;
40 ~SpinBarrier() = default;
41
44
46 int threads() const noexcept { return _threads; }
47
49
54 bool Wait() noexcept;
55
56private:
57 std::atomic<int> _counter;
58 std::atomic<int> _generation;
59 int _threads;
60};
61
64} // namespace CppCommon
65
66#include "spin_barrier.inl"
67
68#endif // CPPCOMMON_THREADS_SPIN_BARRIER_H
Spin barrier synchronization primitive.
SpinBarrier & operator=(SpinBarrier &&)=delete
int threads() const noexcept
Get the count of threads to wait at the barrier.
SpinBarrier(const SpinBarrier &)=delete
bool Wait() noexcept
Wait at the barrier until all other threads reach this barrier.
SpinBarrier(SpinBarrier &&)=delete
SpinBarrier & operator=(const SpinBarrier &)=delete
C++ Common project definitions.