Botan  2.8.0
Crypto and TLS for C++11
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  lock_guard_type<mutex_type> lock(m_mutex);
15  m_value += delta;
16  }
17 
19  {
20  std::unique_lock<mutex_type> 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
Definition: alg_id.cpp:13
void sync()
Definition: barrier.cpp:18