CppCommon 1.0.5.0
C++ Common Library
Loading...
Searching...
No Matches
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
16namespace CppCommon {
17
19
28{
29public:
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
53private:
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
int threads() const noexcept
Get the count of threads to wait at the barrier.
Definition barrier.cpp:139
Barrier & operator=(Barrier &&barrier)=delete
Barrier(Barrier &&barrier)=delete
Barrier & operator=(const 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.