nlib
nn::nlib::threading::Semaphore Class Referencefinal

Implements a semaphore. More...

#include "nn/nlib/threading/Semaphore.h"

Public Member Functions

errno_t Init (int initial_count) noexcept
 Initializes the semaphore. More...
 
errno_t Release (int *previous_count) noexcept
 Releases one semaphore. More...
 
errno_t Release (int release_count, int *previous_count) noexcept
 Releases multiple semaphores. May not be executed atomically. More...
 
errno_t Acquire () noexcept
 Locks one semaphore. More...
 
errno_t TryAcquire () noexcept
 Tries to lock a semaphore. More...
 
errno_t TryAcquire (const nlib_ns::TimeSpan &timeout) noexcept
 Locks one semaphore with timeout. More...
 

Detailed Description

Implements a semaphore.

Description
Implementation in Win32.
Wraps the Win32 API.
Implementation in Linux/Cygwin
Wraps POSIX semaphore.
Implementation in CTR.
Wraps nn::os::Semaphore.

Definition at line 25 of file Semaphore.h.

Member Function Documentation

◆ Acquire()

nn::nlib::threading::Semaphore::Acquire ( )
inlinenoexcept

Locks one semaphore.

Return values
0Lock was successful.
EINVALInvalid semaphore.

Definition at line 40 of file Semaphore.h.

◆ Init()

nn::nlib::threading::Semaphore::Init ( int  initial_count)
inlinenoexcept

Initializes the semaphore.

Parameters
[in]initial_countInitial value for the semaphore.
Return values
0Initialization was successful.
EINVALIndicates that initialCount is too large.

Definition at line 31 of file Semaphore.h.

◆ Release() [1/2]

nn::nlib::threading::Semaphore::Release ( int *  previous_count)
inlinenoexcept

Releases one semaphore.

Parameters
[out]previous_countThe previous semaphore value is stored if any value other than NULL is specified.
Return values
0Success.
EINVALInvalid semaphore.
EOVERFLOWThe semaphore is already at the maximum count.

Definition at line 34 of file Semaphore.h.

◆ Release() [2/2]

nn::nlib::threading::Semaphore::Release ( int  release_count,
int *  previous_count 
)
inlinenoexcept

Releases multiple semaphores. May not be executed atomically.

Parameters
[in]release_countCount number of semaphores to release.
[out]previous_countThe previous semaphore value is stored if any value other than NULL is specified.
Return values
0Success.
EINVALInvalid semaphore.
EOVERFLOWSemaphores have exceeded the maximum count. The post-execution semaphore count is undefined.
ENOTSUPIndicates that the platform does not support multiple releases.

Definition at line 37 of file Semaphore.h.

◆ TryAcquire() [1/2]

nn::nlib::threading::Semaphore::TryAcquire ( )
inlinenoexcept

Tries to lock a semaphore.

Return values
0Lock was successful.
EAGAINLock was unsuccessful.

Definition at line 41 of file Semaphore.h.

◆ TryAcquire() [2/2]

nn::nlib::threading::Semaphore::TryAcquire ( const nlib_ns::TimeSpan timeout)
inlinenoexcept

Locks one semaphore with timeout.

Parameters
[in]timeoutSpecifies the timeout.
Return values
0Lock was successful.
EINVALInvalid semaphore.
ETIMEDOUTIndicates a timeout.

Definition at line 44 of file Semaphore.h.


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