Botan 3.4.0
Crypto and TLS for C&
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 26 of file barrier.h.

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

Member Function Documentation

◆ sync()

void Botan::Barrier::sync ( )

Definition at line 17 of file barrier.cpp.

17 {
18 std::unique_lock<std::mutex> lock(m_mutex);
19
20 if(m_value > 1) {
21 --m_value;
22 const size_t current_syncs = m_syncs;
23 m_cond.wait(lock, [this, &current_syncs] { return m_syncs != current_syncs; });
24 } else {
25 m_value = 0;
26 ++m_syncs;
27 m_cond.notify_all();
28 }
29}
secure_vector< T > lock(const std::vector< T > &in)
Definition secmem.h:70

References Botan::lock().

◆ wait()

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

Definition at line 12 of file barrier.cpp.

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

References Botan::lock().


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