Botan  2.6.0
Crypto and TLS for C++11
barrier.h
Go to the documentation of this file.
1 /*
2 * Barrier
3 * (C) 2016 Joel Low
4 *
5 * Botan is released under the Simplified BSD License (see license.txt)
6 */
7 
8 #ifndef BOTAN_UTIL_BARRIER_H_
9 #define BOTAN_UTIL_BARRIER_H_
10 
11 #include <botan/mutex.h>
12 #include <condition_variable>
13 
14 namespace Botan {
15 
16 /**
17 Barrier implements a barrier synchronization primitive. wait() will
18 indicate how many threads to synchronize; each thread needing
19 synchronization should call sync(). When sync() returns, the barrier
20 is reset to zero, and the m_syncs counter is incremented. m_syncs is a
21 counter to ensure that wait() can be called after a sync() even if the
22 previously sleeping threads have not awoken.)
23 */
24 class Barrier final
25  {
26  public:
27  explicit Barrier(int value = 0) : m_value(value), m_syncs(0) {}
28 
29  void wait(size_t delta);
30 
31  void sync();
32 
33  private:
34  int m_value;
35  size_t m_syncs;
36  mutex_type m_mutex;
37  std::condition_variable m_cond;
38  };
39 
40 }
41 
42 #endif
void wait(size_t delta)
Definition: barrier.cpp:12
Definition: alg_id.cpp:13
void sync()
Definition: barrier.cpp:18
Barrier(int value=0)
Definition: barrier.h:27