Zrythm v2.0.0-DEV
a highly automated and intuitive digital audio workstation
Loading...
Searching...
No Matches
SemaphoreRAII< SemaphoreType > Class Template Reference

RAII wrapper class for std::binary_semaphore. More...

#include <src/utils/concurrency.h>

Public Member Functions

 SemaphoreRAII (SemaphoreType &semaphore, bool force_acquire=false)
 Constructor that attempts to acquire the semaphore.
 ~SemaphoreRAII ()
 Destructor that releases the semaphore if it was acquired.
 SemaphoreRAII (const SemaphoreRAII &)=delete
SemaphoreRAIIoperator= (const SemaphoreRAII &)=delete
 SemaphoreRAII (SemaphoreRAII &&)=default
SemaphoreRAIIoperator= (SemaphoreRAII &&)=default
bool try_acquire ()
 Attempts to acquire the semaphore if it hasn't been acquired already.
void release ()
 Releases the semaphore if it was previously acquired.
bool is_acquired () const
 Checks if the semaphore is currently acquired by the wrapper object.

Detailed Description

template<typename SemaphoreType = std::binary_semaphore>
class SemaphoreRAII< SemaphoreType >

RAII wrapper class for std::binary_semaphore.

This class provides a convenient and safe way to acquire and release a binary semaphore using the RAII (Resource Acquisition Is Initialization) idiom. It ensures that the semaphore is properly released when the wrapper object goes out of scope.

Definition at line 60 of file concurrency.h.

Constructor & Destructor Documentation

◆ SemaphoreRAII()

template<typename SemaphoreType = std::binary_semaphore>
SemaphoreRAII< SemaphoreType >::SemaphoreRAII ( SemaphoreType & semaphore,
bool force_acquire = false )
inlineexplicit

Constructor that attempts to acquire the semaphore.

Parameters
semaphoreThe semaphore to acquire.

Definition at line 68 of file concurrency.h.

◆ ~SemaphoreRAII()

template<typename SemaphoreType = std::binary_semaphore>
SemaphoreRAII< SemaphoreType >::~SemaphoreRAII ( )
inline

Destructor that releases the semaphore if it was acquired.

Definition at line 101 of file concurrency.h.

Member Function Documentation

◆ is_acquired()

template<typename SemaphoreType = std::binary_semaphore>
bool SemaphoreRAII< SemaphoreType >::is_acquired ( ) const
inline

Checks if the semaphore is currently acquired by the wrapper object.

Returns
true if the semaphore is acquired, false otherwise.

Definition at line 169 of file concurrency.h.

◆ release()

template<typename SemaphoreType = std::binary_semaphore>
void SemaphoreRAII< SemaphoreType >::release ( )
inline

Releases the semaphore if it was previously acquired.

Definition at line 147 of file concurrency.h.

◆ try_acquire()

template<typename SemaphoreType = std::binary_semaphore>
bool SemaphoreRAII< SemaphoreType >::try_acquire ( )
inline

Attempts to acquire the semaphore if it hasn't been acquired already.

Returns
true if the semaphore is successfully acquired, false otherwise.

Definition at line 127 of file concurrency.h.


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