SDL3pp
A slim C++ wrapper for SDL3
Loading...
Searching...
No Matches
SDL::Semaphore Struct Reference

A means to manage access to a resource, by count, between threads. More...

Inheritance diagram for SDL::Semaphore:
[legend]

Public Member Functions

constexpr Semaphore (SemaphoreRaw resource) noexcept
 Constructs from raw Semaphore.
constexpr Semaphore (Semaphore &&other) noexcept
 Move constructor.
 Semaphore (Uint32 initial_value)
 Create a semaphore.
 ~Semaphore ()
 Destructor.
constexpr Semaphoreoperator= (Semaphore &&other) noexcept
 Assignment operator.
Public Member Functions inherited from SDL::SemaphoreBase
void Destroy ()
 Destroy 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 (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 ResourceBaseT ()=default
 Default constructor, creates null/invalid resource.
constexpr ResourceBaseT (RawPointer resource)
 Constructs from resource pointer.
constexpr ResourceBaseT (std::nullptr_t)
 Constructs null/invalid.
constexpr ResourceBaseT (const ResourceBaseT &)=default
 Copy constructor.
constexpr ResourceBaseT (ResourceBaseT &&) noexcept=default
 Move constructor.
Public Member Functions inherited from SDL::ResourceBaseT< SemaphoreRaw >
constexpr ResourceBaseT ()=default
 Default constructor, creates null/invalid resource.
constexpr operator bool () const
 Converts to bool.
constexpr auto operator<=> (const ResourceBaseT &other) const=default
 Comparison.
constexpr RawConstPointer operator-> () const noexcept
 member access to underlying resource pointer.
constexpr RawPointer get () const noexcept
 Retrieves underlying resource pointer.
constexpr RawPointer release () noexcept
 Retrieves underlying resource pointer and clear this.

Additional Inherited Members

Public Types inherited from SDL::ResourceBaseT< SemaphoreRaw >
using RawPointer
 The underlying raw pointer type.
using RawConstPointer
 The underlying const raw pointer type.
Protected Member Functions inherited from SDL::ResourceBaseT< SemaphoreRaw >
constexpr ~ResourceBaseT ()=default
 Destructor.
constexpr ResourceBaseToperator= (const ResourceBaseT &)=default
 Assignment operator.

Detailed Description

A means to manage access to a resource, by count, between threads.

Semaphores (specifically, "counting semaphores"), let X number of threads request access at the same time, each thread granted access decrementing a counter. When the counter reaches zero, future requests block until a prior thread releases their request, incrementing the counter again.

Wikipedia has a thorough explanation of the concept:

https://en.wikipedia.org/wiki/Semaphore_(programming)

Since
This struct is available since SDL 3.2.0.
Category:
Resource

Constructor & Destructor Documentation

◆ Semaphore()

SDL::Semaphore::Semaphore ( SemaphoreRaw resource)
inlineexplicitconstexprnoexcept

Constructs from raw Semaphore.

Parameters
resourcea SemaphoreRaw to be wrapped.

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


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