Botan 3.3.0
Crypto and TLS for C&
Public Member Functions | List of all members
Botan::Semaphore Class Referencefinal

#include <semaphore.h>

Public Member Functions

void acquire ()
 
void release (size_t n=1)
 
 Semaphore (int value=0)
 

Detailed Description

Definition at line 16 of file semaphore.h.

Constructor & Destructor Documentation

◆ Semaphore()

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

Definition at line 18 of file semaphore.h.

18: m_value(value), m_wakeups(0) {}

Member Function Documentation

◆ acquire()

void Botan::Semaphore::acquire ( )

Definition at line 25 of file semaphore.cpp.

25 {
26 std::unique_lock<std::mutex> lock(m_mutex);
27 if(m_value-- <= 0) {
28 m_cond.wait(lock, [this] { return m_wakeups > 0; });
29 --m_wakeups;
30 }
31}
secure_vector< T > lock(const std::vector< T > &in)
Definition secmem.h:70

References Botan::lock().

◆ release()

void Botan::Semaphore::release ( size_t n = 1)

Definition at line 14 of file semaphore.cpp.

14 {
15 for(size_t i = 0; i != n; ++i) {
16 std::lock_guard<std::mutex> lock(m_mutex);
17
18 if(m_value++ < 0) {
19 ++m_wakeups;
20 m_cond.notify_one();
21 }
22 }
23}

References Botan::lock().


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