SDL3pp
A slim C++ wrapper for SDL3
Loading...
Searching...
No Matches
Public Member Functions | List of all members
SDL::SemaphoreRef Struct Reference

Reference for Semaphore. More...

Inheritance diagram for SDL::SemaphoreRef:
Inheritance graph
[legend]
Collaboration diagram for SDL::SemaphoreRef:
Collaboration graph
[legend]

Public Member Functions

 SemaphoreRef (SemaphoreRaw resource) noexcept
 Constructs from raw Semaphore. More...
 
constexpr SemaphoreRef (const Semaphore &resource) noexcept
 Constructs from Semaphore. More...
 
constexpr SemaphoreRef (const SemaphoreRef &other) noexcept
 Copy constructor.
 
constexpr SemaphoreRef (SemaphoreRef &&other) noexcept
 Move constructor.
 
 ~SemaphoreRef ()
 Destructor.
 
constexpr SemaphoreRefoperator= (SemaphoreRef other) noexcept
 Assignment operator.
 
constexpr operator SemaphoreRaw () const noexcept
 Converts to SemaphoreRaw.
 
constexpr Semaphore (std::nullptr_t=nullptr) noexcept
 Default ctor.
 
constexpr Semaphore (const SemaphoreRaw resource) noexcept
 Constructs from SemaphoreRef. More...
 
constexpr Semaphore (const Semaphore &other) noexcept=default
 Copy constructor.
 
constexpr Semaphore (Semaphore &&other) noexcept
 Move constructor.
 
constexpr Semaphore (const SemaphoreRef &other)=delete
 
constexpr Semaphore (SemaphoreRef &&other)=delete
 
 Semaphore (Uint32 initial_value)
 Create a semaphore. More...
 
- Public Member Functions inherited from SDL::Semaphore
constexpr Semaphore (std::nullptr_t=nullptr) noexcept
 Default ctor.
 
constexpr Semaphore (const SemaphoreRaw resource) noexcept
 Constructs from SemaphoreRef. More...
 
constexpr Semaphore (Semaphore &&other) noexcept
 Move constructor.
 
constexpr Semaphore (const SemaphoreRef &other)=delete
 
constexpr Semaphore (SemaphoreRef &&other)=delete
 
 Semaphore (Uint32 initial_value)
 Create a semaphore. More...
 
 ~Semaphore ()
 Destructor.
 
constexpr Semaphoreoperator= (Semaphore &&other) noexcept
 Assignment operator.
 
constexpr SemaphoreRaw get () const noexcept
 Retrieves underlying SemaphoreRaw.
 
constexpr SemaphoreRaw release () noexcept
 Retrieves underlying SemaphoreRaw and clear this.
 
constexpr auto operator<=> (const Semaphore &other) const noexcept=default
 Comparison.
 
constexpr operator bool () const noexcept
 Converts to bool.
 
void Destroy ()
 Destroy a semaphore. More...
 
void Wait ()
 Wait until a semaphore has a positive value and then decrements it. More...
 
bool TryWait ()
 See if a semaphore has a positive value and decrement it if it does. More...
 
bool WaitTimeout (std::chrono::milliseconds timeout)
 Wait until a semaphore has a positive value and then decrements it. More...
 
void Signal ()
 Atomically increment a semaphore's value and wake waiting threads. More...
 
Uint32 GetValue () const
 Get the current value of a semaphore. More...
 

Additional Inherited Members

- Protected Member Functions inherited from SDL::Semaphore
constexpr Semaphore (const Semaphore &other) noexcept=default
 Copy constructor.
 
constexpr Semaphoreoperator= (const Semaphore &other) noexcept=default
 Assignment operator.
 

Detailed Description

This does not take ownership!

Constructor & Destructor Documentation

◆ SemaphoreRef() [1/2]

SDL::SemaphoreRef::SemaphoreRef ( SemaphoreRaw  resource)
inlinenoexcept
Parameters
resourcea SemaphoreRaw.

This does not takes ownership!

◆ SemaphoreRef() [2/2]

constexpr SDL::SemaphoreRef::SemaphoreRef ( const Semaphore resource)
inlineconstexprnoexcept
Parameters
resourcea Semaphore.

This does not takes ownership!

Member Function Documentation

◆ Semaphore() [1/2]

constexpr SDL::Semaphore::Semaphore ( const SemaphoreRaw  resource)
inlineexplicitconstexprnoexcept
Parameters
resourcea SemaphoreRaw to be wrapped.

This assumes the ownership, call release() if you need to take back.

◆ Semaphore() [2/2]

SDL::Semaphore::Semaphore ( Uint32  initial_value)
inline

This function creates a new semaphore and initializes it with the value initial_value. Each wait operation on the semaphore will atomically decrement the semaphore value and potentially block if the semaphore value is 0. Each post operation will atomically increment the semaphore value and wake waiting threads and allow them to retry the wait operation.

Parameters
initial_valuethe starting value of the semaphore.
Postcondition
a new semaphore or nullptr on failure; call GetError() for more information.
Thread safety:
It is safe to call this function from any thread.
Since
This function is available since SDL 3.2.0.
See also
Semaphore.Destroy
Semaphore.Signal
Semaphore.TryWait
Semaphore.GetValue
Semaphore.Wait
Semaphore.WaitTimeout

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