SDL3pp
A slim C++ wrapper for SDL3
Loading...
Searching...
No Matches
SDL3pp_mutex.h
1#ifndef SDL3PP_MUTEX_H_
2#define SDL3PP_MUTEX_H_
3
4#include <SDL3/SDL_mutex.h>
5#include "SDL3pp_stdinc.h"
6#include "SDL3pp_thread.h"
7
8namespace SDL {
9
30// Forward decl
31struct Mutex;
32
34using MutexRaw = SDL_Mutex*;
35
36// Forward decl
37struct MutexRef;
38
41{
43
46 : value(value)
47 {
48 }
49
51 constexpr MutexParam(std::nullptr_t _ = nullptr)
52 : value(nullptr)
53 {
54 }
55
57 constexpr explicit operator bool() const { return !!value; }
58
60 constexpr auto operator<=>(const MutexParam& other) const = default;
61
63 constexpr operator MutexRaw() const { return value; }
64};
65
66// Forward decl
67struct RWLock;
68
70using RWLockRaw = SDL_RWLock*;
71
72// Forward decl
73struct RWLockRef;
74
77{
79
82 : value(value)
83 {
84 }
85
87 constexpr RWLockParam(std::nullptr_t _ = nullptr)
88 : value(nullptr)
89 {
90 }
91
93 constexpr explicit operator bool() const { return !!value; }
94
96 constexpr auto operator<=>(const RWLockParam& other) const = default;
97
99 constexpr operator RWLockRaw() const { return value; }
100};
101
102// Forward decl
103struct Semaphore;
104
106using SemaphoreRaw = SDL_Semaphore*;
107
108// Forward decl
109struct SemaphoreRef;
110
113{
115
118 : value(value)
119 {
120 }
121
123 constexpr SemaphoreParam(std::nullptr_t _ = nullptr)
124 : value(nullptr)
125 {
126 }
127
129 constexpr explicit operator bool() const { return !!value; }
130
132 constexpr auto operator<=>(const SemaphoreParam& other) const = default;
133
135 constexpr operator SemaphoreRaw() const { return value; }
136};
137
138// Forward decl
139struct Condition;
140
142using ConditionRaw = SDL_Condition*;
143
144// Forward decl
145struct ConditionRef;
146
149{
151
154 : value(value)
155 {
156 }
157
159 constexpr ConditionParam(std::nullptr_t _ = nullptr)
160 : value(nullptr)
161 {
162 }
163
165 constexpr explicit operator bool() const { return !!value; }
166
168 constexpr auto operator<=>(const ConditionParam& other) const = default;
169
171 constexpr operator ConditionRaw() const { return value; }
172};
173
175using InitStateRaw = SDL_InitState;
176
177// Forward decl
178struct InitState;
179
194class Mutex
195{
196 MutexRaw m_resource = nullptr;
197
198public:
206 constexpr explicit Mutex(const MutexRaw resource)
207 : m_resource(resource)
208 {
209 }
210
212 constexpr Mutex(const Mutex& other) = delete;
213
215 constexpr Mutex(Mutex&& other)
216 : Mutex(other.release())
217 {
218 }
219
220 constexpr Mutex(const MutexRef& other) = delete;
221
222 constexpr Mutex(MutexRef&& other) = delete;
223
245 : m_resource(SDL_CreateMutex())
246 {
247 }
248
250 ~Mutex() { SDL_DestroyMutex(m_resource); }
251
254 {
255 std::swap(m_resource, other.m_resource);
256 return *this;
257 }
258
260 constexpr MutexRaw get() const { return m_resource; }
261
263 constexpr MutexRaw release()
264 {
265 auto r = m_resource;
266 m_resource = nullptr;
267 return r;
268 }
269
271 constexpr auto operator<=>(const Mutex& other) const = default;
272
274 constexpr bool operator==(std::nullptr_t _) const { return !m_resource; }
275
277 constexpr explicit operator bool() const { return !!m_resource; }
278
280 constexpr operator MutexParam() const { return {m_resource}; }
281
296 void Destroy();
297
319 void Lock();
320
339 void TryLock();
340
357 void Unlock();
358};
359
362{
371 : Mutex(resource.value)
372 {
373 }
374
376 MutexRef(const MutexRef& other)
377 : Mutex(other.get())
378 {
379 }
380
383};
384
405inline Mutex CreateMutex() { return Mutex(); }
406
429inline void LockMutex(MutexParam mutex) { SDL_LockMutex(mutex); }
430
431inline void Mutex::Lock() { SDL::LockMutex(m_resource); }
432
452inline void TryLockMutex(MutexParam mutex)
453{
454 CheckError(SDL_TryLockMutex(mutex));
455}
456
457inline void Mutex::TryLock() { SDL::TryLockMutex(m_resource); }
458
476inline void UnlockMutex(MutexParam mutex) { SDL_UnlockMutex(mutex); }
477
478inline void Mutex::Unlock() { SDL::UnlockMutex(m_resource); }
479
495inline void DestroyMutex(MutexRaw mutex) { SDL_DestroyMutex(mutex); }
496
498
520{
521 RWLockRaw m_resource = nullptr;
522
523public:
531 constexpr explicit RWLock(const RWLockRaw resource)
532 : m_resource(resource)
533 {
534 }
535
537 constexpr RWLock(const RWLock& other) = delete;
538
540 constexpr RWLock(RWLock&& other)
541 : RWLock(other.release())
542 {
543 }
544
545 constexpr RWLock(const RWLockRef& other) = delete;
546
547 constexpr RWLock(RWLockRef&& other) = delete;
548
590 : m_resource(SDL_CreateRWLock())
591 {
592 }
593
595 ~RWLock() { SDL_DestroyRWLock(m_resource); }
596
599 {
600 std::swap(m_resource, other.m_resource);
601 return *this;
602 }
603
605 constexpr RWLockRaw get() const { return m_resource; }
606
608 constexpr RWLockRaw release()
609 {
610 auto r = m_resource;
611 m_resource = nullptr;
612 return r;
613 }
614
616 constexpr auto operator<=>(const RWLock& other) const = default;
617
619 constexpr bool operator==(std::nullptr_t _) const { return !m_resource; }
620
622 constexpr explicit operator bool() const { return !!m_resource; }
623
625 constexpr operator RWLockParam() const { return {m_resource}; }
626
641 void Destroy();
642
677 void LockForReading();
678
707 void LockForWriting();
708
731 void TryLockForReading();
732
760 void TryLockForWriting();
761
784 void Unlock();
785};
786
789{
798 : RWLock(resource.value)
799 {
800 }
801
803 RWLockRef(const RWLockRef& other)
804 : RWLock(other.get())
805 {
806 }
807
810};
811
852inline RWLock CreateRWLock() { return RWLock(); }
853
890{
891 SDL_LockRWLockForReading(rwlock);
892}
893
895
926{
927 SDL_LockRWLockForWriting(rwlock);
928}
929
931
956{
957 CheckError(SDL_TryLockRWLockForReading(rwlock));
958}
959
961{
963}
964
994{
995 CheckError(SDL_TryLockRWLockForWriting(rwlock));
996}
997
999{
1000 SDL::TryLockRWLockForWriting(m_resource);
1001}
1002
1026inline void UnlockRWLock(RWLockParam rwlock) { SDL_UnlockRWLock(rwlock); }
1027
1028inline void RWLock::Unlock() { SDL::UnlockRWLock(m_resource); }
1029
1045inline void DestroyRWLock(RWLockRaw rwlock) { SDL_DestroyRWLock(rwlock); }
1046
1048
1066{
1067 SemaphoreRaw m_resource = nullptr;
1068
1069public:
1071 constexpr Semaphore() = default;
1072
1080 constexpr explicit Semaphore(const SemaphoreRaw resource)
1081 : m_resource(resource)
1082 {
1083 }
1084
1086 constexpr Semaphore(const Semaphore& other) = delete;
1087
1089 constexpr Semaphore(Semaphore&& other)
1090 : Semaphore(other.release())
1091 {
1092 }
1093
1094 constexpr Semaphore(const SemaphoreRef& other) = delete;
1095
1096 constexpr Semaphore(SemaphoreRef&& other) = delete;
1097
1120 Semaphore(Uint32 initial_value)
1121 : m_resource(SDL_CreateSemaphore(initial_value))
1122 {
1123 }
1124
1126 ~Semaphore() { SDL_DestroySemaphore(m_resource); }
1127
1130 {
1131 std::swap(m_resource, other.m_resource);
1132 return *this;
1133 }
1134
1136 constexpr SemaphoreRaw get() const { return m_resource; }
1137
1140 {
1141 auto r = m_resource;
1142 m_resource = nullptr;
1143 return r;
1144 }
1145
1147 constexpr auto operator<=>(const Semaphore& other) const = default;
1148
1150 constexpr bool operator==(std::nullptr_t _) const { return !m_resource; }
1151
1153 constexpr explicit operator bool() const { return !!m_resource; }
1154
1156 constexpr operator SemaphoreParam() const { return {m_resource}; }
1157
1169 void Destroy();
1170
1188 void Wait();
1189
1206 bool TryWait();
1207
1225 bool WaitTimeout(std::chrono::milliseconds timeout);
1226
1237 void Signal();
1238
1246 Uint32 GetValue() const;
1247};
1248
1251{
1260 : Semaphore(resource.value)
1261 {
1262 }
1263
1266 : Semaphore(other.get())
1267 {
1268 }
1269
1272};
1273
1296inline Semaphore CreateSemaphore(Uint32 initial_value)
1297{
1298 return Semaphore(initial_value);
1299}
1300
1313inline void DestroySemaphore(SemaphoreRaw sem) { SDL_DestroySemaphore(sem); }
1314
1316
1335inline void WaitSemaphore(SemaphoreParam sem) { SDL_WaitSemaphore(sem); }
1336
1337inline void Semaphore::Wait() { SDL::WaitSemaphore(m_resource); }
1338
1357{
1358 return SDL_TryWaitSemaphore(sem);
1359}
1360
1361inline bool Semaphore::TryWait() { return SDL::TryWaitSemaphore(m_resource); }
1362
1382 std::chrono::milliseconds timeout)
1383{
1384 return SDL_WaitSemaphoreTimeout(sem, timeout.count());
1385}
1386
1387inline bool Semaphore::WaitTimeout(std::chrono::milliseconds timeout)
1388{
1389 return SDL::WaitSemaphoreTimeout(m_resource, timeout);
1390}
1391
1403inline void SignalSemaphore(SemaphoreParam sem) { SDL_SignalSemaphore(sem); }
1404
1405inline void Semaphore::Signal() { SDL::SignalSemaphore(m_resource); }
1406
1416{
1417 return SDL_GetSemaphoreValue(sem);
1418}
1419
1421{
1422 return SDL::GetSemaphoreValue(m_resource);
1423}
1424
1441{
1442 ConditionRaw m_resource = nullptr;
1443
1444public:
1452 constexpr explicit Condition(const ConditionRaw resource)
1453 : m_resource(resource)
1454 {
1455 }
1456
1458 constexpr Condition(const Condition& other) = delete;
1459
1461 constexpr Condition(Condition&& other)
1462 : Condition(other.release())
1463 {
1464 }
1465
1466 constexpr Condition(const ConditionRef& other) = delete;
1467
1468 constexpr Condition(ConditionRef&& other) = delete;
1469
1485 : m_resource(SDL_CreateCondition())
1486 {
1487 }
1488
1490 ~Condition() { SDL_DestroyCondition(m_resource); }
1491
1494 {
1495 std::swap(m_resource, other.m_resource);
1496 return *this;
1497 }
1498
1500 constexpr ConditionRaw get() const { return m_resource; }
1501
1504 {
1505 auto r = m_resource;
1506 m_resource = nullptr;
1507 return r;
1508 }
1509
1511 constexpr auto operator<=>(const Condition& other) const = default;
1512
1514 constexpr bool operator==(std::nullptr_t _) const { return !m_resource; }
1515
1517 constexpr explicit operator bool() const { return !!m_resource; }
1518
1520 constexpr operator ConditionParam() const { return {m_resource}; }
1521
1530 void Destroy();
1531
1544 void Signal();
1545
1558 void Broadcast();
1559
1585 void Wait(MutexParam mutex);
1586
1614 bool WaitTimeout(MutexParam mutex, std::chrono::milliseconds timeout);
1615};
1616
1619{
1628 : Condition(resource.value)
1629 {
1630 }
1631
1634 : Condition(other.get())
1635 {
1636 }
1637
1640};
1641
1657
1667inline void DestroyCondition(ConditionRaw cond) { SDL_DestroyCondition(cond); }
1668
1670
1684inline void SignalCondition(ConditionParam cond) { SDL_SignalCondition(cond); }
1685
1686inline void Condition::Signal() { SDL::SignalCondition(m_resource); }
1687
1702{
1703 SDL_BroadcastCondition(cond);
1704}
1705
1706inline void Condition::Broadcast() { SDL::BroadcastCondition(m_resource); }
1707
1735{
1736 SDL_WaitCondition(cond, mutex);
1737}
1738
1739inline void Condition::Wait(MutexParam mutex)
1740{
1741 SDL::WaitCondition(m_resource, mutex);
1742}
1743
1773 MutexParam mutex,
1774 std::chrono::milliseconds timeout)
1775{
1776 return SDL_WaitConditionTimeout(cond, mutex, timeout.count());
1777}
1778
1780 std::chrono::milliseconds timeout)
1781{
1782 return SDL::WaitConditionTimeout(m_resource, mutex, timeout);
1783}
1784
1790using InitStatus = SDL_InitStatus;
1791
1793 SDL_INIT_STATUS_UNINITIALIZED;
1794
1796 SDL_INIT_STATUS_INITIALIZING;
1797
1799 SDL_INIT_STATUS_INITIALIZED;
1800
1802 SDL_INIT_STATUS_UNINITIALIZING;
1803
1863{
1864 constexpr InitState()
1865 : SDL_InitState{0}
1866 {
1867 }
1868
1889 bool ShouldInit();
1890
1909 bool ShouldQuit();
1910
1927 void SetInitialized(bool initialized);
1928};
1929
1951inline bool ShouldInit(InitStateRaw* state) { return SDL_ShouldInit(state); }
1952
1953inline bool InitState::ShouldInit() { return SDL::ShouldInit(this); }
1954
1974inline bool ShouldQuit(InitStateRaw* state) { return SDL_ShouldQuit(state); }
1975
1976inline bool InitState::ShouldQuit() { return SDL::ShouldQuit(this); }
1977
1995inline void SetInitialized(InitStateRaw* state, bool initialized)
1996{
1997 SDL_SetInitialized(state, initialized);
1998}
1999
2000inline void InitState::SetInitialized(bool initialized)
2001{
2002 SDL::SetInitialized(this, initialized);
2003}
2004
2006
2007} // namespace SDL
2008
2009#endif /* SDL3PP_MUTEX_H_ */
A means to block multiple threads until a condition is satisfied.
Definition: SDL3pp_mutex.h:1441
constexpr ConditionRaw release()
Retrieves underlying ConditionRaw and clear this.
Definition: SDL3pp_mutex.h:1503
Condition()
Create a condition variable.
Definition: SDL3pp_mutex.h:1484
Condition & operator=(Condition other)
Assignment operator.
Definition: SDL3pp_mutex.h:1493
~Condition()
Destructor.
Definition: SDL3pp_mutex.h:1490
constexpr auto operator<=>(const Condition &other) const =default
Comparison.
constexpr Condition(const Condition &other)=delete
Copy constructor.
constexpr Condition(Condition &&other)
Move constructor.
Definition: SDL3pp_mutex.h:1461
constexpr ConditionRaw get() const
Retrieves underlying ConditionRaw.
Definition: SDL3pp_mutex.h:1500
constexpr Condition(const ConditionRaw resource)
Constructs from ConditionParam.
Definition: SDL3pp_mutex.h:1452
constexpr bool operator==(std::nullptr_t _) const
Comparison.
Definition: SDL3pp_mutex.h:1514
A means to serialize access to a resource between threads.
Definition: SDL3pp_mutex.h:195
constexpr MutexRaw release()
Retrieves underlying MutexRaw and clear this.
Definition: SDL3pp_mutex.h:263
~Mutex()
Destructor.
Definition: SDL3pp_mutex.h:250
Mutex & operator=(Mutex other)
Assignment operator.
Definition: SDL3pp_mutex.h:253
Mutex()
Create a new mutex.
Definition: SDL3pp_mutex.h:244
constexpr bool operator==(std::nullptr_t _) const
Comparison.
Definition: SDL3pp_mutex.h:274
constexpr auto operator<=>(const Mutex &other) const =default
Comparison.
constexpr Mutex(const Mutex &other)=delete
Copy constructor.
constexpr Mutex(Mutex &&other)
Move constructor.
Definition: SDL3pp_mutex.h:215
constexpr Mutex(const MutexRaw resource)
Constructs from MutexParam.
Definition: SDL3pp_mutex.h:206
constexpr MutexRaw get() const
Retrieves underlying MutexRaw.
Definition: SDL3pp_mutex.h:260
A mutex that allows read-only threads to run in parallel.
Definition: SDL3pp_mutex.h:520
constexpr RWLock(RWLock &&other)
Move constructor.
Definition: SDL3pp_mutex.h:540
constexpr RWLockRaw release()
Retrieves underlying RWLockRaw and clear this.
Definition: SDL3pp_mutex.h:608
~RWLock()
Destructor.
Definition: SDL3pp_mutex.h:595
constexpr RWLock(const RWLockRaw resource)
Constructs from RWLockParam.
Definition: SDL3pp_mutex.h:531
constexpr RWLockRaw get() const
Retrieves underlying RWLockRaw.
Definition: SDL3pp_mutex.h:605
RWLock()
Create a new read/write lock.
Definition: SDL3pp_mutex.h:589
constexpr auto operator<=>(const RWLock &other) const =default
Comparison.
constexpr bool operator==(std::nullptr_t _) const
Comparison.
Definition: SDL3pp_mutex.h:619
constexpr RWLock(const RWLock &other)=delete
Copy constructor.
RWLock & operator=(RWLock other)
Assignment operator.
Definition: SDL3pp_mutex.h:598
A means to manage access to a resource, by count, between threads.
Definition: SDL3pp_mutex.h:1066
constexpr Semaphore()=default
Default ctor.
Semaphore & operator=(Semaphore other)
Assignment operator.
Definition: SDL3pp_mutex.h:1129
constexpr auto operator<=>(const Semaphore &other) const =default
Comparison.
~Semaphore()
Destructor.
Definition: SDL3pp_mutex.h:1126
constexpr Semaphore(Semaphore &&other)
Move constructor.
Definition: SDL3pp_mutex.h:1089
constexpr SemaphoreRaw release()
Retrieves underlying SemaphoreRaw and clear this.
Definition: SDL3pp_mutex.h:1139
Semaphore(Uint32 initial_value)
Create a semaphore.
Definition: SDL3pp_mutex.h:1120
constexpr Semaphore(const Semaphore &other)=delete
Copy constructor.
constexpr bool operator==(std::nullptr_t _) const
Comparison.
Definition: SDL3pp_mutex.h:1150
constexpr SemaphoreRaw get() const
Retrieves underlying SemaphoreRaw.
Definition: SDL3pp_mutex.h:1136
constexpr Semaphore(const SemaphoreRaw resource)
Constructs from SemaphoreParam.
Definition: SDL3pp_mutex.h:1080
constexpr void CheckError(bool result)
Check and throw if returned value from SDL is an error.
Definition: SDL3pp_error.h:198
bool ShouldQuit(InitStateRaw *state)
Return whether cleanup should be done.
Definition: SDL3pp_mutex.h:1974
Uint32 GetSemaphoreValue(SemaphoreParam sem)
Get the current value of a semaphore.
Definition: SDL3pp_mutex.h:1415
constexpr InitStatus INIT_STATUS_UNINITIALIZING
INIT_STATUS_UNINITIALIZING.
Definition: SDL3pp_mutex.h:1801
void Unlock()
Unlock the read/write lock.
Definition: SDL3pp_mutex.h:1028
void LockMutex(MutexParam mutex)
Lock the mutex.
Definition: SDL3pp_mutex.h:429
bool TryWaitSemaphore(SemaphoreParam sem)
See if a semaphore has a positive value and decrement it if it does.
Definition: SDL3pp_mutex.h:1356
void TryLockForWriting()
Try to lock a read/write lock for writing without blocking.
Definition: SDL3pp_mutex.h:998
void Wait(MutexParam mutex)
Wait until a condition variable is signaled.
Definition: SDL3pp_mutex.h:1739
constexpr InitStatus INIT_STATUS_INITIALIZING
INIT_STATUS_INITIALIZING.
Definition: SDL3pp_mutex.h:1795
void Signal()
Restart one of the threads that are waiting on the condition variable.
Definition: SDL3pp_mutex.h:1686
Mutex CreateMutex()
Create a new mutex.
Definition: SDL3pp_mutex.h:405
constexpr InitStatus INIT_STATUS_UNINITIALIZED
INIT_STATUS_UNINITIALIZED.
Definition: SDL3pp_mutex.h:1792
void SignalSemaphore(SemaphoreParam sem)
Atomically increment a semaphore's value and wake waiting threads.
Definition: SDL3pp_mutex.h:1403
bool TryWait()
See if a semaphore has a positive value and decrement it if it does.
Definition: SDL3pp_mutex.h:1361
void TryLockRWLockForReading(RWLockParam rwlock)
Try to lock a read/write lock for reading without blocking.
Definition: SDL3pp_mutex.h:955
SDL_RWLock * RWLockRaw
Alias to raw representation for RWLock.
Definition: SDL3pp_mutex.h:70
bool WaitSemaphoreTimeout(SemaphoreParam sem, std::chrono::milliseconds timeout)
Wait until a semaphore has a positive value and then decrements it.
Definition: SDL3pp_mutex.h:1381
void Destroy()
Destroy a mutex created with Mutex.Mutex().
Definition: SDL3pp_mutex.h:497
SDL_InitState InitStateRaw
Alias to raw representation for InitState.
Definition: SDL3pp_mutex.h:175
void TryLock()
Try to lock a mutex without blocking.
Definition: SDL3pp_mutex.h:457
void Unlock()
Unlock the mutex.
Definition: SDL3pp_mutex.h:478
void UnlockMutex(MutexParam mutex)
Unlock the mutex.
Definition: SDL3pp_mutex.h:476
SDL_InitStatus InitStatus
The current status of an InitState structure.
Definition: SDL3pp_mutex.h:1790
Condition CreateCondition()
Create a condition variable.
Definition: SDL3pp_mutex.h:1656
void DestroyRWLock(RWLockRaw rwlock)
Destroy a read/write lock created with RWLock.RWLock().
Definition: SDL3pp_mutex.h:1045
bool ShouldInit(InitStateRaw *state)
Return whether initialization should be done.
Definition: SDL3pp_mutex.h:1951
void BroadcastCondition(ConditionParam cond)
Restart all threads that are waiting on the condition variable.
Definition: SDL3pp_mutex.h:1701
SDL_Condition * ConditionRaw
Alias to raw representation for Condition.
Definition: SDL3pp_mutex.h:142
bool ShouldQuit()
Return whether cleanup should be done.
Definition: SDL3pp_mutex.h:1976
void LockForReading()
Lock the read/write lock for read only operations.
Definition: SDL3pp_mutex.h:894
SDL_Semaphore * SemaphoreRaw
Alias to raw representation for Semaphore.
Definition: SDL3pp_mutex.h:106
Uint32 GetValue() const
Get the current value of a semaphore.
Definition: SDL3pp_mutex.h:1420
void UnlockRWLock(RWLockParam rwlock)
Unlock the read/write lock.
Definition: SDL3pp_mutex.h:1026
void TryLockMutex(MutexParam mutex)
Try to lock a mutex without blocking.
Definition: SDL3pp_mutex.h:452
void DestroyMutex(MutexRaw mutex)
Destroy a mutex created with Mutex.Mutex().
Definition: SDL3pp_mutex.h:495
bool ShouldInit()
Return whether initialization should be done.
Definition: SDL3pp_mutex.h:1953
bool WaitTimeout(std::chrono::milliseconds timeout)
Wait until a semaphore has a positive value and then decrements it.
Definition: SDL3pp_mutex.h:1387
void SignalCondition(ConditionParam cond)
Restart one of the threads that are waiting on the condition variable.
Definition: SDL3pp_mutex.h:1684
Semaphore CreateSemaphore(Uint32 initial_value)
Create a semaphore.
Definition: SDL3pp_mutex.h:1296
void LockRWLockForWriting(RWLockParam rwlock)
Lock the read/write lock for write operations.
Definition: SDL3pp_mutex.h:925
void Wait()
Wait until a semaphore has a positive value and then decrements it.
Definition: SDL3pp_mutex.h:1337
constexpr InitStatus INIT_STATUS_INITIALIZED
INIT_STATUS_INITIALIZED.
Definition: SDL3pp_mutex.h:1798
void Lock()
Lock the mutex.
Definition: SDL3pp_mutex.h:431
void Destroy()
Destroy a semaphore.
Definition: SDL3pp_mutex.h:1315
void Broadcast()
Restart all threads that are waiting on the condition variable.
Definition: SDL3pp_mutex.h:1706
bool WaitTimeout(MutexParam mutex, std::chrono::milliseconds timeout)
Wait until a condition variable is signaled or a certain time has passed.
Definition: SDL3pp_mutex.h:1779
void Signal()
Atomically increment a semaphore's value and wake waiting threads.
Definition: SDL3pp_mutex.h:1405
RWLock CreateRWLock()
Create a new read/write lock.
Definition: SDL3pp_mutex.h:852
SDL_Mutex * MutexRaw
Alias to raw representation for Mutex.
Definition: SDL3pp_mutex.h:34
void TryLockRWLockForWriting(RWLockParam rwlock)
Try to lock a read/write lock for writing without blocking.
Definition: SDL3pp_mutex.h:993
void DestroySemaphore(SemaphoreRaw sem)
Destroy a semaphore.
Definition: SDL3pp_mutex.h:1313
void LockForWriting()
Lock the read/write lock for write operations.
Definition: SDL3pp_mutex.h:930
void Destroy()
Destroy a read/write lock created with RWLock.RWLock().
Definition: SDL3pp_mutex.h:1047
bool WaitConditionTimeout(ConditionParam cond, MutexParam mutex, std::chrono::milliseconds timeout)
Wait until a condition variable is signaled or a certain time has passed.
Definition: SDL3pp_mutex.h:1772
void SetInitialized(InitStateRaw *state, bool initialized)
Finish an initialization state transition.
Definition: SDL3pp_mutex.h:1995
void TryLockForReading()
Try to lock a read/write lock for reading without blocking.
Definition: SDL3pp_mutex.h:960
void DestroyCondition(ConditionRaw cond)
Destroy a condition variable.
Definition: SDL3pp_mutex.h:1667
void Destroy()
Destroy a condition variable.
Definition: SDL3pp_mutex.h:1669
void LockRWLockForReading(RWLockParam rwlock)
Lock the read/write lock for read only operations.
Definition: SDL3pp_mutex.h:889
void WaitCondition(ConditionParam cond, MutexParam mutex)
Wait until a condition variable is signaled.
Definition: SDL3pp_mutex.h:1734
void SetInitialized(bool initialized)
Finish an initialization state transition.
Definition: SDL3pp_mutex.h:2000
void WaitSemaphore(SemaphoreParam sem)
Wait until a semaphore has a positive value and then decrements it.
Definition: SDL3pp_mutex.h:1335
Uint32 Uint32
An unsigned 32-bit integer type.
Definition: SDL3pp_stdinc.h:328
Main include header for the SDL3pp library.
Safely wrap Condition for non owning parameters.
Definition: SDL3pp_mutex.h:149
ConditionRaw value
parameter's ConditionRaw
Definition: SDL3pp_mutex.h:150
constexpr ConditionParam(std::nullptr_t _=nullptr)
Constructs null/invalid.
Definition: SDL3pp_mutex.h:159
constexpr ConditionParam(ConditionRaw value)
Constructs from ConditionRaw.
Definition: SDL3pp_mutex.h:153
constexpr auto operator<=>(const ConditionParam &other) const =default
Comparison.
Semi-safe reference for Condition.
Definition: SDL3pp_mutex.h:1619
ConditionRef(const ConditionRef &other)
Copy constructor.
Definition: SDL3pp_mutex.h:1633
ConditionRef(ConditionParam resource)
Constructs from ConditionParam.
Definition: SDL3pp_mutex.h:1627
~ConditionRef()
Destructor.
Definition: SDL3pp_mutex.h:1639
A structure used for thread-safe initialization and shutdown.
Definition: SDL3pp_mutex.h:1863
Safely wrap Mutex for non owning parameters.
Definition: SDL3pp_mutex.h:41
MutexRaw value
parameter's MutexRaw
Definition: SDL3pp_mutex.h:42
constexpr MutexParam(std::nullptr_t _=nullptr)
Constructs null/invalid.
Definition: SDL3pp_mutex.h:51
constexpr auto operator<=>(const MutexParam &other) const =default
Comparison.
constexpr MutexParam(MutexRaw value)
Constructs from MutexRaw.
Definition: SDL3pp_mutex.h:45
Semi-safe reference for Mutex.
Definition: SDL3pp_mutex.h:362
MutexRef(MutexParam resource)
Constructs from MutexParam.
Definition: SDL3pp_mutex.h:370
MutexRef(const MutexRef &other)
Copy constructor.
Definition: SDL3pp_mutex.h:376
~MutexRef()
Destructor.
Definition: SDL3pp_mutex.h:382
Safely wrap RWLock for non owning parameters.
Definition: SDL3pp_mutex.h:77
constexpr RWLockParam(std::nullptr_t _=nullptr)
Constructs null/invalid.
Definition: SDL3pp_mutex.h:87
RWLockRaw value
parameter's RWLockRaw
Definition: SDL3pp_mutex.h:78
constexpr auto operator<=>(const RWLockParam &other) const =default
Comparison.
constexpr RWLockParam(RWLockRaw value)
Constructs from RWLockRaw.
Definition: SDL3pp_mutex.h:81
Semi-safe reference for RWLock.
Definition: SDL3pp_mutex.h:789
RWLockRef(const RWLockRef &other)
Copy constructor.
Definition: SDL3pp_mutex.h:803
~RWLockRef()
Destructor.
Definition: SDL3pp_mutex.h:809
RWLockRef(RWLockParam resource)
Constructs from RWLockParam.
Definition: SDL3pp_mutex.h:797
Safely wrap Semaphore for non owning parameters.
Definition: SDL3pp_mutex.h:113
constexpr SemaphoreParam(std::nullptr_t _=nullptr)
Constructs null/invalid.
Definition: SDL3pp_mutex.h:123
SemaphoreRaw value
parameter's SemaphoreRaw
Definition: SDL3pp_mutex.h:114
constexpr SemaphoreParam(SemaphoreRaw value)
Constructs from SemaphoreRaw.
Definition: SDL3pp_mutex.h:117
constexpr auto operator<=>(const SemaphoreParam &other) const =default
Comparison.
Semi-safe reference for Semaphore.
Definition: SDL3pp_mutex.h:1251
SemaphoreRef(SemaphoreParam resource)
Constructs from SemaphoreParam.
Definition: SDL3pp_mutex.h:1259
~SemaphoreRef()
Destructor.
Definition: SDL3pp_mutex.h:1271
SemaphoreRef(const SemaphoreRef &other)
Copy constructor.
Definition: SDL3pp_mutex.h:1265