CppBenchmark  1.0.4.0
C++ Benchmark Library
barrier.h
Go to the documentation of this file.
1 
9 #ifndef CPPBENCHMARK_BARRIER_H
10 #define CPPBENCHMARK_BARRIER_H
11 
12 #include <condition_variable>
13 #include <mutex>
14 
15 namespace CppBenchmark {
16 
18 
26 class Barrier
27 {
28 public:
30 
33  explicit Barrier(int threads) noexcept;
34  Barrier(const Barrier&) = delete;
35  Barrier(Barrier&&) = delete;
36  ~Barrier() = default;
37 
38  Barrier& operator=(const Barrier&) = delete;
39  Barrier& operator=(Barrier&&) = delete;
40 
42 
47  bool Wait() noexcept;
48 
49 private:
50  std::mutex _mutex;
51  std::condition_variable _cond;
52  int _counter;
53  int _generation;
54  int _threads;
55 };
56 
57 } // namespace CppBenchmark
58 
59 #endif // CPPBENCHMARK_BARRIER_H
Barrier synchronization primitive.
Definition: barrier.h:27
Barrier & operator=(const Barrier &)=delete
Barrier(Barrier &&)=delete
Barrier & operator=(Barrier &&)=delete
Barrier(int threads) noexcept
Default class constructor.
Definition: barrier.cpp:15
Barrier(const Barrier &)=delete
bool Wait() noexcept
Wait at the barrier until all other threads reach this barrier.
Definition: barrier.cpp:20
C++ Benchmark project definitions.
Definition: barrier.h:15