Roc Toolkit internal modules
Roc Toolkit: real-time audio streaming
roc::core::Semaphore Class Reference

Semaphore. More...

#include <semaphore.h>

Inheritance diagram for roc::core::Semaphore:
Collaboration diagram for roc::core::Semaphore:

Public Member Functions

 Semaphore (unsigned counter=0)
 Initialize semaphore with given counter. More...
 
ROC_ATTR_NODISCARD bool timed_wait (nanoseconds_t deadline)
 Wait until the counter becomes non-zero, decrement it, and return true. If deadline expires before the counter becomes non-zero, returns false. Deadline should be in the same time domain as core::timestamp(). More...
 
void wait ()
 Wait until the counter becomes non-zero, decrement it, and return. More...
 
void post ()
 Increment counter and wake up blocked waits. This method is lock-free. More...
 
 Semaphore (unsigned counter=0)
 Initialize semaphore with given counter. More...
 
ROC_ATTR_NODISCARD bool timed_wait (nanoseconds_t deadline)
 Wait until the counter becomes non-zero, decrement it, and return true. If deadline expires before the counter becomes non-zero, returns false. Deadline should be in the same time domain as core::timestamp(). More...
 
void wait ()
 Wait until the counter becomes non-zero, decrement it, and return. More...
 
void post ()
 Increment counter and wake up blocked waits. This method is lock-free at least on recent glibc and musl versions (which implement POSIX semaphores using a futex and an atomic). More...
 

Detailed Description

Semaphore.

Definition at line 25 of file semaphore.h.

Constructor & Destructor Documentation

◆ Semaphore() [1/2]

roc::core::Semaphore::Semaphore ( unsigned  counter = 0)
explicit

Initialize semaphore with given counter.

◆ Semaphore() [2/2]

roc::core::Semaphore::Semaphore ( unsigned  counter = 0)
explicit

Initialize semaphore with given counter.

Member Function Documentation

◆ post() [1/2]

void roc::core::Semaphore::post ( )

Increment counter and wake up blocked waits. This method is lock-free.

◆ post() [2/2]

void roc::core::Semaphore::post ( )

Increment counter and wake up blocked waits. This method is lock-free at least on recent glibc and musl versions (which implement POSIX semaphores using a futex and an atomic).

◆ timed_wait() [1/2]

ROC_ATTR_NODISCARD bool roc::core::Semaphore::timed_wait ( nanoseconds_t  deadline)

Wait until the counter becomes non-zero, decrement it, and return true. If deadline expires before the counter becomes non-zero, returns false. Deadline should be in the same time domain as core::timestamp().

◆ timed_wait() [2/2]

ROC_ATTR_NODISCARD bool roc::core::Semaphore::timed_wait ( nanoseconds_t  deadline)

Wait until the counter becomes non-zero, decrement it, and return true. If deadline expires before the counter becomes non-zero, returns false. Deadline should be in the same time domain as core::timestamp().

◆ wait() [1/2]

void roc::core::Semaphore::wait ( )

Wait until the counter becomes non-zero, decrement it, and return.

◆ wait() [2/2]

void roc::core::Semaphore::wait ( )

Wait until the counter becomes non-zero, decrement it, and return.


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