Botan  2.4.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 
13 #if defined(BOTAN_TARGET_OS_HAS_THREADS)
14  #include <condition_variable>
15 #endif
16 
17 namespace Botan {
18 
19 #if defined(BOTAN_TARGET_OS_HAS_THREADS)
20 
21 /**
22 Barrier implements a barrier synchronization primitive. wait() will
23 indicate how many threads to synchronize; each thread needing
24 synchronization should call sync(). When sync() returns, the barrier
25 is reset to zero, and the m_syncs counter is incremented. m_syncs is a
26 counter to ensure that wait() can be called after a sync() even if the
27 previously sleeping threads have not awoken.)
28 */
29 class Barrier final
30  {
31  public:
32  explicit Barrier(int value = 0) : m_value(value), m_syncs(0) {}
33 
34  void wait(size_t delta);
35 
36  void sync();
37 
38  private:
39  int m_value;
40  size_t m_syncs;
41  mutex_type m_mutex;
42  std::condition_variable m_cond;
43  };
44 
45 #endif
46 
47 }
48 
49 #endif
Definition: alg_id.cpp:13