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

Handle to a non owned semaphore. More...

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

Public Member Functions

constexpr SemaphoreRef (const SemaphoreRef &other)
 Copy constructor.
 
constexpr SemaphoreRef (SemaphoreRef &&other)
 Move constructor.
 
constexpr ~SemaphoreRef ()=default
 Default constructor.
 
SemaphoreRefoperator= (SemaphoreRef other)
 Assignment operator.
 
void reset (SDL_Semaphore *newResource={})
 Destroy a semaphore.
 
 SemaphoreBase (Uint32 initial_value)
 Create a semaphore.
 
- Public Member Functions inherited from SDL::SemaphoreBase
 SemaphoreBase (Uint32 initial_value)
 Create a semaphore.
 
void Wait ()
 Wait until a semaphore has a positive value and then decrements it.
 
bool TryWait ()
 See if a semaphore has a positive value and decrement it if it does.
 
bool WaitTimeout (std::chrono::milliseconds timeout)
 Wait until a semaphore has a positive value and then decrements it.
 
void Signal ()
 Atomically increment a semaphore's value and wake waiting threads.
 
Uint32 GetValue () const
 Get the current value of a semaphore.
 
constexpr Resource (T resource={})
 Constructs the underlying resource.
 
constexpr Resource (std::nullptr_t)
 Equivalent to default ctor.
 
constexpr Resource (std::nullopt_t)
 Equivalent to default ctor.
 
 Resource (const Resource &other)=delete
 
 Resource (Resource &&other)=delete
 
- Public Member Functions inherited from SDL::Resource< SDL_Semaphore * >
constexpr Resource (SDL_Semaphore * resource={})
 Constructs the underlying resource.
 
constexpr Resource (std::nullptr_t)
 Equivalent to default ctor.
 
constexpr Resource (std::nullopt_t)
 Equivalent to default ctor.
 
 Resource (const Resource &other)=delete
 
 Resource (Resource &&other)=delete
 
Resourceoperator= (const Resource &other)=delete
 
Resourceoperator= (Resource &&other)=delete
 
constexpr operator bool () const
 True if contains a valid resource.
 
constexpr bool operator== (const Resource &other) const=default
 Comparison.
 
constexpr bool operator== (std::nullopt_t) const
 Comparison.
 
constexpr bool operator== (std::nullptr_t) const
 Comparison.
 
constexpr SDL_Semaphore * get () const
 Return contained resource;.
 
constexpr SDL_Semaphore * release (SDL_Semaphore * newResource={})
 Return contained resource and empties or replace value.
 
constexpr const SDL_Semaphore * operator-> () const
 Access to fields.
 
constexpr SDL_Semaphore * operator-> ()
 Access to fields.
 

Detailed Description

Category:
Resource
See also
SemaphoreBase
Semaphore

Member Function Documentation

◆ reset()

void SDL::SemaphoreRef::reset ( SDL_Semaphore *  newResource = {})
inline

It is not safe to destroy a semaphore if there are threads currently waiting on it.

Since
This function is available since SDL 3.2.0.
See also
SemaphoreBase.SemaphoreBase

◆ SemaphoreBase()

SDL::SemaphoreBase::SemaphoreBase ( 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.
Since
This function is available since SDL 3.2.0.
See also
SemaphoreBase.Signal
SemaphoreBase.TryWait
SemaphoreBase.GetValue
SemaphoreBase.Wait
SemaphoreBase.WaitTimeout

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