Botan 2.19.3
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
10namespace Botan {
11
12void Barrier::wait(size_t delta)
13 {
14 std::lock_guard<std::mutex> lock(m_mutex);
15 m_value += delta;
16 }
17
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}
void wait(size_t delta)
Definition barrier.cpp:12