Botan  2.12.1
Crypto and TLS for C++11
Public Member Functions | List of all members
Botan::Barrier Class Referencefinal

#include <barrier.h>

Public Member Functions

 Barrier (int value=0)
 
void sync ()
 
void wait (size_t delta)
 

Detailed Description

Barrier implements a barrier synchronization primitive. wait() will indicate how many threads to synchronize; each thread needing synchronization should call sync(). When sync() returns, the barrier is reset to zero, and the m_syncs counter is incremented. m_syncs is a counter to ensure that wait() can be called after a sync() even if the previously sleeping threads have not awoken.)

Definition at line 24 of file barrier.h.

Constructor & Destructor Documentation

◆ Barrier()

Botan::Barrier::Barrier ( int  value = 0)
inlineexplicit

Definition at line 27 of file barrier.h.

27 : m_value(value), m_syncs(0) {}

Member Function Documentation

◆ sync()

void Botan::Barrier::sync ( )

Definition at line 18 of file barrier.cpp.

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  }

◆ wait()

void Botan::Barrier::wait ( size_t  delta)

Definition at line 12 of file barrier.cpp.

13  {
14  std::lock_guard<std::mutex> lock(m_mutex);
15  m_value += delta;
16  }

The documentation for this class was generated from the following files: