4#include <SDL3/SDL_mutex.h>
5#include "SDL3pp_stdinc.h"
6#include "SDL3pp_thread.h"
230 static void reset(SDL_Mutex* resource) { SDL_DestroyMutex(resource); }
500 static void reset(SDL_RWLock* resource) { SDL_DestroyRWLock(resource); }
684 return SDL_WaitSemaphoreTimeout(
get(), timeout.count());
720 static void reset(SDL_Semaphore* resource) { SDL_DestroySemaphore(resource); }
758 return Semaphore(SDL_CreateSemaphore(initial_value));
913 return SDL_WaitConditionTimeout(
get(), mutex, timeout.count());
925 static void reset(SDL_Condition* resource) { SDL_DestroyCondition(resource); }
1007 SDL_INIT_STATUS_UNINITIALIZED;
1010 SDL_INIT_STATUS_INITIALIZING;
1013 SDL_INIT_STATUS_INITIALIZED;
1016 SDL_INIT_STATUS_UNINITIALIZING;
1146 SDL_SetInitialized(
this, initialized);
RESOURCE release()
Returns reference and reset this.
Definition SDL3pp_resource.h:178
Implement shared ownership for a resource.
Definition SDL3pp_resource.h:283
Implement unique ownership for a resource.
Definition SDL3pp_resource.h:226
constexpr ResourceUnique(std::nullptr_t=nullptr)
Default constructor.
Definition SDL3pp_resource.h:231
void reset()
Resets the value, destroying the resource if not nullptr.
Definition SDL3pp_resource.h:265
A dumb pointer to resource.
Definition SDL3pp_resource.h:197
constexpr ResourceUnsafe()=default
Default constructor.
Implement weak ownership for a resource.
Definition SDL3pp_resource.h:328
A SDL managed resource.
Definition SDL3pp_resource.h:29
constexpr Resource(T resource={})
Constructs from the underlying resource.
Definition SDL3pp_resource.h:37
constexpr SDL_Mutex * get() const
Return contained resource;.
Definition SDL3pp_resource.h:76
constexpr void CheckError(bool result)
Check and throw if returned value from SDL is an error.
Definition SDL3pp_error.h:206
ResourceShared< RWLock > RWLockShared
Handle to a shared rWLock.
Definition SDL3pp_mutex.h:71
RWLockShared share()
Move this rWLock into a RWLockShared.
Definition SDL3pp_mutex.h:579
constexpr InitStatus INIT_STATUS_UNINITIALIZING
INIT_STATUS_UNINITIALIZING.
Definition SDL3pp_mutex.h:1015
ResourceShared< Semaphore > SemaphoreShared
Handle to a shared semaphore.
Definition SDL3pp_mutex.h:97
ResourceShared< Mutex > MutexShared
Handle to a shared mutex.
Definition SDL3pp_mutex.h:45
constexpr InitStatus INIT_STATUS_INITIALIZING
INIT_STATUS_INITIALIZING.
Definition SDL3pp_mutex.h:1009
constexpr InitStatus INIT_STATUS_UNINITIALIZED
INIT_STATUS_UNINITIALIZED.
Definition SDL3pp_mutex.h:1006
SemaphoreShared share()
Move this semaphore into a SemaphoreShared.
Definition SDL3pp_mutex.h:781
SDL_InitStatus InitStatus
The current status of an InitState structure.
Definition SDL3pp_mutex.h:1004
constexpr InitStatus INIT_STATUS_INITIALIZED
INIT_STATUS_INITIALIZED.
Definition SDL3pp_mutex.h:1012
ConditionShared share()
Move this condition into a ConditionShared.
Definition SDL3pp_mutex.h:972
MutexShared share()
Move this mutex into a MutexShared.
Definition SDL3pp_mutex.h:289
ResourceShared< Condition > ConditionShared
Handle to a shared condition.
Definition SDL3pp_mutex.h:123
the main namespace where all SDL3pp public functions and types live
Definition SDL3pp_assert.h:7
A means to block multiple threads until a condition is satisfied.
Definition SDL3pp_mutex.h:826
void Broadcast()
Restart all threads that are waiting on the condition variable.
Definition SDL3pp_mutex.h:855
void Signal()
Restart one of the threads that are waiting on the condition variable.
Definition SDL3pp_mutex.h:841
void Wait(MutexRef mutex)
Wait until a condition variable is signaled.
Definition SDL3pp_mutex.h:882
bool WaitTimeout(MutexRef mutex, std::chrono::milliseconds timeout)
Wait until a condition variable is signaled or a certain time has passed.
Definition SDL3pp_mutex.h:911
static void reset(SDL_Condition *resource)
Destroy a condition variable.
Definition SDL3pp_mutex.h:925
Unsafe Handle to condition.
Definition SDL3pp_mutex.h:987
constexpr ConditionUnsafe(Condition &&other)
Constructs ConditionUnsafe from Condition.
Definition SDL3pp_mutex.h:993
Handle to an owned condition.
Definition SDL3pp_mutex.h:936
static Condition Create()
Create a condition variable.
Definition SDL3pp_mutex.h:953
void Destroy()
Destroy a condition variable.
Definition SDL3pp_mutex.h:963
A structure used for thread-safe initialization and shutdown.
Definition SDL3pp_mutex.h:1077
bool ShouldQuit()
Return whether cleanup should be done.
Definition SDL3pp_mutex.h:1126
bool ShouldInit()
Return whether initialization should be done.
Definition SDL3pp_mutex.h:1106
constexpr InitState()
Constructor.
Definition SDL3pp_mutex.h:1081
void SetInitialized(bool initialized)
Finish an initialization state transition.
Definition SDL3pp_mutex.h:1144
A means to serialize access to a resource between threads.
Definition SDL3pp_mutex.h:152
void TryLock()
Try to lock a mutex without blocking.
Definition SDL3pp_mutex.h:195
void Unlock()
Unlock the mutex.
Definition SDL3pp_mutex.h:213
static void reset(SDL_Mutex *resource)
Destroy a mutex created with Mutex.Create().
Definition SDL3pp_mutex.h:230
void Lock()
Lock the mutex.
Definition SDL3pp_mutex.h:175
Unsafe Handle to mutex.
Definition SDL3pp_mutex.h:304
constexpr MutexUnsafe(Mutex &&other)
Constructs MutexUnsafe from Mutex.
Definition SDL3pp_mutex.h:310
Handle to an owned mutex.
Definition SDL3pp_mutex.h:241
void Destroy()
Destroy a mutex created with Mutex.Create().
Definition SDL3pp_mutex.h:280
static Mutex Create()
Create a new mutex.
Definition SDL3pp_mutex.h:264
A mutex that allows read-only threads to run in parallel.
Definition SDL3pp_mutex.h:339
void LockForWriting()
Lock the read/write lock for write operations.
Definition SDL3pp_mutex.h:406
static void reset(SDL_RWLock *resource)
Destroy a read/write lock created with RWLock.Create().
Definition SDL3pp_mutex.h:500
void TryLockForWriting()
Try to lock a read/write lock for writing without blocking.
Definition SDL3pp_mutex.h:459
void Unlock()
Unlock the read/write lock.
Definition SDL3pp_mutex.h:483
void TryLockForReading()
Try to lock a read/write lock for reading without blocking.
Definition SDL3pp_mutex.h:430
void LockForReading()
Lock the read/write lock for read only operations.
Definition SDL3pp_mutex.h:376
Unsafe Handle to rWLock.
Definition SDL3pp_mutex.h:594
constexpr RWLockUnsafe(RWLock &&other)
Constructs RWLockUnsafe from RWLock.
Definition SDL3pp_mutex.h:600
Handle to an owned rWLock.
Definition SDL3pp_mutex.h:511
static RWLock Create()
Create a new read/write lock.
Definition SDL3pp_mutex.h:554
void Destroy()
Destroy a read/write lock created with RWLock.Create().
Definition SDL3pp_mutex.h:570
A means to manage access to a resource, by count, between threads.
Definition SDL3pp_mutex.h:625
void Signal()
Atomically increment a semaphore's value and wake waiting threads.
Definition SDL3pp_mutex.h:697
bool TryWait()
See if a semaphore has a positive value and decrement it if it does.
Definition SDL3pp_mutex.h:663
static void reset(SDL_Semaphore *resource)
Destroy a semaphore.
Definition SDL3pp_mutex.h:720
Uint32 GetValue() const
Get the current value of a semaphore.
Definition SDL3pp_mutex.h:706
void Wait()
Wait until a semaphore has a positive value and then decrements it.
Definition SDL3pp_mutex.h:645
bool WaitTimeout(std::chrono::milliseconds timeout)
Wait until a semaphore has a positive value and then decrements it.
Definition SDL3pp_mutex.h:682
Unsafe Handle to semaphore.
Definition SDL3pp_mutex.h:796
constexpr SemaphoreUnsafe(Semaphore &&other)
Constructs SemaphoreUnsafe from Semaphore.
Definition SDL3pp_mutex.h:802
Handle to an owned semaphore.
Definition SDL3pp_mutex.h:731
void Destroy()
Destroy a semaphore.
Definition SDL3pp_mutex.h:772
static Semaphore Create(Uint32 initial_value)
Create a semaphore.
Definition SDL3pp_mutex.h:756