Botan  1.11.15
Public Member Functions
Botan::Semaphore Class Reference

#include <semaphore.h>

List of all members.

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

Botan::Semaphore::Semaphore ( int  value = 0) [inline]

Definition at line 19 of file semaphore.h.

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

Member Function Documentation

Definition at line 30 of file semaphore.cpp.

   {
   std::unique_lock<std::mutex> lock(m_mutex);
   --m_value;
   if(m_value < 0)
      {
      m_cond.wait(lock, [this] { return m_wakeups > 0; });
      --m_wakeups;
      }
   }
void Botan::Semaphore::release ( size_t  n = 1)

Definition at line 14 of file semaphore.cpp.

References n.

   {
   for(size_t i = 0; i != n; ++i)
      {
      std::lock_guard<std::mutex> lock(m_mutex);

      ++m_value;

      if(m_value <= 0)
         {
         ++m_wakeups;
         m_cond.notify_one();
         }
      }
   }

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