4#include <SDL3/SDL_mutex.h>
5#include "SDL3pp_stdinc.h"
6#include "SDL3pp_thread.h"
209 using MutexBase::MutexBase;
225 :
Mutex(other.release())
289 :
Mutex(SDL_CreateMutex())
591 using RWLockBase::RWLockBase;
711 :
RWLock(SDL_CreateRWLock())
754 SDL_LockRWLockForReading(rwlock);
792 SDL_LockRWLockForWriting(rwlock);
824 return SDL_TryLockRWLockForReading(rwlock);
864 return SDL_TryLockRWLockForWriting(rwlock);
1050 using SemaphoreBase::SemaphoreBase;
1137 :
Semaphore(SDL_CreateSemaphore(initial_value))
1204 return SDL_TryWaitSemaphore(sem);
1231 return SDL_WaitSemaphoreTimeout(sem,
narrowS32(timeout.count()));
1268 return SDL_GetSemaphoreValue(sem);
1396 using ConditionBase::ConditionBase;
1515 SDL_BroadcastCondition(cond);
1548 SDL_WaitCondition(cond, mutex);
1588 return SDL_WaitConditionTimeout(cond, mutex,
narrowS32(timeout.count()));
1604 SDL_INIT_STATUS_UNINITIALIZED;
1607 SDL_INIT_STATUS_INITIALIZING;
1610 SDL_INIT_STATUS_INITIALIZED;
1613 SDL_INIT_STATUS_UNINITIALIZING;
1674 constexpr InitState()
1807 SDL_SetInitialized(state, initialized);
constexpr RawPointer release() noexcept
Definition SDL3pp_resource.h:57
friend constexpr void swap(ResourceBaseT &lhs, ResourceBaseT &rhs) noexcept
Definition SDL3pp_resource.h:65
constexpr RawPointer get() const noexcept
Definition SDL3pp_resource.h:54
constexpr ResourceBaseT()=default
Default constructor, creates null/invalid resource.
void Destroy()
Destroy a read/write lock created with CreateRWLock().
Definition SDL3pp_mutex.h:921
bool ShouldQuit(InitStateRaw *state)
Return whether cleanup should be done.
Definition SDL3pp_mutex.h:1784
void BroadcastCondition(ConditionRef cond)
Restart all threads that are waiting on the condition variable.
Definition SDL3pp_mutex.h:1513
constexpr InitStatus INIT_STATUS_UNINITIALIZING
INIT_STATUS_UNINITIALIZING.
Definition SDL3pp_mutex.h:1612
void Destroy()
Destroy a condition variable.
Definition SDL3pp_mutex.h:1481
Uint32 GetValue() const
Get the current value of a semaphore.
Definition SDL3pp_mutex.h:1271
Condition()
Create a condition variable.
Definition SDL3pp_mutex.h:1463
void Unlock()
Unlock the mutex.
Definition SDL3pp_mutex.h:368
constexpr InitStatus INIT_STATUS_INITIALIZING
INIT_STATUS_INITIALIZING.
Definition SDL3pp_mutex.h:1606
Mutex CreateMutex()
Create a new mutex.
Definition SDL3pp_mutex.h:286
bool TryLockForWriting()
Try to lock a read/write lock for writing without blocking.
Definition SDL3pp_mutex.h:867
constexpr InitStatus INIT_STATUS_UNINITIALIZED
INIT_STATUS_UNINITIALIZED.
Definition SDL3pp_mutex.h:1603
bool TryWait()
See if a semaphore has a positive value and decrement it if it does.
Definition SDL3pp_mutex.h:1207
void LockForWriting()
Lock the read/write lock for write operations.
Definition SDL3pp_mutex.h:795
Uint32 GetSemaphoreValue(SemaphoreRef sem)
Get the current value of a semaphore.
Definition SDL3pp_mutex.h:1266
bool TryLockRWLockForReading(RWLockRef rwlock)
Try to lock a read/write lock for reading without blocking.
Definition SDL3pp_mutex.h:822
void Destroy()
Destroy a mutex created with CreateMutex().
Definition SDL3pp_mutex.h:389
SDL_Semaphore * SemaphoreRaw
Alias to raw representation for Semaphore.
Definition SDL3pp_mutex.h:69
void UnlockRWLock(RWLockRef rwlock)
Unlock the read/write lock.
Definition SDL3pp_mutex.h:898
Condition CreateCondition()
Create a condition variable.
Definition SDL3pp_mutex.h:1461
void DestroyRWLock(RWLockRaw rwlock)
Destroy a read/write lock created with CreateRWLock().
Definition SDL3pp_mutex.h:919
bool ShouldInit(InitStateRaw *state)
Return whether initialization should be done.
Definition SDL3pp_mutex.h:1761
ResourceRefT< RWLockBase > RWLockRef
Reference for RWLock.
Definition SDL3pp_mutex.h:60
Mutex()
Create a new mutex.
Definition SDL3pp_mutex.h:288
void WaitSemaphore(SemaphoreRef sem)
Wait until a semaphore has a positive value and then decrements it.
Definition SDL3pp_mutex.h:1179
bool ShouldQuit()
Return whether cleanup should be done.
Definition SDL3pp_mutex.h:1786
void Wait()
Wait until a semaphore has a positive value and then decrements it.
Definition SDL3pp_mutex.h:1181
bool TryWaitSemaphore(SemaphoreRef sem)
See if a semaphore has a positive value and decrement it if it does.
Definition SDL3pp_mutex.h:1202
bool WaitTimeout(MutexRef mutex, Milliseconds timeout)
Wait until a condition variable is signaled or a certain time has passed.
Definition SDL3pp_mutex.h:1591
void Destroy()
Destroy a semaphore.
Definition SDL3pp_mutex.h:1157
void Signal()
Restart one of the threads that are waiting on the condition variable.
Definition SDL3pp_mutex.h:1498
bool TryLockForReading()
Try to lock a read/write lock for reading without blocking.
Definition SDL3pp_mutex.h:827
void DestroyMutex(MutexRaw mutex)
Destroy a mutex created with CreateMutex().
Definition SDL3pp_mutex.h:387
bool ShouldInit()
Return whether initialization should be done.
Definition SDL3pp_mutex.h:1763
ResourceRefT< ConditionBase > ConditionRef
Reference for Condition.
Definition SDL3pp_mutex.h:92
void Signal()
Atomically increment a semaphore's value and wake waiting threads.
Definition SDL3pp_mutex.h:1254
void LockRWLockForWriting(RWLockRef rwlock)
Lock the read/write lock for write operations.
Definition SDL3pp_mutex.h:790
bool TryLock()
Try to lock a mutex without blocking.
Definition SDL3pp_mutex.h:344
RWLock()
Create a new read/write lock.
Definition SDL3pp_mutex.h:710
bool TryLockRWLockForWriting(RWLockRef rwlock)
Try to lock a read/write lock for writing without blocking.
Definition SDL3pp_mutex.h:862
Semaphore CreateSemaphore(Uint32 initial_value)
Create a semaphore.
Definition SDL3pp_mutex.h:1131
ResourceRefT< MutexBase > MutexRef
Reference for Mutex.
Definition SDL3pp_mutex.h:44
void UnlockMutex(MutexRef mutex)
Unlock the mutex.
Definition SDL3pp_mutex.h:366
void LockMutex(MutexRef mutex)
Lock the mutex.
Definition SDL3pp_mutex.h:317
void SignalSemaphore(SemaphoreRef sem)
Atomically increment a semaphore's value and wake waiting threads.
Definition SDL3pp_mutex.h:1252
constexpr InitStatus INIT_STATUS_INITIALIZED
INIT_STATUS_INITIALIZED.
Definition SDL3pp_mutex.h:1609
SDL_Mutex * MutexRaw
Alias to raw representation for Mutex.
Definition SDL3pp_mutex.h:37
void Lock()
Lock the mutex.
Definition SDL3pp_mutex.h:319
bool WaitConditionTimeout(ConditionRef cond, MutexRef mutex, Milliseconds timeout)
Wait until a condition variable is signaled or a certain time has passed.
Definition SDL3pp_mutex.h:1584
SDL_Condition * ConditionRaw
Alias to raw representation for Condition.
Definition SDL3pp_mutex.h:85
RWLock CreateRWLock()
Create a new read/write lock.
Definition SDL3pp_mutex.h:708
void LockForReading()
Lock the read/write lock for read only operations.
Definition SDL3pp_mutex.h:757
bool TryLockMutex(MutexRef mutex)
Try to lock a mutex without blocking.
Definition SDL3pp_mutex.h:342
ResourceRefT< SemaphoreBase > SemaphoreRef
Reference for Semaphore.
Definition SDL3pp_mutex.h:76
SDL_InitState InitStateRaw
Alias to raw representation for InitState.
Definition SDL3pp_mutex.h:95
void DestroySemaphore(SemaphoreRaw sem)
Destroy a semaphore.
Definition SDL3pp_mutex.h:1155
void Broadcast()
Restart all threads that are waiting on the condition variable.
Definition SDL3pp_mutex.h:1518
void LockRWLockForReading(RWLockRef rwlock)
Lock the read/write lock for read only operations.
Definition SDL3pp_mutex.h:752
void SetInitialized(InitStateRaw *state, bool initialized)
Finish an initialization state transition.
Definition SDL3pp_mutex.h:1805
void DestroyCondition(ConditionRaw cond)
Destroy a condition variable.
Definition SDL3pp_mutex.h:1479
bool WaitSemaphoreTimeout(SemaphoreRef sem, Milliseconds timeout)
Wait until a semaphore has a positive value and then decrements it.
Definition SDL3pp_mutex.h:1229
SDL_InitStatus InitStatus
The current status of an InitState structure.
Definition SDL3pp_mutex.h:1601
void Wait(MutexRef mutex)
Wait until a condition variable is signaled.
Definition SDL3pp_mutex.h:1551
void Unlock()
Unlock the read/write lock.
Definition SDL3pp_mutex.h:900
bool WaitTimeout(Milliseconds timeout)
Wait until a semaphore has a positive value and then decrements it.
Definition SDL3pp_mutex.h:1234
void SetInitialized(bool initialized)
Finish an initialization state transition.
Definition SDL3pp_mutex.h:1810
SDL_RWLock * RWLockRaw
Alias to raw representation for RWLock.
Definition SDL3pp_mutex.h:53
void WaitCondition(ConditionRef cond, MutexRef mutex)
Wait until a condition variable is signaled.
Definition SDL3pp_mutex.h:1546
void SignalCondition(ConditionRef cond)
Restart one of the threads that are waiting on the condition variable.
Definition SDL3pp_mutex.h:1496
::Uint32 Uint32
An unsigned 32-bit integer type.
Definition SDL3pp_stdinc.h:296
std::chrono::milliseconds Milliseconds
Duration in Miliseconds (Uint32).
Definition SDL3pp_stdinc.h:341
Main include header for the SDL3pp library.
Sint32 narrowS32(T value)
Narrows to Sint32.
Definition SDL3pp_stdinc.h:6263
Base class to Condition.
Definition SDL3pp_mutex.h:1282
constexpr ResourceBaseT()=default
Default constructor, creates null/invalid resource.
A means to block multiple threads until a condition is satisfied.
Definition SDL3pp_mutex.h:1395
constexpr Condition(Condition &&other) noexcept
Move constructor.
Definition SDL3pp_mutex.h:1411
~Condition()
Destructor.
Definition SDL3pp_mutex.h:1435
constexpr Condition(ConditionRaw resource) noexcept
Constructs from raw Condition.
Definition SDL3pp_mutex.h:1405
constexpr Condition & operator=(Condition &&other) noexcept
Assignment operator.
Definition SDL3pp_mutex.h:1438
A structure used for thread-safe initialization and shutdown.
Definition SDL3pp_mutex.h:1673
Base class to Mutex.
Definition SDL3pp_mutex.h:106
constexpr ResourceBaseT()=default
Default constructor, creates null/invalid resource.
A means to serialize access to a resource between threads.
Definition SDL3pp_mutex.h:208
constexpr Mutex & operator=(Mutex &&other) noexcept
Assignment operator.
Definition SDL3pp_mutex.h:257
~Mutex()
Destructor.
Definition SDL3pp_mutex.h:254
constexpr Mutex(MutexRaw resource) noexcept
Constructs from raw Mutex.
Definition SDL3pp_mutex.h:218
constexpr Mutex(Mutex &&other) noexcept
Move constructor.
Definition SDL3pp_mutex.h:224
Base class to RWLock.
Definition SDL3pp_mutex.h:397
constexpr ResourceBaseT()=default
Default constructor, creates null/invalid resource.
A mutex that allows read-only threads to run in parallel.
Definition SDL3pp_mutex.h:590
~RWLock()
Destructor.
Definition SDL3pp_mutex.h:656
constexpr RWLock(RWLock &&other) noexcept
Move constructor.
Definition SDL3pp_mutex.h:606
constexpr RWLock & operator=(RWLock &&other) noexcept
Assignment operator.
Definition SDL3pp_mutex.h:659
constexpr RWLock(RWLockRaw resource) noexcept
Constructs from raw RWLock.
Definition SDL3pp_mutex.h:600
A non-owning reference wrapper for a given resource.
Definition SDL3pp_resource.h:93
Base class to Semaphore.
Definition SDL3pp_mutex.h:929
constexpr ResourceBaseT()=default
Default constructor, creates null/invalid resource.
A means to manage access to a resource, by count, between threads.
Definition SDL3pp_mutex.h:1049
constexpr Semaphore(SemaphoreRaw resource) noexcept
Constructs from raw Semaphore.
Definition SDL3pp_mutex.h:1059
constexpr Semaphore & operator=(Semaphore &&other) noexcept
Assignment operator.
Definition SDL3pp_mutex.h:1100
~Semaphore()
Destructor.
Definition SDL3pp_mutex.h:1097
constexpr Semaphore(Semaphore &&other) noexcept
Move constructor.
Definition SDL3pp_mutex.h:1065