LMMS
Loading...
Searching...
No Matches
lmms::Semaphore Class Reference

#include <LmmsSemaphore.h>

Public Member Functions

 Semaphore (unsigned initial)
 Semaphore (const Semaphore &)=delete
Semaphoreoperator= (const Semaphore &)=delete
 Semaphore (Semaphore &&)=delete
Semaphoreoperator= (Semaphore &&)=delete
 ~Semaphore ()
void post ()
void wait ()
bool tryWait ()

Private Attributes

sem_t m_sem

Detailed Description

A counting semaphore.

This is an integer that is always positive, and has two main operations: increment (post) and decrement (wait). If a decrement can not be performed (i.e. the value is 0) the caller will be blocked until another thread posts and the operation can succeed.

Semaphores can be created with any starting value, but typically this will be 0 so the semaphore can be used as a simple signal where each post corresponds to one wait.

Semaphores are very efficient (much more so than a mutex/cond pair). In particular, at least on Linux, post is async-signal-safe, which means it does not block and will not be interrupted. If you need to signal from a realtime thread, this is the most appropriate primitive to use.

Note
Likely outdated with C++20's std::counting_semaphore (though we have to check that this will be RT conforming on all platforms)

Constructor & Destructor Documentation

◆ Semaphore() [1/3]

lmms::Semaphore::Semaphore ( unsigned initial)

◆ Semaphore() [2/3]

lmms::Semaphore::Semaphore ( const Semaphore & )
delete

◆ Semaphore() [3/3]

lmms::Semaphore::Semaphore ( Semaphore && )
delete

◆ ~Semaphore()

lmms::Semaphore::~Semaphore ( )

Member Function Documentation

◆ operator=() [1/2]

Semaphore & lmms::Semaphore::operator= ( const Semaphore & )
delete

◆ operator=() [2/2]

Semaphore & lmms::Semaphore::operator= ( Semaphore && )
delete

◆ post()

void lmms::Semaphore::post ( )

◆ tryWait()

bool lmms::Semaphore::tryWait ( )

◆ wait()

void lmms::Semaphore::wait ( )

Member Data Documentation

◆ m_sem

sem_t lmms::Semaphore::m_sem
private

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