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

A means to block multiple threads until a condition is satisfied. More...

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

Public Member Functions

void Signal ()
 Restart one of the threads that are waiting on the condition variable.
 
void Broadcast ()
 Restart all threads that are waiting on the condition variable.
 
void Wait (MutexRef mutex)
 Wait until a condition variable is signaled.
 
bool WaitTimeout (MutexRef mutex, std::chrono::milliseconds timeout)
 Wait until a condition variable is signaled or a certain time has passed.
 
constexpr Resource (T resource={})
 Constructs from the underlying resource.
 
constexpr Resource (const ResourceHandle< Resource< T > > auto &resource)
 Constructs from pointer like.
 
constexpr Resource (std::nullptr_t)
 Equivalent to default ctor.
 
constexpr Resource (std::nullopt_t)
 Equivalent to default ctor.
 
- Public Member Functions inherited from SDL::Resource< SDL_Condition * >
constexpr Resource (SDL_Condition * resource={})
 Constructs from the underlying resource.
 
constexpr Resource (const ResourceHandle< Resource< SDL_Condition * > > auto &resource)
 Constructs from pointer like.
 
constexpr Resource (std::nullptr_t)
 Equivalent to default ctor.
 
constexpr Resource (std::nullopt_t)
 Equivalent to default ctor.
 
constexpr operator bool () const
 True if contains a valid resource.
 
constexpr operator value_type () const
 Converts back to underlying type.
 
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_Condition * get () const
 Return contained resource;.
 
constexpr const SDL_Condition * operator-> () const
 Access to fields.
 
constexpr SDL_Condition * operator-> ()
 Access to fields.
 

Static Public Member Functions

static void reset (SDL_Condition *resource)
 Destroy a condition variable.
 

Additional Inherited Members

- Public Types inherited from SDL::Resource< SDL_Condition * >
using value_type = SDL_Condition *
 The raw resource type.
 

Detailed Description

Condition variables, paired with an Mutex, let an app halt multiple threads until a condition has occurred, at which time the app can release one or all waiting threads.

Wikipedia has a thorough explanation of the concept:

https://en.wikipedia.org/wiki/Condition_variable

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

Member Function Documentation

◆ Broadcast()

void SDL::ConditionRef::Broadcast ( )
inline
Thread safety:
It is safe to call this function from any thread.
Since
This function is available since SDL 3.2.0.
See also
ConditionRef.Signal
ConditionRef.Wait
ConditionRef.WaitTimeout

◆ reset()

static void SDL::ConditionRef::reset ( SDL_Condition *  resource)
inlinestatic
Parameters
resourcethe condition variable to destroy.
Since
This function is available since SDL 3.2.0.
See also
Condition.Create

◆ Signal()

void SDL::ConditionRef::Signal ( )
inline
Thread safety:
It is safe to call this function from any thread.
Since
This function is available since SDL 3.2.0.
See also
ConditionRef.Broadcast
ConditionRef.Wait
ConditionRef.WaitTimeout

◆ Wait()

void SDL::ConditionRef::Wait ( MutexRef  mutex)
inline

This function unlocks the specified mutex and waits for another thread to call ConditionRef.Signal() or ConditionRef.Broadcast() on the condition variable cond. Once the condition variable is signaled, the mutex is re-locked and the function returns.

The mutex must be locked before calling this function. Locking the mutex recursively (more than once) is not supported and leads to undefined behavior.

This function is the equivalent of calling ConditionRef.WaitTimeout() with a time length of -1.

Parameters
mutexthe mutex used to coordinate thread access.
Thread safety:
It is safe to call this function from any thread.
Since
This function is available since SDL 3.2.0.
See also
ConditionRef.Broadcast
ConditionRef.Signal
ConditionRef.WaitTimeout

◆ WaitTimeout()

bool SDL::ConditionRef::WaitTimeout ( MutexRef  mutex,
std::chrono::milliseconds  timeout 
)
inline

This function unlocks the specified mutex and waits for another thread to call ConditionRef.Signal() or ConditionRef.Broadcast() on the condition variable cond, or for the specified time to elapse. Once the condition variable is signaled or the time elapsed, the mutex is re-locked and the function returns.

The mutex must be locked before calling this function. Locking the mutex recursively (more than once) is not supported and leads to undefined behavior.

Parameters
mutexthe mutex used to coordinate thread access.
timeoutthe maximum time to wait, in milliseconds, or -1 to wait indefinitely.
Returns
true if the condition variable is signaled, false if the condition is not signaled in the allotted time.
Thread safety:
It is safe to call this function from any thread.
Since
This function is available since SDL 3.2.0.
See also
ConditionRef.Broadcast
ConditionRef.Signal
ConditionRef.Wait

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