4#include <SDL3/SDL_mutex.h>
5#include "SDL3pp_stdinc.h"
6#include "SDL3pp_thread.h"
231 void reset(SDL_Mutex* newResource = {})
233 SDL_DestroyMutex(
release(newResource));
252 constexpr explicit Mutex(SDL_Mutex* resource = {})
257 constexpr Mutex(
const Mutex& other) =
delete;
549 void reset(SDL_RWLock* newResource = {})
551 SDL_DestroyRWLock(
release(newResource));
570 constexpr explicit RWLock(SDL_RWLock* resource = {})
575 constexpr RWLock(
const RWLock& other) =
delete;
642 :
Resource(SDL_CreateSemaphore(initial_value))
702 return SDL_WaitSemaphoreTimeout(
get(), timeout.count());
779 void reset(SDL_Semaphore* newResource = {})
781 SDL_DestroySemaphore(
release(newResource));
800 constexpr explicit Semaphore(SDL_Semaphore* resource = {})
805 constexpr Semaphore(
const Semaphore& other) =
delete;
951 return SDL_WaitConditionTimeout(
get(), mutex.
get(), timeout.count());
1004 void reset(SDL_Condition* newResource = {})
1006 SDL_DestroyCondition(
release(newResource));
1030 constexpr Condition(
const Condition& other) =
delete;
1060 SDL_INIT_STATUS_UNINITIALIZED;
1063 SDL_INIT_STATUS_INITIALIZING;
1066 SDL_INIT_STATUS_INITIALIZED;
1069 SDL_INIT_STATUS_UNINITIALIZING;
1199 SDL_SetInitialized(
this, initialized);
A SDL managed resource.
Definition SDL3pp_resource.h:17
constexpr SDL_Mutex * release(SDL_Mutex * newResource={})
Return contained resource and empties or replace value.
Definition SDL3pp_resource.h:60
constexpr Resource(T resource={})
Constructs the underlying resource.
Definition SDL3pp_resource.h:22
constexpr SDL_Mutex * get() const
Return contained resource;.
Definition SDL3pp_resource.h:57
constexpr void CheckError(bool result)
Check and throw if returned value from SDL is an error.
Definition SDL3pp_error.h:206
constexpr InitStatus INIT_STATUS_UNINITIALIZING
INIT_STATUS_UNINITIALIZING.
Definition SDL3pp_mutex.h:1068
constexpr InitStatus INIT_STATUS_INITIALIZING
INIT_STATUS_INITIALIZING.
Definition SDL3pp_mutex.h:1062
constexpr InitStatus INIT_STATUS_UNINITIALIZED
INIT_STATUS_UNINITIALIZED.
Definition SDL3pp_mutex.h:1059
SDL_InitStatus InitStatus
The current status of an InitState structure.
Definition SDL3pp_mutex.h:1057
constexpr InitStatus INIT_STATUS_INITIALIZED
INIT_STATUS_INITIALIZED.
Definition SDL3pp_mutex.h:1065
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:846
bool WaitTimeout(MutexBase &mutex, std::chrono::milliseconds timeout)
Wait until a condition variable is signaled or a certain time has passed.
Definition SDL3pp_mutex.h:949
void Signal()
Restart one of the threads that are waiting on the condition variable.
Definition SDL3pp_mutex.h:879
ConditionBase()
Create a condition variable.
Definition SDL3pp_mutex.h:862
void Broadcast()
Restart all threads that are waiting on the condition variable.
Definition SDL3pp_mutex.h:893
void Wait(MutexBase &mutex)
Wait until a condition variable is signaled.
Definition SDL3pp_mutex.h:920
Handle to a non owned condition.
Definition SDL3pp_mutex.h:964
void reset(SDL_Condition *newResource={})
Destroy a condition variable.
Definition SDL3pp_mutex.h:1004
constexpr ConditionRef(ConditionRef &&other)
Move constructor.
Definition SDL3pp_mutex.h:978
constexpr ConditionRef(const ConditionRef &other)
Copy constructor.
Definition SDL3pp_mutex.h:970
ConditionRef & operator=(ConditionRef other)
Assignment operator.
Definition SDL3pp_mutex.h:991
constexpr ~ConditionRef()=default
Default constructor.
Handle to an owned condition.
Definition SDL3pp_mutex.h:1019
constexpr Condition(SDL_Condition *resource={})
Constructs from the underlying resource.
Definition SDL3pp_mutex.h:1025
Condition & operator=(Condition other)
Assignment operator.
Definition SDL3pp_mutex.h:1045
constexpr Condition(Condition &&other)=default
Move constructor.
~Condition()
Frees up resource when object goes out of scope.
Definition SDL3pp_mutex.h:1040
A structure used for thread-safe initialization and shutdown.
Definition SDL3pp_mutex.h:1130
bool ShouldQuit()
Return whether cleanup should be done.
Definition SDL3pp_mutex.h:1179
bool ShouldInit()
Return whether initialization should be done.
Definition SDL3pp_mutex.h:1159
constexpr InitState()
Constructor.
Definition SDL3pp_mutex.h:1134
void SetInitialized(bool initialized)
Finish an initialization state transition.
Definition SDL3pp_mutex.h:1197
A means to serialize access to a resource between threads.
Definition SDL3pp_mutex.h:85
void Unlock()
Unlock the mutex.
Definition SDL3pp_mutex.h:172
void TryLock()
Try to lock a mutex without blocking.
Definition SDL3pp_mutex.h:154
void Lock()
Lock the mutex.
Definition SDL3pp_mutex.h:134
MutexBase()
Create a new mutex.
Definition SDL3pp_mutex.h:108
Handle to a non owned mutex.
Definition SDL3pp_mutex.h:184
constexpr ~MutexRef()=default
Default constructor.
void reset(SDL_Mutex *newResource={})
Destroy a mutex created with MutexBase.MutexBase().
Definition SDL3pp_mutex.h:231
constexpr MutexRef(const MutexRef &other)
Copy constructor.
Definition SDL3pp_mutex.h:190
constexpr MutexRef(MutexRef &&other)
Move constructor.
Definition SDL3pp_mutex.h:198
MutexRef & operator=(MutexRef other)
Assignment operator.
Definition SDL3pp_mutex.h:211
Handle to an owned mutex.
Definition SDL3pp_mutex.h:246
constexpr Mutex(SDL_Mutex *resource={})
Constructs from the underlying resource.
Definition SDL3pp_mutex.h:252
~Mutex()
Frees up resource when object goes out of scope.
Definition SDL3pp_mutex.h:267
Mutex & operator=(Mutex other)
Assignment operator.
Definition SDL3pp_mutex.h:272
constexpr Mutex(Mutex &&other)=default
Move constructor.
A mutex that allows read-only threads to run in parallel.
Definition SDL3pp_mutex.h:303
void TryLockForReading()
Try to lock a read/write lock for reading without blocking.
Definition SDL3pp_mutex.h:438
void LockForWriting()
Lock the read/write lock for write operations.
Definition SDL3pp_mutex.h:414
void TryLockForWriting()
Try to lock a read/write lock for writing without blocking.
Definition SDL3pp_mutex.h:467
RWLockBase()
Create a new read/write lock.
Definition SDL3pp_mutex.h:345
void LockForReading()
Lock the read/write lock for read only operations.
Definition SDL3pp_mutex.h:384
void Unlock()
Unlock the read/write lock.
Definition SDL3pp_mutex.h:491
Handle to a non owned rWLock.
Definition SDL3pp_mutex.h:503
constexpr ~RWLockRef()=default
Default constructor.
RWLockRef & operator=(RWLockRef other)
Assignment operator.
Definition SDL3pp_mutex.h:530
constexpr RWLockRef(const RWLockRef &other)
Copy constructor.
Definition SDL3pp_mutex.h:509
constexpr RWLockRef(RWLockRef &&other)
Move constructor.
Definition SDL3pp_mutex.h:517
void reset(SDL_RWLock *newResource={})
Destroy a read/write lock created with RWLockBase.RWLockBase().
Definition SDL3pp_mutex.h:549
Handle to an owned rWLock.
Definition SDL3pp_mutex.h:564
constexpr RWLock(RWLock &&other)=default
Move constructor.
~RWLock()
Frees up resource when object goes out of scope.
Definition SDL3pp_mutex.h:585
constexpr RWLock(SDL_RWLock *resource={})
Constructs from the underlying resource.
Definition SDL3pp_mutex.h:570
RWLock & operator=(RWLock other)
Assignment operator.
Definition SDL3pp_mutex.h:590
A means to manage access to a resource, by count, between threads.
Definition SDL3pp_mutex.h:617
Uint32 GetValue() const
Get the current value of a semaphore.
Definition SDL3pp_mutex.h:724
bool TryWait()
See if a semaphore has a positive value and decrement it if it does.
Definition SDL3pp_mutex.h:681
void Wait()
Wait until a semaphore has a positive value and then decrements it.
Definition SDL3pp_mutex.h:663
void Signal()
Atomically increment a semaphore's value and wake waiting threads.
Definition SDL3pp_mutex.h:715
bool WaitTimeout(std::chrono::milliseconds timeout)
Wait until a semaphore has a positive value and then decrements it.
Definition SDL3pp_mutex.h:700
SemaphoreBase(Uint32 initial_value)
Create a semaphore.
Definition SDL3pp_mutex.h:641
Handle to a non owned semaphore.
Definition SDL3pp_mutex.h:736
SemaphoreRef & operator=(SemaphoreRef other)
Assignment operator.
Definition SDL3pp_mutex.h:763
constexpr SemaphoreRef(SemaphoreRef &&other)
Move constructor.
Definition SDL3pp_mutex.h:750
void reset(SDL_Semaphore *newResource={})
Destroy a semaphore.
Definition SDL3pp_mutex.h:779
constexpr SemaphoreRef(const SemaphoreRef &other)
Copy constructor.
Definition SDL3pp_mutex.h:742
constexpr ~SemaphoreRef()=default
Default constructor.
Handle to an owned semaphore.
Definition SDL3pp_mutex.h:794
constexpr Semaphore(SDL_Semaphore *resource={})
Constructs from the underlying resource.
Definition SDL3pp_mutex.h:800
Semaphore & operator=(Semaphore other)
Assignment operator.
Definition SDL3pp_mutex.h:820
~Semaphore()
Frees up resource when object goes out of scope.
Definition SDL3pp_mutex.h:815
constexpr Semaphore(Semaphore &&other)=default
Move constructor.