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
217protected:
219 constexpr Mutex(const Mutex& other) noexcept = default;
220
221public:
223 constexpr Mutex(Mutex&& other) noexcept
224 : Mutex(other.release())
225 {
226 }
227
228 constexpr Mutex(const MutexRef& other) = delete;
229
230 constexpr Mutex(MutexRef&& other) = delete;
231
253 : m_resource(SDL_CreateMutex())
254 {
255 }
256
258 ~Mutex() { SDL_DestroyMutex(m_resource); }
259
261 constexpr Mutex& operator=(Mutex&& other) noexcept
262 {
263 std::swap(m_resource, other.m_resource);
264 return *this;
265 }
266
267protected:
269 constexpr Mutex& operator=(const Mutex& other) noexcept = default;
270
271public:
273 constexpr MutexRaw get() const noexcept { return m_resource; }
274
276 constexpr MutexRaw release() noexcept
277 {
278 auto r = m_resource;
279 m_resource = nullptr;
280 return r;
281 }
282
284 constexpr auto operator<=>(const Mutex& other) const noexcept = default;
285
287 constexpr explicit operator bool() const noexcept { return !!m_resource; }
288
290 constexpr operator MutexParam() const noexcept { return {m_resource}; }
291
305 void Destroy();
306
327 void Lock();
328
347 void TryLock();
348
364 void Unlock();
365};
366
369{
370 using Mutex::Mutex;
371
379 MutexRef(MutexParam resource) noexcept
380 : Mutex(resource.value)
381 {
382 }
383
391 MutexRef(MutexRaw resource) noexcept
392 : Mutex(resource)
393 {
394 }
395
397 constexpr MutexRef(const MutexRef& other) noexcept = default;
398
401};
402
423inline Mutex CreateMutex() { return Mutex(); }
424
447inline void LockMutex(MutexParam mutex) { SDL_LockMutex(mutex); }
448
449inline void Mutex::Lock() { SDL::LockMutex(m_resource); }
450
470inline void TryLockMutex(MutexParam mutex)
471{
472 CheckError(SDL_TryLockMutex(mutex));
473}
474
475inline void Mutex::TryLock() { SDL::TryLockMutex(m_resource); }
476
494inline void UnlockMutex(MutexParam mutex) { SDL_UnlockMutex(mutex); }
495
496inline void Mutex::Unlock() { SDL::UnlockMutex(m_resource); }
497
513inline void DestroyMutex(MutexRaw mutex) { SDL_DestroyMutex(mutex); }
514
516
538{
539 RWLockRaw m_resource = nullptr;
540
541public:
543 constexpr RWLock(std::nullptr_t) noexcept
544 : m_resource(0)
545 {
546 }
547
555 constexpr explicit RWLock(const RWLockRaw resource) noexcept
556 : m_resource(resource)
557 {
558 }
559
560protected:
562 constexpr RWLock(const RWLock& other) noexcept = default;
563
564public:
566 constexpr RWLock(RWLock&& other) noexcept
567 : RWLock(other.release())
568 {
569 }
570
571 constexpr RWLock(const RWLockRef& other) = delete;
572
573 constexpr RWLock(RWLockRef&& other) = delete;
574
616 : m_resource(SDL_CreateRWLock())
617 {
618 }
619
621 ~RWLock() { SDL_DestroyRWLock(m_resource); }
622
624 constexpr RWLock& operator=(RWLock&& other) noexcept
625 {
626 std::swap(m_resource, other.m_resource);
627 return *this;
628 }
629
630protected:
632 constexpr RWLock& operator=(const RWLock& other) noexcept = default;
633
634public:
636 constexpr RWLockRaw get() const noexcept { return m_resource; }
637
639 constexpr RWLockRaw release() noexcept
640 {
641 auto r = m_resource;
642 m_resource = nullptr;
643 return r;
644 }
645
647 constexpr auto operator<=>(const RWLock& other) const noexcept = default;
648
650 constexpr explicit operator bool() const noexcept { return !!m_resource; }
651
653 constexpr operator RWLockParam() const noexcept { return {m_resource}; }
654
668 void Destroy();
669
703 void LockForReading();
704
732 void LockForWriting();
733
756 void TryLockForReading();
757
785 void TryLockForWriting();
786
808 void Unlock();
809};
810
813{
814 using RWLock::RWLock;
815
823 RWLockRef(RWLockParam resource) noexcept
824 : RWLock(resource.value)
825 {
826 }
827
835 RWLockRef(RWLockRaw resource) noexcept
836 : RWLock(resource)
837 {
838 }
839
841 constexpr RWLockRef(const RWLockRef& other) noexcept = default;
842
845};
846
887inline RWLock CreateRWLock() { return RWLock(); }
888
925{
926 SDL_LockRWLockForReading(rwlock);
927}
928
930
961{
962 SDL_LockRWLockForWriting(rwlock);
963}
964
966
991{
992 CheckError(SDL_TryLockRWLockForReading(rwlock));
993}
994
996{
998}
999
1029{
1030 CheckError(SDL_TryLockRWLockForWriting(rwlock));
1031}
1032
1034{
1035 SDL::TryLockRWLockForWriting(m_resource);
1036}
1037
1061inline void UnlockRWLock(RWLockParam rwlock) { SDL_UnlockRWLock(rwlock); }
1062
1063inline void RWLock::Unlock() { SDL::UnlockRWLock(m_resource); }
1064
1080inline void DestroyRWLock(RWLockRaw rwlock) { SDL_DestroyRWLock(rwlock); }
1081
1083
1101{
1102 SemaphoreRaw m_resource = nullptr;
1103
1104public:
1106 constexpr Semaphore(std::nullptr_t = nullptr) noexcept
1107 : m_resource(0)
1108 {
1109 }
1110
1118 constexpr explicit Semaphore(const SemaphoreRaw resource) noexcept
1119 : m_resource(resource)
1120 {
1121 }
1122
1123protected:
1125 constexpr Semaphore(const Semaphore& other) noexcept = default;
1126
1127public:
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 constexpr SemaphoreRef(const SemaphoreRef& other) noexcept = default;
1319
1322};
1323
1346inline Semaphore CreateSemaphore(Uint32 initial_value)
1347{
1348 return Semaphore(initial_value);
1349}
1350
1363inline void DestroySemaphore(SemaphoreRaw sem) { SDL_DestroySemaphore(sem); }
1364
1366
1385inline void WaitSemaphore(SemaphoreParam sem) { SDL_WaitSemaphore(sem); }
1386
1387inline void Semaphore::Wait() { SDL::WaitSemaphore(m_resource); }
1388
1407{
1408 return SDL_TryWaitSemaphore(sem);
1409}
1410
1411inline bool Semaphore::TryWait() { return SDL::TryWaitSemaphore(m_resource); }
1412
1432 std::chrono::milliseconds timeout)
1433{
1434 return SDL_WaitSemaphoreTimeout(sem, timeout.count());
1435}
1436
1437inline bool Semaphore::WaitTimeout(std::chrono::milliseconds timeout)
1438{
1439 return SDL::WaitSemaphoreTimeout(m_resource, timeout);
1440}
1441
1453inline void SignalSemaphore(SemaphoreParam sem) { SDL_SignalSemaphore(sem); }
1454
1455inline void Semaphore::Signal() { SDL::SignalSemaphore(m_resource); }
1456
1466{
1467 return SDL_GetSemaphoreValue(sem);
1468}
1469
1471{
1472 return SDL::GetSemaphoreValue(m_resource);
1473}
1474
1491{
1492 ConditionRaw m_resource = nullptr;
1493
1494public:
1496 constexpr Condition(std::nullptr_t) noexcept
1497 : m_resource(0)
1498 {
1499 }
1500
1508 constexpr explicit Condition(const ConditionRaw resource) noexcept
1509 : m_resource(resource)
1510 {
1511 }
1512
1513protected:
1515 constexpr Condition(const Condition& other) noexcept = default;
1516
1517public:
1519 constexpr Condition(Condition&& other) noexcept
1520 : Condition(other.release())
1521 {
1522 }
1523
1524 constexpr Condition(const ConditionRef& other) = delete;
1525
1526 constexpr Condition(ConditionRef&& other) = delete;
1527
1543 : m_resource(SDL_CreateCondition())
1544 {
1545 }
1546
1548 ~Condition() { SDL_DestroyCondition(m_resource); }
1549
1551 constexpr Condition& operator=(Condition&& other) noexcept
1552 {
1553 std::swap(m_resource, other.m_resource);
1554 return *this;
1555 }
1556
1557protected:
1559 constexpr Condition& operator=(const Condition& other) noexcept = default;
1560
1561public:
1563 constexpr ConditionRaw get() const noexcept { return m_resource; }
1564
1566 constexpr ConditionRaw release() noexcept
1567 {
1568 auto r = m_resource;
1569 m_resource = nullptr;
1570 return r;
1571 }
1572
1574 constexpr auto operator<=>(const Condition& other) const noexcept = default;
1575
1577 constexpr explicit operator bool() const noexcept { return !!m_resource; }
1578
1580 constexpr operator ConditionParam() const noexcept { return {m_resource}; }
1581
1589 void Destroy();
1590
1602 void Signal();
1603
1615 void Broadcast();
1616
1642 void Wait(MutexParam mutex);
1643
1671 bool WaitTimeout(MutexParam mutex, std::chrono::milliseconds timeout);
1672};
1673
1676{
1678
1686 ConditionRef(ConditionParam resource) noexcept
1687 : Condition(resource.value)
1688 {
1689 }
1690
1698 ConditionRef(ConditionRaw resource) noexcept
1699 : Condition(resource)
1700 {
1701 }
1702
1704 constexpr ConditionRef(const ConditionRef& other) noexcept = default;
1705
1708};
1709
1725
1735inline void DestroyCondition(ConditionRaw cond) { SDL_DestroyCondition(cond); }
1736
1738
1752inline void SignalCondition(ConditionParam cond) { SDL_SignalCondition(cond); }
1753
1754inline void Condition::Signal() { SDL::SignalCondition(m_resource); }
1755
1770{
1771 SDL_BroadcastCondition(cond);
1772}
1773
1774inline void Condition::Broadcast() { SDL::BroadcastCondition(m_resource); }
1775
1803{
1804 SDL_WaitCondition(cond, mutex);
1805}
1806
1807inline void Condition::Wait(MutexParam mutex)
1808{
1809 SDL::WaitCondition(m_resource, mutex);
1810}
1811
1841 MutexParam mutex,
1842 std::chrono::milliseconds timeout)
1843{
1844 return SDL_WaitConditionTimeout(cond, mutex, timeout.count());
1845}
1846
1848 std::chrono::milliseconds timeout)
1849{
1850 return SDL::WaitConditionTimeout(m_resource, mutex, timeout);
1851}
1852
1858using InitStatus = SDL_InitStatus;
1859
1861 SDL_INIT_STATUS_UNINITIALIZED;
1862
1864 SDL_INIT_STATUS_INITIALIZING;
1865
1867 SDL_INIT_STATUS_INITIALIZED;
1868
1870 SDL_INIT_STATUS_UNINITIALIZING;
1871
1930{
1931 constexpr InitState()
1932 : SDL_InitState{0}
1933 {
1934 }
1935
1956 bool ShouldInit();
1957
1976 bool ShouldQuit();
1977
1994 void SetInitialized(bool initialized);
1995};
1996
2018inline bool ShouldInit(InitStateRaw* state) { return SDL_ShouldInit(state); }
2019
2020inline bool InitState::ShouldInit() { return SDL::ShouldInit(this); }
2021
2041inline bool ShouldQuit(InitStateRaw* state) { return SDL_ShouldQuit(state); }
2042
2043inline bool InitState::ShouldQuit() { return SDL::ShouldQuit(this); }
2044
2062inline void SetInitialized(InitStateRaw* state, bool initialized)
2063{
2064 SDL_SetInitialized(state, initialized);
2065}
2066
2067inline void InitState::SetInitialized(bool initialized)
2068{
2069 SDL::SetInitialized(this, initialized);
2070}
2071
2073
2074} // namespace SDL
2075
2076#endif /* SDL3PP_MUTEX_H_ */
A means to block multiple threads until a condition is satisfied.
Definition: SDL3pp_mutex.h:1491
constexpr Condition(const ConditionRaw resource) noexcept
Constructs from ConditionParam.
Definition: SDL3pp_mutex.h:1508
constexpr ConditionRaw get() const noexcept
Retrieves underlying ConditionRaw.
Definition: SDL3pp_mutex.h:1563
Condition()
Create a condition variable.
Definition: SDL3pp_mutex.h:1542
constexpr Condition(Condition &&other) noexcept
Move constructor.
Definition: SDL3pp_mutex.h:1519
constexpr Condition(std::nullptr_t) noexcept
Default ctor.
Definition: SDL3pp_mutex.h:1496
constexpr ConditionRaw release() noexcept
Retrieves underlying ConditionRaw and clear this.
Definition: SDL3pp_mutex.h:1566
constexpr Condition & operator=(const Condition &other) noexcept=default
Assignment operator.
constexpr Condition(const Condition &other) noexcept=default
Copy constructor.
~Condition()
Destructor.
Definition: SDL3pp_mutex.h:1548
constexpr auto operator<=>(const Condition &other) const noexcept=default
Comparison.
constexpr Condition & operator=(Condition &&other) noexcept
Assignment operator.
Definition: SDL3pp_mutex.h:1551
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:261
~Mutex()
Destructor.
Definition: SDL3pp_mutex.h:258
constexpr MutexRaw get() const noexcept
Retrieves underlying MutexRaw.
Definition: SDL3pp_mutex.h:273
Mutex()
Create a new mutex.
Definition: SDL3pp_mutex.h:252
constexpr Mutex(const Mutex &other) noexcept=default
Copy constructor.
constexpr auto operator<=>(const Mutex &other) const noexcept=default
Comparison.
constexpr Mutex & operator=(const Mutex &other) noexcept=default
Assignment operator.
constexpr MutexRaw release() noexcept
Retrieves underlying MutexRaw and clear this.
Definition: SDL3pp_mutex.h:276
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:223
A mutex that allows read-only threads to run in parallel.
Definition: SDL3pp_mutex.h:538
constexpr auto operator<=>(const RWLock &other) const noexcept=default
Comparison.
~RWLock()
Destructor.
Definition: SDL3pp_mutex.h:621
constexpr RWLock(const RWLockRaw resource) noexcept
Constructs from RWLockParam.
Definition: SDL3pp_mutex.h:555
constexpr RWLock(RWLock &&other) noexcept
Move constructor.
Definition: SDL3pp_mutex.h:566
constexpr RWLock & operator=(const RWLock &other) noexcept=default
Assignment operator.
RWLock()
Create a new read/write lock.
Definition: SDL3pp_mutex.h:615
constexpr RWLock(std::nullptr_t) noexcept
Default ctor.
Definition: SDL3pp_mutex.h:543
constexpr RWLockRaw get() const noexcept
Retrieves underlying RWLockRaw.
Definition: SDL3pp_mutex.h:636
constexpr RWLock & operator=(RWLock &&other) noexcept
Assignment operator.
Definition: SDL3pp_mutex.h:624
constexpr RWLock(const RWLock &other) noexcept=default
Copy constructor.
constexpr RWLockRaw release() noexcept
Retrieves underlying RWLockRaw and clear this.
Definition: SDL3pp_mutex.h:639
A means to manage access to a resource, by count, between threads.
Definition: SDL3pp_mutex.h:1101
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.
constexpr Semaphore(const Semaphore &other) noexcept=default
Copy constructor.
Semaphore(Uint32 initial_value)
Create a semaphore.
Definition: SDL3pp_mutex.h:1160
constexpr Semaphore(const SemaphoreRaw resource) noexcept
Constructs from SemaphoreParam.
Definition: SDL3pp_mutex.h:1118
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:1106
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:2041
Uint32 GetSemaphoreValue(SemaphoreParam sem)
Get the current value of a semaphore.
Definition: SDL3pp_mutex.h:1465
constexpr InitStatus INIT_STATUS_UNINITIALIZING
INIT_STATUS_UNINITIALIZING.
Definition: SDL3pp_mutex.h:1869
void Unlock()
Unlock the read/write lock.
Definition: SDL3pp_mutex.h:1063
void LockMutex(MutexParam mutex)
Lock the mutex.
Definition: SDL3pp_mutex.h:447
bool TryWaitSemaphore(SemaphoreParam sem)
See if a semaphore has a positive value and decrement it if it does.
Definition: SDL3pp_mutex.h:1406
void TryLockForWriting()
Try to lock a read/write lock for writing without blocking.
Definition: SDL3pp_mutex.h:1033
void Wait(MutexParam mutex)
Wait until a condition variable is signaled.
Definition: SDL3pp_mutex.h:1807
constexpr InitStatus INIT_STATUS_INITIALIZING
INIT_STATUS_INITIALIZING.
Definition: SDL3pp_mutex.h:1863
void Signal()
Restart one of the threads that are waiting on the condition variable.
Definition: SDL3pp_mutex.h:1754
Mutex CreateMutex()
Create a new mutex.
Definition: SDL3pp_mutex.h:423
constexpr InitStatus INIT_STATUS_UNINITIALIZED
INIT_STATUS_UNINITIALIZED.
Definition: SDL3pp_mutex.h:1860
void SignalSemaphore(SemaphoreParam sem)
Atomically increment a semaphore's value and wake waiting threads.
Definition: SDL3pp_mutex.h:1453
bool TryWait()
See if a semaphore has a positive value and decrement it if it does.
Definition: SDL3pp_mutex.h:1411
void TryLockRWLockForReading(RWLockParam rwlock)
Try to lock a read/write lock for reading without blocking.
Definition: SDL3pp_mutex.h:990
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:1431
void Destroy()
Destroy a mutex created with Mutex.Mutex().
Definition: SDL3pp_mutex.h:515
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:475
void Unlock()
Unlock the mutex.
Definition: SDL3pp_mutex.h:496
void UnlockMutex(MutexParam mutex)
Unlock the mutex.
Definition: SDL3pp_mutex.h:494
SDL_InitStatus InitStatus
The current status of an InitState structure.
Definition: SDL3pp_mutex.h:1858
Condition CreateCondition()
Create a condition variable.
Definition: SDL3pp_mutex.h:1724
void DestroyRWLock(RWLockRaw rwlock)
Destroy a read/write lock created with RWLock.RWLock().
Definition: SDL3pp_mutex.h:1080
bool ShouldInit(InitStateRaw *state)
Return whether initialization should be done.
Definition: SDL3pp_mutex.h:2018
void BroadcastCondition(ConditionParam cond)
Restart all threads that are waiting on the condition variable.
Definition: SDL3pp_mutex.h:1769
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:2043
void LockForReading()
Lock the read/write lock for read only operations.
Definition: SDL3pp_mutex.h:929
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:1470
void UnlockRWLock(RWLockParam rwlock)
Unlock the read/write lock.
Definition: SDL3pp_mutex.h:1061
void TryLockMutex(MutexParam mutex)
Try to lock a mutex without blocking.
Definition: SDL3pp_mutex.h:470
void DestroyMutex(MutexRaw mutex)
Destroy a mutex created with Mutex.Mutex().
Definition: SDL3pp_mutex.h:513
bool ShouldInit()
Return whether initialization should be done.
Definition: SDL3pp_mutex.h:2020
bool WaitTimeout(std::chrono::milliseconds timeout)
Wait until a semaphore has a positive value and then decrements it.
Definition: SDL3pp_mutex.h:1437
void SignalCondition(ConditionParam cond)
Restart one of the threads that are waiting on the condition variable.
Definition: SDL3pp_mutex.h:1752
Semaphore CreateSemaphore(Uint32 initial_value)
Create a semaphore.
Definition: SDL3pp_mutex.h:1346
void LockRWLockForWriting(RWLockParam rwlock)
Lock the read/write lock for write operations.
Definition: SDL3pp_mutex.h:960
void Wait()
Wait until a semaphore has a positive value and then decrements it.
Definition: SDL3pp_mutex.h:1387
constexpr InitStatus INIT_STATUS_INITIALIZED
INIT_STATUS_INITIALIZED.
Definition: SDL3pp_mutex.h:1866
void Lock()
Lock the mutex.
Definition: SDL3pp_mutex.h:449
void Destroy()
Destroy a semaphore.
Definition: SDL3pp_mutex.h:1365
void Broadcast()
Restart all threads that are waiting on the condition variable.
Definition: SDL3pp_mutex.h:1774
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:1847
void Signal()
Atomically increment a semaphore's value and wake waiting threads.
Definition: SDL3pp_mutex.h:1455
RWLock CreateRWLock()
Create a new read/write lock.
Definition: SDL3pp_mutex.h:887
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:1028
void DestroySemaphore(SemaphoreRaw sem)
Destroy a semaphore.
Definition: SDL3pp_mutex.h:1363
void LockForWriting()
Lock the read/write lock for write operations.
Definition: SDL3pp_mutex.h:965
void Destroy()
Destroy a read/write lock created with RWLock.RWLock().
Definition: SDL3pp_mutex.h:1082
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:1840
void SetInitialized(InitStateRaw *state, bool initialized)
Finish an initialization state transition.
Definition: SDL3pp_mutex.h:2062
void TryLockForReading()
Try to lock a read/write lock for reading without blocking.
Definition: SDL3pp_mutex.h:995
void DestroyCondition(ConditionRaw cond)
Destroy a condition variable.
Definition: SDL3pp_mutex.h:1735
void Destroy()
Destroy a condition variable.
Definition: SDL3pp_mutex.h:1737
void LockRWLockForReading(RWLockParam rwlock)
Lock the read/write lock for read only operations.
Definition: SDL3pp_mutex.h:924
void WaitCondition(ConditionParam cond, MutexParam mutex)
Wait until a condition variable is signaled.
Definition: SDL3pp_mutex.h:1802
void SetInitialized(bool initialized)
Finish an initialization state transition.
Definition: SDL3pp_mutex.h:2067
void WaitSemaphore(SemaphoreParam sem)
Wait until a semaphore has a positive value and then decrements it.
Definition: SDL3pp_mutex.h:1385
::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(ConditionRaw value)
Constructs from ConditionRaw.
Definition: SDL3pp_mutex.h:153
constexpr auto operator<=>(const ConditionParam &other) const =default
Comparison.
constexpr ConditionParam(std::nullptr_t=nullptr)
Constructs null/invalid.
Definition: SDL3pp_mutex.h:159
Semi-safe reference for Condition.
Definition: SDL3pp_mutex.h:1676
Condition()
Create a condition variable.
Definition: SDL3pp_mutex.h:1542
ConditionRef(ConditionParam resource) noexcept
Constructs from ConditionParam.
Definition: SDL3pp_mutex.h:1686
constexpr ConditionRef(const ConditionRef &other) noexcept=default
Copy constructor.
ConditionRef(ConditionRaw resource) noexcept
Constructs from ConditionParam.
Definition: SDL3pp_mutex.h:1698
~ConditionRef()
Destructor.
Definition: SDL3pp_mutex.h:1707
A structure used for thread-safe initialization and shutdown.
Definition: SDL3pp_mutex.h:1930
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:369
MutexRef(MutexRaw resource) noexcept
Constructs from MutexParam.
Definition: SDL3pp_mutex.h:391
Mutex()
Create a new mutex.
Definition: SDL3pp_mutex.h:252
constexpr MutexRef(const MutexRef &other) noexcept=default
Copy constructor.
MutexRef(MutexParam resource) noexcept
Constructs from MutexParam.
Definition: SDL3pp_mutex.h:379
~MutexRef()
Destructor.
Definition: SDL3pp_mutex.h:400
Safely wrap RWLock for non owning parameters.
Definition: SDL3pp_mutex.h:77
RWLockRaw value
parameter's RWLockRaw
Definition: SDL3pp_mutex.h:78
constexpr RWLockParam(std::nullptr_t=nullptr)
Constructs null/invalid.
Definition: SDL3pp_mutex.h:87
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:813
RWLockRef(RWLockParam resource) noexcept
Constructs from RWLockParam.
Definition: SDL3pp_mutex.h:823
RWLock()
Create a new read/write lock.
Definition: SDL3pp_mutex.h:615
~RWLockRef()
Destructor.
Definition: SDL3pp_mutex.h:844
RWLockRef(RWLockRaw resource) noexcept
Constructs from RWLockParam.
Definition: SDL3pp_mutex.h:835
constexpr RWLockRef(const RWLockRef &other) noexcept=default
Copy constructor.
Safely wrap Semaphore for non owning parameters.
Definition: SDL3pp_mutex.h:113
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.
constexpr SemaphoreParam(std::nullptr_t=nullptr)
Constructs null/invalid.
Definition: SDL3pp_mutex.h:123
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()
Destructor.
Definition: SDL3pp_mutex.h:1321
constexpr SemaphoreRef(const SemaphoreRef &other) noexcept=default
Copy constructor.