ardour
Public Member Functions | Private Attributes | List of all members
PBD::Semaphore Class Reference

#include <semaphore.h>

Public Member Functions

 Semaphore (unsigned initial)
 
 ~Semaphore ()
 
void post ()
 
bool wait ()
 
bool try_wait ()
 

Private Attributes

sem_t _sem
 

Detailed Description

Unnamed (process local) counting semaphore.

The civilized person's synchronisation primitive. A counting semaphore is an integer which is always non-negative, so, an attempted decrement (or "wait") will block if the value is 0, until another thread does an increment (or "post").

At least on Lignux, the main advantage of this is that it is fast and the only safe way to reliably signal from a real-time audio thread. The counting semantics also complement ringbuffers of events nicely.

Definition at line 52 of file semaphore.h.

Constructor & Destructor Documentation

PBD::Semaphore::Semaphore ( unsigned  initial)
inline

Create a new semaphore.

Chances are you want 1 wait() per 1 post(), an initial value of 0.

Definition at line 160 of file semaphore.h.

PBD::Semaphore::~Semaphore ( )
inline

Definition at line 168 of file semaphore.h.

Member Function Documentation

void PBD::Semaphore::post ( )
inline

Post/Increment/Signal

Definition at line 174 of file semaphore.h.

bool PBD::Semaphore::try_wait ( )
inline

Attempt Wait/Decrement. Returns true iff a decrement occurred.

Definition at line 193 of file semaphore.h.

bool PBD::Semaphore::wait ( )
inline

Wait/Decrement. Returns false on error.

Definition at line 180 of file semaphore.h.

Member Data Documentation

sem_t PBD::Semaphore::_sem
private

Definition at line 79 of file semaphore.h.


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