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:
200 constexpr Mutex(std::nullptr_t) noexcept
201 : m_resource(0)
202 {
203 }
204
212 constexpr explicit Mutex(const MutexRaw resource) noexcept
213 : m_resource(resource)
214 {
215 }
216
218 constexpr Mutex(const Mutex& other) = delete;
219
221 constexpr Mutex(Mutex&& other) noexcept
222 : Mutex(other.release())
223 {
224 }
225
226 constexpr Mutex(const MutexRef& other) = delete;
227
228 constexpr Mutex(MutexRef&& other) = delete;
229
251 : m_resource(SDL_CreateMutex())
252 {
253 }
254
256 ~Mutex() { SDL_DestroyMutex(m_resource); }
257
259 constexpr Mutex& operator=(Mutex&& other) noexcept
260 {
261 std::swap(m_resource, other.m_resource);
262 return *this;
263 }
264
265protected:
267 constexpr Mutex& operator=(const Mutex& other) noexcept = default;
268
269public:
271 constexpr MutexRaw get() const noexcept { return m_resource; }
272
274 constexpr MutexRaw release() noexcept
275 {
276 auto r = m_resource;
277 m_resource = nullptr;
278 return r;
279 }
280
282 constexpr auto operator<=>(const Mutex& other) const noexcept = default;
283
285 constexpr explicit operator bool() const noexcept { return !!m_resource; }
286
288 constexpr operator MutexParam() const noexcept { return {m_resource}; }
289
303 void Destroy();
304
325 void Lock();
326
345 void TryLock();
346
362 void Unlock();
363};
364
367{
368 using Mutex::Mutex;
369
377 MutexRef(MutexParam resource) noexcept
378 : Mutex(resource.value)
379 {
380 }
381
389 MutexRef(MutexRaw resource) noexcept
390 : Mutex(resource)
391 {
392 }
393
395 MutexRef(const MutexRef& other) noexcept
396 : Mutex(other.get())
397 {
398 }
399
402};
403
424inline Mutex CreateMutex() { return Mutex(); }
425
448inline void LockMutex(MutexParam mutex) { SDL_LockMutex(mutex); }
449
450inline void Mutex::Lock() { SDL::LockMutex(m_resource); }
451
471inline void TryLockMutex(MutexParam mutex)
472{
473 CheckError(SDL_TryLockMutex(mutex));
474}
475
476inline void Mutex::TryLock() { SDL::TryLockMutex(m_resource); }
477
495inline void UnlockMutex(MutexParam mutex) { SDL_UnlockMutex(mutex); }
496
497inline void Mutex::Unlock() { SDL::UnlockMutex(m_resource); }
498
514inline void DestroyMutex(MutexRaw mutex) { SDL_DestroyMutex(mutex); }
515
517
539{
540 RWLockRaw m_resource = nullptr;
541
542public:
544 constexpr RWLock(std::nullptr_t) noexcept
545 : m_resource(0)
546 {
547 }
548
556 constexpr explicit RWLock(const RWLockRaw resource) noexcept
557 : m_resource(resource)
558 {
559 }
560
562 constexpr RWLock(const RWLock& other) = delete;
563
565 constexpr RWLock(RWLock&& other) noexcept
566 : RWLock(other.release())
567 {
568 }
569
570 constexpr RWLock(const RWLockRef& other) = delete;
571
572 constexpr RWLock(RWLockRef&& other) = delete;
573
615 : m_resource(SDL_CreateRWLock())
616 {
617 }
618
620 ~RWLock() { SDL_DestroyRWLock(m_resource); }
621
623 constexpr RWLock& operator=(RWLock&& other) noexcept
624 {
625 std::swap(m_resource, other.m_resource);
626 return *this;
627 }
628
629protected:
631 constexpr RWLock& operator=(const RWLock& other) noexcept = default;
632
633public:
635 constexpr RWLockRaw get() const noexcept { return m_resource; }
636
638 constexpr RWLockRaw release() noexcept
639 {
640 auto r = m_resource;
641 m_resource = nullptr;
642 return r;
643 }
644
646 constexpr auto operator<=>(const RWLock& other) const noexcept = default;
647
649 constexpr explicit operator bool() const noexcept { return !!m_resource; }
650
652 constexpr operator RWLockParam() const noexcept { return {m_resource}; }
653
667 void Destroy();
668
702 void LockForReading();
703
731 void LockForWriting();
732
755 void TryLockForReading();
756
784 void TryLockForWriting();
785
807 void Unlock();
808};
809
812{
813 using RWLock::RWLock;
814
822 RWLockRef(RWLockParam resource) noexcept
823 : RWLock(resource.value)
824 {
825 }
826
834 RWLockRef(RWLockRaw resource) noexcept
835 : RWLock(resource)
836 {
837 }
838
840 RWLockRef(const RWLockRef& other) noexcept
841 : RWLock(other.get())
842 {
843 }
844
847};
848
889inline RWLock CreateRWLock() { return RWLock(); }
890
927{
928 SDL_LockRWLockForReading(rwlock);
929}
930
932
963{
964 SDL_LockRWLockForWriting(rwlock);
965}
966
968
993{
994 CheckError(SDL_TryLockRWLockForReading(rwlock));
995}
996
998{
1000}
1001
1031{
1032 CheckError(SDL_TryLockRWLockForWriting(rwlock));
1033}
1034
1036{
1037 SDL::TryLockRWLockForWriting(m_resource);
1038}
1039
1063inline void UnlockRWLock(RWLockParam rwlock) { SDL_UnlockRWLock(rwlock); }
1064
1065inline void RWLock::Unlock() { SDL::UnlockRWLock(m_resource); }
1066
1082inline void DestroyRWLock(RWLockRaw rwlock) { SDL_DestroyRWLock(rwlock); }
1083
1085
1103{
1104 SemaphoreRaw m_resource = nullptr;
1105
1106public:
1108 constexpr Semaphore(std::nullptr_t = nullptr) noexcept
1109 : m_resource(0)
1110 {
1111 }
1112
1120 constexpr explicit Semaphore(const SemaphoreRaw resource) noexcept
1121 : m_resource(resource)
1122 {
1123 }
1124
1126 constexpr Semaphore(const Semaphore& other) = delete;
1127
1129 constexpr Semaphore(Semaphore&& other) noexcept
1130 : Semaphore(other.release())
1131 {
1132 }
1133
1134 constexpr Semaphore(const SemaphoreRef& other) = delete;
1135
1136 constexpr Semaphore(SemaphoreRef&& other) = delete;
1137
1160 Semaphore(Uint32 initial_value)
1161 : m_resource(SDL_CreateSemaphore(initial_value))
1162 {
1163 }
1164
1166 ~Semaphore() { SDL_DestroySemaphore(m_resource); }
1167
1169 constexpr Semaphore& operator=(Semaphore&& other) noexcept
1170 {
1171 std::swap(m_resource, other.m_resource);
1172 return *this;
1173 }
1174
1175protected:
1177 constexpr Semaphore& operator=(const Semaphore& other) noexcept = default;
1178
1179public:
1181 constexpr SemaphoreRaw get() const noexcept { return m_resource; }
1182
1184 constexpr SemaphoreRaw release() noexcept
1185 {
1186 auto r = m_resource;
1187 m_resource = nullptr;
1188 return r;
1189 }
1190
1192 constexpr auto operator<=>(const Semaphore& other) const noexcept = default;
1193
1195 constexpr explicit operator bool() const noexcept { return !!m_resource; }
1196
1198 constexpr operator SemaphoreParam() const noexcept { return {m_resource}; }
1199
1210 void Destroy();
1211
1228 void Wait();
1229
1246 bool TryWait();
1247
1265 bool WaitTimeout(std::chrono::milliseconds timeout);
1266
1276 void Signal();
1277
1285 Uint32 GetValue() const;
1286};
1287
1290{
1292
1300 SemaphoreRef(SemaphoreParam resource) noexcept
1301 : Semaphore(resource.value)
1302 {
1303 }
1304
1312 SemaphoreRef(SemaphoreRaw resource) noexcept
1313 : Semaphore(resource)
1314 {
1315 }
1316
1318 SemaphoreRef(const SemaphoreRef& other) noexcept
1319 : Semaphore(other.get())
1320 {
1321 }
1322
1325};
1326
1349inline Semaphore CreateSemaphore(Uint32 initial_value)
1350{
1351 return Semaphore(initial_value);
1352}
1353
1366inline void DestroySemaphore(SemaphoreRaw sem) { SDL_DestroySemaphore(sem); }
1367
1369
1388inline void WaitSemaphore(SemaphoreParam sem) { SDL_WaitSemaphore(sem); }
1389
1390inline void Semaphore::Wait() { SDL::WaitSemaphore(m_resource); }
1391
1410{
1411 return SDL_TryWaitSemaphore(sem);
1412}
1413
1414inline bool Semaphore::TryWait() { return SDL::TryWaitSemaphore(m_resource); }
1415
1435 std::chrono::milliseconds timeout)
1436{
1437 return SDL_WaitSemaphoreTimeout(sem, timeout.count());
1438}
1439
1440inline bool Semaphore::WaitTimeout(std::chrono::milliseconds timeout)
1441{
1442 return SDL::WaitSemaphoreTimeout(m_resource, timeout);
1443}
1444
1456inline void SignalSemaphore(SemaphoreParam sem) { SDL_SignalSemaphore(sem); }
1457
1458inline void Semaphore::Signal() { SDL::SignalSemaphore(m_resource); }
1459
1469{
1470 return SDL_GetSemaphoreValue(sem);
1471}
1472
1474{
1475 return SDL::GetSemaphoreValue(m_resource);
1476}
1477
1494{
1495 ConditionRaw m_resource = nullptr;
1496
1497public:
1499 constexpr Condition(std::nullptr_t) noexcept
1500 : m_resource(0)
1501 {
1502 }
1503
1511 constexpr explicit Condition(const ConditionRaw resource) noexcept
1512 : m_resource(resource)
1513 {
1514 }
1515
1517 constexpr Condition(const Condition& other) = delete;
1518
1520 constexpr Condition(Condition&& other) noexcept
1521 : Condition(other.release())
1522 {
1523 }
1524
1525 constexpr Condition(const ConditionRef& other) = delete;
1526
1527 constexpr Condition(ConditionRef&& other) = delete;
1528
1544 : m_resource(SDL_CreateCondition())
1545 {
1546 }
1547
1549 ~Condition() { SDL_DestroyCondition(m_resource); }
1550
1552 constexpr Condition& operator=(Condition&& other) noexcept
1553 {
1554 std::swap(m_resource, other.m_resource);
1555 return *this;
1556 }
1557
1558protected:
1560 constexpr Condition& operator=(const Condition& other) noexcept = default;
1561
1562public:
1564 constexpr ConditionRaw get() const noexcept { return m_resource; }
1565
1567 constexpr ConditionRaw release() noexcept
1568 {
1569 auto r = m_resource;
1570 m_resource = nullptr;
1571 return r;
1572 }
1573
1575 constexpr auto operator<=>(const Condition& other) const noexcept = default;
1576
1578 constexpr explicit operator bool() const noexcept { return !!m_resource; }
1579
1581 constexpr operator ConditionParam() const noexcept { return {m_resource}; }
1582
1590 void Destroy();
1591
1603 void Signal();
1604
1616 void Broadcast();
1617
1643 void Wait(MutexParam mutex);
1644
1672 bool WaitTimeout(MutexParam mutex, std::chrono::milliseconds timeout);
1673};
1674
1677{
1679
1687 ConditionRef(ConditionParam resource) noexcept
1688 : Condition(resource.value)
1689 {
1690 }
1691
1699 ConditionRef(ConditionRaw resource) noexcept
1700 : Condition(resource)
1701 {
1702 }
1703
1705 ConditionRef(const ConditionRef& other) noexcept
1706 : Condition(other.get())
1707 {
1708 }
1709
1712};
1713
1729
1739inline void DestroyCondition(ConditionRaw cond) { SDL_DestroyCondition(cond); }
1740
1742
1756inline void SignalCondition(ConditionParam cond) { SDL_SignalCondition(cond); }
1757
1758inline void Condition::Signal() { SDL::SignalCondition(m_resource); }
1759
1774{
1775 SDL_BroadcastCondition(cond);
1776}
1777
1778inline void Condition::Broadcast() { SDL::BroadcastCondition(m_resource); }
1779
1807{
1808 SDL_WaitCondition(cond, mutex);
1809}
1810
1811inline void Condition::Wait(MutexParam mutex)
1812{
1813 SDL::WaitCondition(m_resource, mutex);
1814}
1815
1845 MutexParam mutex,
1846 std::chrono::milliseconds timeout)
1847{
1848 return SDL_WaitConditionTimeout(cond, mutex, timeout.count());
1849}
1850
1852 std::chrono::milliseconds timeout)
1853{
1854 return SDL::WaitConditionTimeout(m_resource, mutex, timeout);
1855}
1856
1862using InitStatus = SDL_InitStatus;
1863
1865 SDL_INIT_STATUS_UNINITIALIZED;
1866
1868 SDL_INIT_STATUS_INITIALIZING;
1869
1871 SDL_INIT_STATUS_INITIALIZED;
1872
1874 SDL_INIT_STATUS_UNINITIALIZING;
1875
1934{
1935 constexpr InitState()
1936 : SDL_InitState{0}
1937 {
1938 }
1939
1960 bool ShouldInit();
1961
1980 bool ShouldQuit();
1981
1998 void SetInitialized(bool initialized);
1999};
2000
2022inline bool ShouldInit(InitStateRaw* state) { return SDL_ShouldInit(state); }
2023
2024inline bool InitState::ShouldInit() { return SDL::ShouldInit(this); }
2025
2045inline bool ShouldQuit(InitStateRaw* state) { return SDL_ShouldQuit(state); }
2046
2047inline bool InitState::ShouldQuit() { return SDL::ShouldQuit(this); }
2048
2066inline void SetInitialized(InitStateRaw* state, bool initialized)
2067{
2068 SDL_SetInitialized(state, initialized);
2069}
2070
2071inline void InitState::SetInitialized(bool initialized)
2072{
2073 SDL::SetInitialized(this, initialized);
2074}
2075
2077
2078} // namespace SDL
2079
2080#endif /* SDL3PP_MUTEX_H_ */
A means to block multiple threads until a condition is satisfied.
Definition: SDL3pp_mutex.h:1494
constexpr Condition(const ConditionRaw resource) noexcept
Constructs from ConditionParam.
Definition: SDL3pp_mutex.h:1511
constexpr ConditionRaw get() const noexcept
Retrieves underlying ConditionRaw.
Definition: SDL3pp_mutex.h:1564
Condition()
Create a condition variable.
Definition: SDL3pp_mutex.h:1543
constexpr Condition(Condition &&other) noexcept
Move constructor.
Definition: SDL3pp_mutex.h:1520
constexpr Condition(std::nullptr_t) noexcept
Default ctor.
Definition: SDL3pp_mutex.h:1499
constexpr ConditionRaw release() noexcept
Retrieves underlying ConditionRaw and clear this.
Definition: SDL3pp_mutex.h:1567
constexpr Condition & operator=(const Condition &other) noexcept=default
Assignment operator.
~Condition()
Destructor.
Definition: SDL3pp_mutex.h:1549
constexpr Condition(const Condition &other)=delete
Copy constructor.
constexpr auto operator<=>(const Condition &other) const noexcept=default
Comparison.
constexpr Condition & operator=(Condition &&other) noexcept
Assignment operator.
Definition: SDL3pp_mutex.h:1552
A means to serialize access to a resource between threads.
Definition: SDL3pp_mutex.h:195
constexpr Mutex & operator=(Mutex &&other) noexcept
Assignment operator.
Definition: SDL3pp_mutex.h:259
~Mutex()
Destructor.
Definition: SDL3pp_mutex.h:256
constexpr MutexRaw get() const noexcept
Retrieves underlying MutexRaw.
Definition: SDL3pp_mutex.h:271
Mutex()
Create a new mutex.
Definition: SDL3pp_mutex.h:250
constexpr auto operator<=>(const Mutex &other) const noexcept=default
Comparison.
constexpr Mutex & operator=(const Mutex &other) noexcept=default
Assignment operator.
constexpr Mutex(const Mutex &other)=delete
Copy constructor.
constexpr MutexRaw release() noexcept
Retrieves underlying MutexRaw and clear this.
Definition: SDL3pp_mutex.h:274
constexpr Mutex(const MutexRaw resource) noexcept
Constructs from MutexParam.
Definition: SDL3pp_mutex.h:212
constexpr Mutex(std::nullptr_t) noexcept
Default ctor.
Definition: SDL3pp_mutex.h:200
constexpr Mutex(Mutex &&other) noexcept
Move constructor.
Definition: SDL3pp_mutex.h:221
A mutex that allows read-only threads to run in parallel.
Definition: SDL3pp_mutex.h:539
constexpr auto operator<=>(const RWLock &other) const noexcept=default
Comparison.
~RWLock()
Destructor.
Definition: SDL3pp_mutex.h:620
constexpr RWLock(const RWLockRaw resource) noexcept
Constructs from RWLockParam.
Definition: SDL3pp_mutex.h:556
constexpr RWLock(RWLock &&other) noexcept
Move constructor.
Definition: SDL3pp_mutex.h:565
constexpr RWLock & operator=(const RWLock &other) noexcept=default
Assignment operator.
RWLock()
Create a new read/write lock.
Definition: SDL3pp_mutex.h:614
constexpr RWLock(const RWLock &other)=delete
Copy constructor.
constexpr RWLock(std::nullptr_t) noexcept
Default ctor.
Definition: SDL3pp_mutex.h:544
constexpr RWLockRaw get() const noexcept
Retrieves underlying RWLockRaw.
Definition: SDL3pp_mutex.h:635
constexpr RWLock & operator=(RWLock &&other) noexcept
Assignment operator.
Definition: SDL3pp_mutex.h:623
constexpr RWLockRaw release() noexcept
Retrieves underlying RWLockRaw and clear this.
Definition: SDL3pp_mutex.h:638
A means to manage access to a resource, by count, between threads.
Definition: SDL3pp_mutex.h:1103
constexpr SemaphoreRaw release() noexcept
Retrieves underlying SemaphoreRaw and clear this.
Definition: SDL3pp_mutex.h:1184
constexpr Semaphore & operator=(Semaphore &&other) noexcept
Assignment operator.
Definition: SDL3pp_mutex.h:1169
~Semaphore()
Destructor.
Definition: SDL3pp_mutex.h:1166
constexpr auto operator<=>(const Semaphore &other) const noexcept=default
Comparison.
Semaphore(Uint32 initial_value)
Create a semaphore.
Definition: SDL3pp_mutex.h:1160
constexpr Semaphore(const Semaphore &other)=delete
Copy constructor.
constexpr Semaphore(const SemaphoreRaw resource) noexcept
Constructs from SemaphoreParam.
Definition: SDL3pp_mutex.h:1120
constexpr SemaphoreRaw get() const noexcept
Retrieves underlying SemaphoreRaw.
Definition: SDL3pp_mutex.h:1181
constexpr Semaphore(Semaphore &&other) noexcept
Move constructor.
Definition: SDL3pp_mutex.h:1129
constexpr Semaphore(std::nullptr_t=nullptr) noexcept
Default ctor.
Definition: SDL3pp_mutex.h:1108
constexpr Semaphore & operator=(const Semaphore &other) noexcept=default
Assignment operator.
constexpr void CheckError(bool result)
Check and throw if returned value from SDL is an error.
Definition: SDL3pp_error.h:197
bool ShouldQuit(InitStateRaw *state)
Return whether cleanup should be done.
Definition: SDL3pp_mutex.h:2045
Uint32 GetSemaphoreValue(SemaphoreParam sem)
Get the current value of a semaphore.
Definition: SDL3pp_mutex.h:1468
constexpr InitStatus INIT_STATUS_UNINITIALIZING
INIT_STATUS_UNINITIALIZING.
Definition: SDL3pp_mutex.h:1873
void Unlock()
Unlock the read/write lock.
Definition: SDL3pp_mutex.h:1065
void LockMutex(MutexParam mutex)
Lock the mutex.
Definition: SDL3pp_mutex.h:448
bool TryWaitSemaphore(SemaphoreParam sem)
See if a semaphore has a positive value and decrement it if it does.
Definition: SDL3pp_mutex.h:1409
void TryLockForWriting()
Try to lock a read/write lock for writing without blocking.
Definition: SDL3pp_mutex.h:1035
void Wait(MutexParam mutex)
Wait until a condition variable is signaled.
Definition: SDL3pp_mutex.h:1811
constexpr InitStatus INIT_STATUS_INITIALIZING
INIT_STATUS_INITIALIZING.
Definition: SDL3pp_mutex.h:1867
void Signal()
Restart one of the threads that are waiting on the condition variable.
Definition: SDL3pp_mutex.h:1758
Mutex CreateMutex()
Create a new mutex.
Definition: SDL3pp_mutex.h:424
constexpr InitStatus INIT_STATUS_UNINITIALIZED
INIT_STATUS_UNINITIALIZED.
Definition: SDL3pp_mutex.h:1864
void SignalSemaphore(SemaphoreParam sem)
Atomically increment a semaphore's value and wake waiting threads.
Definition: SDL3pp_mutex.h:1456
bool TryWait()
See if a semaphore has a positive value and decrement it if it does.
Definition: SDL3pp_mutex.h:1414
void TryLockRWLockForReading(RWLockParam rwlock)
Try to lock a read/write lock for reading without blocking.
Definition: SDL3pp_mutex.h:992
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:1434
void Destroy()
Destroy a mutex created with Mutex.Mutex().
Definition: SDL3pp_mutex.h:516
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:476
void Unlock()
Unlock the mutex.
Definition: SDL3pp_mutex.h:497
void UnlockMutex(MutexParam mutex)
Unlock the mutex.
Definition: SDL3pp_mutex.h:495
SDL_InitStatus InitStatus
The current status of an InitState structure.
Definition: SDL3pp_mutex.h:1862
Condition CreateCondition()
Create a condition variable.
Definition: SDL3pp_mutex.h:1728
void DestroyRWLock(RWLockRaw rwlock)
Destroy a read/write lock created with RWLock.RWLock().
Definition: SDL3pp_mutex.h:1082
bool ShouldInit(InitStateRaw *state)
Return whether initialization should be done.
Definition: SDL3pp_mutex.h:2022
void BroadcastCondition(ConditionParam cond)
Restart all threads that are waiting on the condition variable.
Definition: SDL3pp_mutex.h:1773
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:2047
void LockForReading()
Lock the read/write lock for read only operations.
Definition: SDL3pp_mutex.h:931
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:1473
void UnlockRWLock(RWLockParam rwlock)
Unlock the read/write lock.
Definition: SDL3pp_mutex.h:1063
void TryLockMutex(MutexParam mutex)
Try to lock a mutex without blocking.
Definition: SDL3pp_mutex.h:471
void DestroyMutex(MutexRaw mutex)
Destroy a mutex created with Mutex.Mutex().
Definition: SDL3pp_mutex.h:514
bool ShouldInit()
Return whether initialization should be done.
Definition: SDL3pp_mutex.h:2024
bool WaitTimeout(std::chrono::milliseconds timeout)
Wait until a semaphore has a positive value and then decrements it.
Definition: SDL3pp_mutex.h:1440
void SignalCondition(ConditionParam cond)
Restart one of the threads that are waiting on the condition variable.
Definition: SDL3pp_mutex.h:1756
Semaphore CreateSemaphore(Uint32 initial_value)
Create a semaphore.
Definition: SDL3pp_mutex.h:1349
void LockRWLockForWriting(RWLockParam rwlock)
Lock the read/write lock for write operations.
Definition: SDL3pp_mutex.h:962
void Wait()
Wait until a semaphore has a positive value and then decrements it.
Definition: SDL3pp_mutex.h:1390
constexpr InitStatus INIT_STATUS_INITIALIZED
INIT_STATUS_INITIALIZED.
Definition: SDL3pp_mutex.h:1870
void Lock()
Lock the mutex.
Definition: SDL3pp_mutex.h:450
void Destroy()
Destroy a semaphore.
Definition: SDL3pp_mutex.h:1368
void Broadcast()
Restart all threads that are waiting on the condition variable.
Definition: SDL3pp_mutex.h:1778
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:1851
void Signal()
Atomically increment a semaphore's value and wake waiting threads.
Definition: SDL3pp_mutex.h:1458
RWLock CreateRWLock()
Create a new read/write lock.
Definition: SDL3pp_mutex.h:889
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:1030
void DestroySemaphore(SemaphoreRaw sem)
Destroy a semaphore.
Definition: SDL3pp_mutex.h:1366
void LockForWriting()
Lock the read/write lock for write operations.
Definition: SDL3pp_mutex.h:967
void Destroy()
Destroy a read/write lock created with RWLock.RWLock().
Definition: SDL3pp_mutex.h:1084
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:1844
void SetInitialized(InitStateRaw *state, bool initialized)
Finish an initialization state transition.
Definition: SDL3pp_mutex.h:2066
void TryLockForReading()
Try to lock a read/write lock for reading without blocking.
Definition: SDL3pp_mutex.h:997
void DestroyCondition(ConditionRaw cond)
Destroy a condition variable.
Definition: SDL3pp_mutex.h:1739
void Destroy()
Destroy a condition variable.
Definition: SDL3pp_mutex.h:1741
void LockRWLockForReading(RWLockParam rwlock)
Lock the read/write lock for read only operations.
Definition: SDL3pp_mutex.h:926
void WaitCondition(ConditionParam cond, MutexParam mutex)
Wait until a condition variable is signaled.
Definition: SDL3pp_mutex.h:1806
void SetInitialized(bool initialized)
Finish an initialization state transition.
Definition: SDL3pp_mutex.h:2071
void WaitSemaphore(SemaphoreParam sem)
Wait until a semaphore has a positive value and then decrements it.
Definition: SDL3pp_mutex.h:1388
::Uint32 Uint32
An unsigned 32-bit integer type.
Definition: SDL3pp_stdinc.h:341
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:1677
Condition()
Create a condition variable.
Definition: SDL3pp_mutex.h:1543
ConditionRef(ConditionParam resource) noexcept
Constructs from ConditionParam.
Definition: SDL3pp_mutex.h:1687
ConditionRef(const ConditionRef &other) noexcept
Copy constructor.
Definition: SDL3pp_mutex.h:1705
ConditionRef(ConditionRaw resource) noexcept
Constructs from ConditionParam.
Definition: SDL3pp_mutex.h:1699
~ConditionRef()
Destructor.
Definition: SDL3pp_mutex.h:1711
A structure used for thread-safe initialization and shutdown.
Definition: SDL3pp_mutex.h:1934
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:367
MutexRef(MutexRaw resource) noexcept
Constructs from MutexParam.
Definition: SDL3pp_mutex.h:389
Mutex()
Create a new mutex.
Definition: SDL3pp_mutex.h:250
MutexRef(const MutexRef &other) noexcept
Copy constructor.
Definition: SDL3pp_mutex.h:395
MutexRef(MutexParam resource) noexcept
Constructs from MutexParam.
Definition: SDL3pp_mutex.h:377
~MutexRef()
Destructor.
Definition: SDL3pp_mutex.h:401
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:812
RWLockRef(RWLockParam resource) noexcept
Constructs from RWLockParam.
Definition: SDL3pp_mutex.h:822
RWLock()
Create a new read/write lock.
Definition: SDL3pp_mutex.h:614
~RWLockRef()
Destructor.
Definition: SDL3pp_mutex.h:846
RWLockRef(RWLockRaw resource) noexcept
Constructs from RWLockParam.
Definition: SDL3pp_mutex.h:834
RWLockRef(const RWLockRef &other) noexcept
Copy constructor.
Definition: SDL3pp_mutex.h:840
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:1290
SemaphoreRef(SemaphoreRaw resource) noexcept
Constructs from SemaphoreParam.
Definition: SDL3pp_mutex.h:1312
SemaphoreRef(SemaphoreParam resource) noexcept
Constructs from SemaphoreParam.
Definition: SDL3pp_mutex.h:1300
SemaphoreRef(const SemaphoreRef &other) noexcept
Copy constructor.
Definition: SDL3pp_mutex.h:1318
~SemaphoreRef()
Destructor.
Definition: SDL3pp_mutex.h:1324