Botan  2.4.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 #if defined(BOTAN_TARGET_OS_HAS_THREADS)
11 
12 namespace Botan {
13 
14 void Barrier::wait(size_t 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 
24  if(m_value > 1)
25  {
26  --m_value;
27  const size_t current_syncs = m_syncs;
28  m_cond.wait(lock, [this, &current_syncs] { return m_syncs != current_syncs; });
29  }
30  else
31  {
32  m_value = 0;
33  ++m_syncs;
34  m_cond.notify_all();
35  }
36  }
37 
38 }
39 
40 #endif
Definition: alg_id.cpp:13