CppCommon  1.0.4.1
C++ Common Library
barrier.h
Go to the documentation of this file.
1 
9 #ifndef CPPCOMMON_THREADS_BARRIER_H
10 #define CPPCOMMON_THREADS_BARRIER_H
11 
12 #include "errors/exceptions.h"
13 
14 #include <memory>
15 
16 namespace CppCommon {
17 
19 
27 class Barrier
28 {
29 public:
31 
34  explicit Barrier(int threads);
35  Barrier(const Barrier&) = delete;
36  Barrier(Barrier&& barrier) = delete;
37  ~Barrier();
38 
39  Barrier& operator=(const Barrier&) = delete;
40  Barrier& operator=(Barrier&& barrier) = delete;
41 
43  int threads() const noexcept;
44 
46 
51  bool Wait();
52 
53 private:
54  class Impl;
55 
56  Impl& impl() noexcept { return reinterpret_cast<Impl&>(_storage); }
57  const Impl& impl() const noexcept { return reinterpret_cast<Impl const&>(_storage); }
58 
59  static const size_t StorageSize = 128;
60  static const size_t StorageAlign = 8;
61  alignas(StorageAlign) std::byte _storage[StorageSize];
62 };
63 
66 } // namespace CppCommon
67 
68 #endif // CPPCOMMON_THREADS_BARRIER_H
Barrier synchronization primitive.
Definition: barrier.h:28
Barrier & operator=(Barrier &&barrier)=delete
int threads() const noexcept
Get the count of threads to wait at the barrier.
Definition: barrier.cpp:139
Barrier(int threads)
Default class constructor.
Definition: barrier.cpp:122
Barrier & operator=(const Barrier &)=delete
Barrier(Barrier &&barrier)=delete
bool Wait()
Wait at the barrier until all other threads reach this barrier.
Definition: barrier.cpp:141
Barrier(const Barrier &)=delete
Exceptions definition.
C++ Common project definitions.
Definition: token_bucket.h:15