Botan 2.19.5 Crypto and TLS for C&

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 namespace Botan {
11
12 void Barrier::wait(size_t delta)
13 {
14 std::lock_guard<std::mutex> lock(m_mutex);
15 m_value += delta;
16 }
17
18 void Barrier::sync()
19 {
20 std::unique_lock<std::mutex> lock(m_mutex);
21
22 if(m_value > 1)
23 {
24 --m_value;
25 const size_t current_syncs = m_syncs;
26 m_cond.wait(lock, [this, &current_syncs] { return m_syncs != current_syncs; });
27 }
28 else
29 {
30 m_value = 0;
31 ++m_syncs;
32 m_cond.notify_all();
33 }
34 }
35
36}
Botan::Barrier::wait
void wait(size_t delta)
Definition: barrier.cpp:12
Botan::Barrier::sync
void sync()
Definition: barrier.cpp:18
Botan
Definition: alg_id.cpp:13