Botan 2.1.0 Crypto and TLS for C++11

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

barrier.cpp
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 #include <botan/internal/barrier.h>
9
10 #if defined(BOTAN_TARGET_OS_HAS_THREADS)
11
12 namespace Botan {
13
14 void Barrier::wait(unsigned delta)
15 {
16 lock_guard_type<mutex_type> lock(m_mutex);
17 m_value += delta;
18 }
19
20 void Barrier::sync()
21 {
22 std::unique_lock<mutex_type> lock(m_mutex);
23 --m_value;
24 if(m_value > 0)
25 {
26 unsigned current_syncs = m_syncs;
27 m_cond.wait(lock, [this, &current_syncs] { return m_syncs != current_syncs; });
28 }
29 else
30 {
31 m_value = 0;
32 ++m_syncs;
33 m_cond.notify_all();
34 }
35 }
36
37 }
38
39 #endif
Botan
Definition: alg_id.cpp:13