Botan 2.1.0 Crypto and TLS for C++11

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

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