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
39// Forward decl
40struct RWLock;
41
43using RWLockRaw = SDL_RWLock*;
44
45// Forward decl
46struct RWLockRef;
47
48// Forward decl
49struct Semaphore;
50
52using SemaphoreRaw = SDL_Semaphore*;
53
54// Forward decl
55struct SemaphoreRef;
56
57// Forward decl
58struct Condition;
59
61using ConditionRaw = SDL_Condition*;
62
63// Forward decl
64struct ConditionRef;
65
67using InitStateRaw = SDL_InitState;
68
69// Forward decl
70struct InitState;
71
86class Mutex
87{
88 MutexRaw m_resource = nullptr;
89
90public:
92 constexpr Mutex(std::nullptr_t) noexcept
93 : m_resource(nullptr)
94 {
95 }
96
104 constexpr explicit Mutex(MutexRaw resource) noexcept
105 : m_resource(resource)
106 {
107 }
108
110 constexpr Mutex(const Mutex& other) noexcept = delete;
111
113 constexpr Mutex(Mutex&& other) noexcept
114 : Mutex(other.release())
115 {
116 }
117
118 constexpr Mutex(const MutexRef& other) = delete;
119
120 constexpr Mutex(MutexRef&& other) = delete;
121
145
147 ~Mutex() { SDL_DestroyMutex(m_resource); }
148
150 constexpr Mutex& operator=(Mutex&& other) noexcept
151 {
152 std::swap(m_resource, other.m_resource);
153 return *this;
154 }
155
157 Mutex& operator=(const Mutex& other) = delete;
158
160 constexpr MutexRaw get() const noexcept { return m_resource; }
161
163 constexpr MutexRaw release() noexcept
164 {
165 auto r = m_resource;
166 m_resource = nullptr;
167 return r;
168 }
169
171 constexpr auto operator<=>(const Mutex& other) const noexcept = default;
172
174 constexpr explicit operator bool() const noexcept { return !!m_resource; }
175
191 void Destroy();
192
215 void Lock();
216
237 bool TryLock();
238
257 void Unlock();
258};
259
266{
267 using Mutex::Mutex;
268
276 constexpr MutexRef(MutexRaw resource) noexcept
277 : Mutex(resource)
278 {
279 }
280
288 constexpr MutexRef(const Mutex& resource) noexcept
289 : Mutex(resource.get())
290 {
291 }
292
300 constexpr MutexRef(Mutex&& resource) noexcept
301 : Mutex(std::move(resource).release())
302 {
303 }
304
306 constexpr MutexRef(const MutexRef& other) noexcept
307 : Mutex(other.get())
308 {
309 }
310
312 constexpr MutexRef(MutexRef&& other) noexcept
313 : Mutex(other.get())
314 {
315 }
316
319
321 MutexRef& operator=(const MutexRef& other) noexcept
322 {
323 release();
324 Mutex::operator=(Mutex(other.get()));
325 return *this;
326 }
327
329 constexpr operator MutexRaw() const noexcept { return get(); }
330};
331
354inline Mutex CreateMutex() { return Mutex(); }
355
357 : m_resource(SDL_CreateMutex())
358{
359}
360
385inline void LockMutex(MutexRef mutex) { SDL_LockMutex(mutex); }
386
387inline void Mutex::Lock() { SDL::LockMutex(m_resource); }
388
410inline bool TryLockMutex(MutexRef mutex) { return SDL_TryLockMutex(mutex); }
411
412inline bool Mutex::TryLock() { return SDL::TryLockMutex(m_resource); }
413
434inline void UnlockMutex(MutexRef mutex) { SDL_UnlockMutex(mutex); }
435
436inline void Mutex::Unlock() { SDL::UnlockMutex(m_resource); }
437
455inline void DestroyMutex(MutexRaw mutex) { SDL_DestroyMutex(mutex); }
456
458
480{
481 RWLockRaw m_resource = nullptr;
482
483public:
485 constexpr RWLock(std::nullptr_t) noexcept
486 : m_resource(nullptr)
487 {
488 }
489
497 constexpr explicit RWLock(RWLockRaw resource) noexcept
498 : m_resource(resource)
499 {
500 }
501
503 constexpr RWLock(const RWLock& other) noexcept = delete;
504
506 constexpr RWLock(RWLock&& other) noexcept
507 : RWLock(other.release())
508 {
509 }
510
511 constexpr RWLock(const RWLockRef& other) = delete;
512
513 constexpr RWLock(RWLockRef&& other) = delete;
514
558
560 ~RWLock() { SDL_DestroyRWLock(m_resource); }
561
563 constexpr RWLock& operator=(RWLock&& other) noexcept
564 {
565 std::swap(m_resource, other.m_resource);
566 return *this;
567 }
568
570 RWLock& operator=(const RWLock& other) = delete;
571
573 constexpr RWLockRaw get() const noexcept { return m_resource; }
574
576 constexpr RWLockRaw release() noexcept
577 {
578 auto r = m_resource;
579 m_resource = nullptr;
580 return r;
581 }
582
584 constexpr auto operator<=>(const RWLock& other) const noexcept = default;
585
587 constexpr explicit operator bool() const noexcept { return !!m_resource; }
588
604 void Destroy();
605
641 void LockForReading();
642
672 void LockForWriting();
673
698 bool TryLockForReading();
699
729 bool TryLockForWriting();
730
755 void Unlock();
756};
757
764{
765 using RWLock::RWLock;
766
774 constexpr RWLockRef(RWLockRaw resource) noexcept
775 : RWLock(resource)
776 {
777 }
778
786 constexpr RWLockRef(const RWLock& resource) noexcept
787 : RWLock(resource.get())
788 {
789 }
790
798 constexpr RWLockRef(RWLock&& resource) noexcept
799 : RWLock(std::move(resource).release())
800 {
801 }
802
804 constexpr RWLockRef(const RWLockRef& other) noexcept
805 : RWLock(other.get())
806 {
807 }
808
810 constexpr RWLockRef(RWLockRef&& other) noexcept
811 : RWLock(other.get())
812 {
813 }
814
817
819 RWLockRef& operator=(const RWLockRef& other) noexcept
820 {
821 release();
822 RWLock::operator=(RWLock(other.get()));
823 return *this;
824 }
825
827 constexpr operator RWLockRaw() const noexcept { return get(); }
828};
829
872inline RWLock CreateRWLock() { return RWLock(); }
873
875 : m_resource(SDL_CreateRWLock())
876{
877}
878
917{
918 SDL_LockRWLockForReading(rwlock);
919}
920
922
955{
956 SDL_LockRWLockForWriting(rwlock);
957}
958
960
987{
988 return SDL_TryLockRWLockForReading(rwlock);
989}
990
992{
993 return SDL::TryLockRWLockForReading(m_resource);
994}
995
1027{
1028 return SDL_TryLockRWLockForWriting(rwlock);
1029}
1030
1032{
1033 return SDL::TryLockRWLockForWriting(m_resource);
1034}
1035
1062inline void UnlockRWLock(RWLockRef rwlock) { SDL_UnlockRWLock(rwlock); }
1063
1064inline void RWLock::Unlock() { SDL::UnlockRWLock(m_resource); }
1065
1083inline void DestroyRWLock(RWLockRaw rwlock) { SDL_DestroyRWLock(rwlock); }
1084
1086
1104{
1105 SemaphoreRaw m_resource = nullptr;
1106
1107public:
1109 constexpr Semaphore(std::nullptr_t = nullptr) noexcept
1110 : m_resource(nullptr)
1111 {
1112 }
1113
1121 constexpr explicit Semaphore(SemaphoreRaw resource) noexcept
1122 : m_resource(resource)
1123 {
1124 }
1125
1127 constexpr Semaphore(const Semaphore& other) noexcept = delete;
1128
1130 constexpr Semaphore(Semaphore&& other) noexcept
1131 : Semaphore(other.release())
1132 {
1133 }
1134
1135 constexpr Semaphore(const SemaphoreRef& other) = delete;
1136
1137 constexpr Semaphore(SemaphoreRef&& other) = delete;
1138
1163 Semaphore(Uint32 initial_value);
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
1176 Semaphore& operator=(const Semaphore& other) = delete;
1177
1179 constexpr SemaphoreRaw get() const noexcept { return m_resource; }
1180
1182 constexpr SemaphoreRaw release() noexcept
1183 {
1184 auto r = m_resource;
1185 m_resource = nullptr;
1186 return r;
1187 }
1188
1190 constexpr auto operator<=>(const Semaphore& other) const noexcept = default;
1191
1193 constexpr explicit operator bool() const noexcept { return !!m_resource; }
1194
1207 void Destroy();
1208
1227 void Wait();
1228
1247 bool TryWait();
1248
1268 bool WaitTimeout(std::chrono::milliseconds timeout);
1269
1281 void Signal();
1282
1292 Uint32 GetValue() const;
1293};
1294
1301{
1303
1311 constexpr SemaphoreRef(SemaphoreRaw resource) noexcept
1312 : Semaphore(resource)
1313 {
1314 }
1315
1323 constexpr SemaphoreRef(const Semaphore& resource) noexcept
1324 : Semaphore(resource.get())
1325 {
1326 }
1327
1335 constexpr SemaphoreRef(Semaphore&& resource) noexcept
1336 : Semaphore(std::move(resource).release())
1337 {
1338 }
1339
1341 constexpr SemaphoreRef(const SemaphoreRef& other) noexcept
1342 : Semaphore(other.get())
1343 {
1344 }
1345
1347 constexpr SemaphoreRef(SemaphoreRef&& other) noexcept
1348 : Semaphore(other.get())
1349 {
1350 }
1351
1354
1356 SemaphoreRef& operator=(const SemaphoreRef& other) noexcept
1357 {
1358 release();
1359 Semaphore::operator=(Semaphore(other.get()));
1360 return *this;
1361 }
1362
1364 constexpr operator SemaphoreRaw() const noexcept { return get(); }
1365};
1366
1391inline Semaphore CreateSemaphore(Uint32 initial_value)
1392{
1393 return Semaphore(initial_value);
1394}
1395
1396inline Semaphore::Semaphore(Uint32 initial_value)
1397 : m_resource(SDL_CreateSemaphore(initial_value))
1398{
1399}
1400
1415inline void DestroySemaphore(SemaphoreRaw sem) { SDL_DestroySemaphore(sem); }
1416
1418
1439inline void WaitSemaphore(SemaphoreRef sem) { SDL_WaitSemaphore(sem); }
1440
1441inline void Semaphore::Wait() { SDL::WaitSemaphore(m_resource); }
1442
1463{
1464 return SDL_TryWaitSemaphore(sem);
1465}
1466
1467inline bool Semaphore::TryWait() { return SDL::TryWaitSemaphore(m_resource); }
1468
1490 std::chrono::milliseconds timeout)
1491{
1492 return SDL_WaitSemaphoreTimeout(sem, narrowS32(timeout.count()));
1493}
1494
1495inline bool Semaphore::WaitTimeout(std::chrono::milliseconds timeout)
1496{
1497 return SDL::WaitSemaphoreTimeout(m_resource, timeout);
1498}
1499
1513inline void SignalSemaphore(SemaphoreRef sem) { SDL_SignalSemaphore(sem); }
1514
1515inline void Semaphore::Signal() { SDL::SignalSemaphore(m_resource); }
1516
1528{
1529 return SDL_GetSemaphoreValue(sem);
1530}
1531
1533{
1534 return SDL::GetSemaphoreValue(m_resource);
1535}
1536
1553{
1554 ConditionRaw m_resource = nullptr;
1555
1556public:
1558 constexpr Condition(std::nullptr_t) noexcept
1559 : m_resource(nullptr)
1560 {
1561 }
1562
1570 constexpr explicit Condition(ConditionRaw resource) noexcept
1571 : m_resource(resource)
1572 {
1573 }
1574
1576 constexpr Condition(const Condition& other) noexcept = delete;
1577
1579 constexpr Condition(Condition&& other) noexcept
1580 : Condition(other.release())
1581 {
1582 }
1583
1584 constexpr Condition(const ConditionRef& other) = delete;
1585
1586 constexpr Condition(ConditionRef&& other) = delete;
1587
1605
1607 ~Condition() { SDL_DestroyCondition(m_resource); }
1608
1610 constexpr Condition& operator=(Condition&& other) noexcept
1611 {
1612 std::swap(m_resource, other.m_resource);
1613 return *this;
1614 }
1615
1617 Condition& operator=(const Condition& other) = delete;
1618
1620 constexpr ConditionRaw get() const noexcept { return m_resource; }
1621
1623 constexpr ConditionRaw release() noexcept
1624 {
1625 auto r = m_resource;
1626 m_resource = nullptr;
1627 return r;
1628 }
1629
1631 constexpr auto operator<=>(const Condition& other) const noexcept = default;
1632
1634 constexpr explicit operator bool() const noexcept { return !!m_resource; }
1635
1645 void Destroy();
1646
1658 void Signal();
1659
1671 void Broadcast();
1672
1698 void Wait(MutexRef mutex);
1699
1727 bool WaitTimeout(MutexRef mutex, std::chrono::milliseconds timeout);
1728};
1729
1736{
1738
1746 constexpr ConditionRef(ConditionRaw resource) noexcept
1747 : Condition(resource)
1748 {
1749 }
1750
1758 constexpr ConditionRef(const Condition& resource) noexcept
1759 : Condition(resource.get())
1760 {
1761 }
1762
1770 constexpr ConditionRef(Condition&& resource) noexcept
1771 : Condition(std::move(resource).release())
1772 {
1773 }
1774
1776 constexpr ConditionRef(const ConditionRef& other) noexcept
1777 : Condition(other.get())
1778 {
1779 }
1780
1782 constexpr ConditionRef(ConditionRef&& other) noexcept
1783 : Condition(other.get())
1784 {
1785 }
1786
1789
1791 ConditionRef& operator=(const ConditionRef& other) noexcept
1792 {
1793 release();
1794 Condition::operator=(Condition(other.get()));
1795 return *this;
1796 }
1797
1799 constexpr operator ConditionRaw() const noexcept { return get(); }
1800};
1801
1819
1821 : m_resource(SDL_CreateCondition())
1822{
1823}
1824
1836inline void DestroyCondition(ConditionRaw cond) { SDL_DestroyCondition(cond); }
1837
1839
1853inline void SignalCondition(ConditionRef cond) { SDL_SignalCondition(cond); }
1854
1855inline void Condition::Signal() { SDL::SignalCondition(m_resource); }
1856
1871{
1872 SDL_BroadcastCondition(cond);
1873}
1874
1875inline void Condition::Broadcast() { SDL::BroadcastCondition(m_resource); }
1876
1903inline void WaitCondition(ConditionRef cond, MutexRef mutex)
1904{
1905 SDL_WaitCondition(cond, mutex);
1906}
1907
1908inline void Condition::Wait(MutexRef mutex)
1909{
1910 SDL::WaitCondition(m_resource, mutex);
1911}
1912
1942 MutexRef mutex,
1943 std::chrono::milliseconds timeout)
1944{
1945 return SDL_WaitConditionTimeout(cond, mutex, narrowS32(timeout.count()));
1946}
1947
1949 std::chrono::milliseconds timeout)
1950{
1951 return SDL::WaitConditionTimeout(m_resource, mutex, timeout);
1952}
1953
1959using InitStatus = SDL_InitStatus;
1960
1962 SDL_INIT_STATUS_UNINITIALIZED;
1963
1965 SDL_INIT_STATUS_INITIALIZING;
1966
1968 SDL_INIT_STATUS_INITIALIZED;
1969
1971 SDL_INIT_STATUS_UNINITIALIZING;
1972
2031{
2032 constexpr InitState()
2033 : SDL_InitState{}
2034 {
2035 }
2036
2057 bool ShouldInit();
2058
2077 bool ShouldQuit();
2078
2095 void SetInitialized(bool initialized);
2096};
2097
2119inline bool ShouldInit(InitStateRaw* state) { return SDL_ShouldInit(state); }
2120
2121inline bool InitState::ShouldInit() { return SDL::ShouldInit(this); }
2122
2142inline bool ShouldQuit(InitStateRaw* state) { return SDL_ShouldQuit(state); }
2143
2144inline bool InitState::ShouldQuit() { return SDL::ShouldQuit(this); }
2145
2163inline void SetInitialized(InitStateRaw* state, bool initialized)
2164{
2165 SDL_SetInitialized(state, initialized);
2166}
2167
2168inline void InitState::SetInitialized(bool initialized)
2169{
2170 SDL::SetInitialized(this, initialized);
2171}
2172
2174
2175} // namespace SDL
2176
2177#endif /* SDL3PP_MUTEX_H_ */
A means to block multiple threads until a condition is satisfied.
Definition: SDL3pp_mutex.h:1553
constexpr ConditionRaw get() const noexcept
Retrieves underlying ConditionRaw.
Definition: SDL3pp_mutex.h:1620
constexpr Condition(Condition &&other) noexcept
Move constructor.
Definition: SDL3pp_mutex.h:1579
constexpr Condition(std::nullptr_t) noexcept
Default ctor.
Definition: SDL3pp_mutex.h:1558
Condition & operator=(const Condition &other)=delete
Assignment operator.
constexpr ConditionRaw release() noexcept
Retrieves underlying ConditionRaw and clear this.
Definition: SDL3pp_mutex.h:1623
constexpr Condition(const Condition &other) noexcept=delete
Copy constructor.
~Condition()
Destructor.
Definition: SDL3pp_mutex.h:1607
constexpr Condition(ConditionRaw resource) noexcept
Constructs from raw Condition.
Definition: SDL3pp_mutex.h:1570
constexpr auto operator<=>(const Condition &other) const noexcept=default
Comparison.
constexpr Condition & operator=(Condition &&other) noexcept
Assignment operator.
Definition: SDL3pp_mutex.h:1610
A means to serialize access to a resource between threads.
Definition: SDL3pp_mutex.h:87
constexpr Mutex & operator=(Mutex &&other) noexcept
Assignment operator.
Definition: SDL3pp_mutex.h:150
~Mutex()
Destructor.
Definition: SDL3pp_mutex.h:147
constexpr MutexRaw get() const noexcept
Retrieves underlying MutexRaw.
Definition: SDL3pp_mutex.h:160
constexpr auto operator<=>(const Mutex &other) const noexcept=default
Comparison.
constexpr Mutex(const Mutex &other) noexcept=delete
Copy constructor.
constexpr MutexRaw release() noexcept
Retrieves underlying MutexRaw and clear this.
Definition: SDL3pp_mutex.h:163
constexpr Mutex(std::nullptr_t) noexcept
Default ctor.
Definition: SDL3pp_mutex.h:92
constexpr Mutex(MutexRaw resource) noexcept
Constructs from raw Mutex.
Definition: SDL3pp_mutex.h:104
constexpr Mutex(Mutex &&other) noexcept
Move constructor.
Definition: SDL3pp_mutex.h:113
Mutex & operator=(const Mutex &other)=delete
Assignment operator.
A mutex that allows read-only threads to run in parallel.
Definition: SDL3pp_mutex.h:480
constexpr auto operator<=>(const RWLock &other) const noexcept=default
Comparison.
~RWLock()
Destructor.
Definition: SDL3pp_mutex.h:560
constexpr RWLock(RWLock &&other) noexcept
Move constructor.
Definition: SDL3pp_mutex.h:506
constexpr RWLock(const RWLock &other) noexcept=delete
Copy constructor.
constexpr RWLock(std::nullptr_t) noexcept
Default ctor.
Definition: SDL3pp_mutex.h:485
constexpr RWLockRaw get() const noexcept
Retrieves underlying RWLockRaw.
Definition: SDL3pp_mutex.h:573
constexpr RWLock & operator=(RWLock &&other) noexcept
Assignment operator.
Definition: SDL3pp_mutex.h:563
constexpr RWLock(RWLockRaw resource) noexcept
Constructs from raw RWLock.
Definition: SDL3pp_mutex.h:497
constexpr RWLockRaw release() noexcept
Retrieves underlying RWLockRaw and clear this.
Definition: SDL3pp_mutex.h:576
RWLock & operator=(const RWLock &other)=delete
Assignment operator.
A means to manage access to a resource, by count, between threads.
Definition: SDL3pp_mutex.h:1104
constexpr Semaphore(SemaphoreRaw resource) noexcept
Constructs from raw Semaphore.
Definition: SDL3pp_mutex.h:1121
constexpr SemaphoreRaw release() noexcept
Retrieves underlying SemaphoreRaw and clear this.
Definition: SDL3pp_mutex.h:1182
constexpr Semaphore & operator=(Semaphore &&other) noexcept
Assignment operator.
Definition: SDL3pp_mutex.h:1169
~Semaphore()
Destructor.
Definition: SDL3pp_mutex.h:1166
constexpr Semaphore(const Semaphore &other) noexcept=delete
Copy constructor.
constexpr auto operator<=>(const Semaphore &other) const noexcept=default
Comparison.
Semaphore & operator=(const Semaphore &other)=delete
Assignment operator.
constexpr SemaphoreRaw get() const noexcept
Retrieves underlying SemaphoreRaw.
Definition: SDL3pp_mutex.h:1179
constexpr Semaphore(Semaphore &&other) noexcept
Move constructor.
Definition: SDL3pp_mutex.h:1130
constexpr Semaphore(std::nullptr_t=nullptr) noexcept
Default ctor.
Definition: SDL3pp_mutex.h:1109
bool ShouldQuit(InitStateRaw *state)
Return whether cleanup should be done.
Definition: SDL3pp_mutex.h:2142
void BroadcastCondition(ConditionRef cond)
Restart all threads that are waiting on the condition variable.
Definition: SDL3pp_mutex.h:1870
constexpr InitStatus INIT_STATUS_UNINITIALIZING
INIT_STATUS_UNINITIALIZING.
Definition: SDL3pp_mutex.h:1970
void Unlock()
Unlock the read/write lock.
Definition: SDL3pp_mutex.h:1064
Condition()
Create a condition variable.
Definition: SDL3pp_mutex.h:1820
constexpr InitStatus INIT_STATUS_INITIALIZING
INIT_STATUS_INITIALIZING.
Definition: SDL3pp_mutex.h:1964
void Signal()
Restart one of the threads that are waiting on the condition variable.
Definition: SDL3pp_mutex.h:1855
Mutex CreateMutex()
Create a new mutex.
Definition: SDL3pp_mutex.h:354
bool WaitTimeout(MutexRef mutex, std::chrono::milliseconds timeout)
Wait until a condition variable is signaled or a certain time has passed.
Definition: SDL3pp_mutex.h:1948
constexpr InitStatus INIT_STATUS_UNINITIALIZED
INIT_STATUS_UNINITIALIZED.
Definition: SDL3pp_mutex.h:1961
bool TryWait()
See if a semaphore has a positive value and decrement it if it does.
Definition: SDL3pp_mutex.h:1467
SDL_RWLock * RWLockRaw
Alias to raw representation for RWLock.
Definition: SDL3pp_mutex.h:43
void Destroy()
Destroy a mutex created with CreateMutex().
Definition: SDL3pp_mutex.h:457
Uint32 GetSemaphoreValue(SemaphoreRef sem)
Get the current value of a semaphore.
Definition: SDL3pp_mutex.h:1527
SDL_InitState InitStateRaw
Alias to raw representation for InitState.
Definition: SDL3pp_mutex.h:67
void Unlock()
Unlock the mutex.
Definition: SDL3pp_mutex.h:436
bool TryLockRWLockForReading(RWLockRef rwlock)
Try to lock a read/write lock for reading without blocking.
Definition: SDL3pp_mutex.h:986
void UnlockRWLock(RWLockRef rwlock)
Unlock the read/write lock.
Definition: SDL3pp_mutex.h:1062
SDL_InitStatus InitStatus
The current status of an InitState structure.
Definition: SDL3pp_mutex.h:1959
Condition CreateCondition()
Create a condition variable.
Definition: SDL3pp_mutex.h:1818
void DestroyRWLock(RWLockRaw rwlock)
Destroy a read/write lock created with CreateRWLock().
Definition: SDL3pp_mutex.h:1083
bool ShouldInit(InitStateRaw *state)
Return whether initialization should be done.
Definition: SDL3pp_mutex.h:2119
Mutex()
Create a new mutex.
Definition: SDL3pp_mutex.h:356
SDL_Condition * ConditionRaw
Alias to raw representation for Condition.
Definition: SDL3pp_mutex.h:61
void WaitSemaphore(SemaphoreRef sem)
Wait until a semaphore has a positive value and then decrements it.
Definition: SDL3pp_mutex.h:1439
bool ShouldQuit()
Return whether cleanup should be done.
Definition: SDL3pp_mutex.h:2144
void LockForReading()
Lock the read/write lock for read only operations.
Definition: SDL3pp_mutex.h:921
bool TryWaitSemaphore(SemaphoreRef sem)
See if a semaphore has a positive value and decrement it if it does.
Definition: SDL3pp_mutex.h:1462
SDL_Semaphore * SemaphoreRaw
Alias to raw representation for Semaphore.
Definition: SDL3pp_mutex.h:52
Uint32 GetValue() const
Get the current value of a semaphore.
Definition: SDL3pp_mutex.h:1532
void Wait(MutexRef mutex)
Wait until a condition variable is signaled.
Definition: SDL3pp_mutex.h:1908
bool TryLockForWriting()
Try to lock a read/write lock for writing without blocking.
Definition: SDL3pp_mutex.h:1031
void DestroyMutex(MutexRaw mutex)
Destroy a mutex created with CreateMutex().
Definition: SDL3pp_mutex.h:455
bool ShouldInit()
Return whether initialization should be done.
Definition: SDL3pp_mutex.h:2121
void LockRWLockForWriting(RWLockRef rwlock)
Lock the read/write lock for write operations.
Definition: SDL3pp_mutex.h:954
RWLock()
Create a new read/write lock.
Definition: SDL3pp_mutex.h:874
bool WaitTimeout(std::chrono::milliseconds timeout)
Wait until a semaphore has a positive value and then decrements it.
Definition: SDL3pp_mutex.h:1495
bool TryLockRWLockForWriting(RWLockRef rwlock)
Try to lock a read/write lock for writing without blocking.
Definition: SDL3pp_mutex.h:1026
Semaphore CreateSemaphore(Uint32 initial_value)
Create a semaphore.
Definition: SDL3pp_mutex.h:1391
void UnlockMutex(MutexRef mutex)
Unlock the mutex.
Definition: SDL3pp_mutex.h:434
void LockMutex(MutexRef mutex)
Lock the mutex.
Definition: SDL3pp_mutex.h:385
void Wait()
Wait until a semaphore has a positive value and then decrements it.
Definition: SDL3pp_mutex.h:1441
void SignalSemaphore(SemaphoreRef sem)
Atomically increment a semaphore's value and wake waiting threads.
Definition: SDL3pp_mutex.h:1513
constexpr InitStatus INIT_STATUS_INITIALIZED
INIT_STATUS_INITIALIZED.
Definition: SDL3pp_mutex.h:1967
void Lock()
Lock the mutex.
Definition: SDL3pp_mutex.h:387
void Destroy()
Destroy a semaphore.
Definition: SDL3pp_mutex.h:1417
void Broadcast()
Restart all threads that are waiting on the condition variable.
Definition: SDL3pp_mutex.h:1875
bool TryLockForReading()
Try to lock a read/write lock for reading without blocking.
Definition: SDL3pp_mutex.h:991
void Signal()
Atomically increment a semaphore's value and wake waiting threads.
Definition: SDL3pp_mutex.h:1515
RWLock CreateRWLock()
Create a new read/write lock.
Definition: SDL3pp_mutex.h:872
bool TryLockMutex(MutexRef mutex)
Try to lock a mutex without blocking.
Definition: SDL3pp_mutex.h:410
SDL_Mutex * MutexRaw
Alias to raw representation for Mutex.
Definition: SDL3pp_mutex.h:34
void DestroySemaphore(SemaphoreRaw sem)
Destroy a semaphore.
Definition: SDL3pp_mutex.h:1415
void LockForWriting()
Lock the read/write lock for write operations.
Definition: SDL3pp_mutex.h:959
void Destroy()
Destroy a read/write lock created with CreateRWLock().
Definition: SDL3pp_mutex.h:1085
void LockRWLockForReading(RWLockRef rwlock)
Lock the read/write lock for read only operations.
Definition: SDL3pp_mutex.h:916
void SetInitialized(InitStateRaw *state, bool initialized)
Finish an initialization state transition.
Definition: SDL3pp_mutex.h:2163
bool WaitSemaphoreTimeout(SemaphoreRef sem, std::chrono::milliseconds timeout)
Wait until a semaphore has a positive value and then decrements it.
Definition: SDL3pp_mutex.h:1489
void DestroyCondition(ConditionRaw cond)
Destroy a condition variable.
Definition: SDL3pp_mutex.h:1836
bool TryLock()
Try to lock a mutex without blocking.
Definition: SDL3pp_mutex.h:412
void Destroy()
Destroy a condition variable.
Definition: SDL3pp_mutex.h:1838
bool WaitConditionTimeout(ConditionRef cond, MutexRef mutex, std::chrono::milliseconds timeout)
Wait until a condition variable is signaled or a certain time has passed.
Definition: SDL3pp_mutex.h:1941
void SetInitialized(bool initialized)
Finish an initialization state transition.
Definition: SDL3pp_mutex.h:2168
void WaitCondition(ConditionRef cond, MutexRef mutex)
Wait until a condition variable is signaled.
Definition: SDL3pp_mutex.h:1903
void SignalCondition(ConditionRef cond)
Restart one of the threads that are waiting on the condition variable.
Definition: SDL3pp_mutex.h:1853
::Uint32 Uint32
An unsigned 32-bit integer type.
Definition: SDL3pp_stdinc.h:281
Main include header for the SDL3pp library.
Sint32 narrowS32(T value)
Narrows to Sint32.
Definition: SDL3pp_stdinc.h:6425
Reference for Condition.
Definition: SDL3pp_mutex.h:1736
constexpr ConditionRef(ConditionRaw resource) noexcept
Constructs from raw Condition.
Definition: SDL3pp_mutex.h:1746
Condition()
Create a condition variable.
Definition: SDL3pp_mutex.h:1820
constexpr ConditionRef(const Condition &resource) noexcept
Constructs from Condition.
Definition: SDL3pp_mutex.h:1758
constexpr ConditionRef(Condition &&resource) noexcept
Constructs from Condition.
Definition: SDL3pp_mutex.h:1770
ConditionRef & operator=(const ConditionRef &other) noexcept
Assignment operator.
Definition: SDL3pp_mutex.h:1791
constexpr ConditionRef(const ConditionRef &other) noexcept
Copy constructor.
Definition: SDL3pp_mutex.h:1776
~ConditionRef()
Destructor.
Definition: SDL3pp_mutex.h:1788
constexpr ConditionRef(ConditionRef &&other) noexcept
Move constructor.
Definition: SDL3pp_mutex.h:1782
A structure used for thread-safe initialization and shutdown.
Definition: SDL3pp_mutex.h:2031
Reference for Mutex.
Definition: SDL3pp_mutex.h:266
constexpr MutexRef(MutexRef &&other) noexcept
Move constructor.
Definition: SDL3pp_mutex.h:312
Mutex()
Create a new mutex.
Definition: SDL3pp_mutex.h:356
constexpr MutexRef(const MutexRef &other) noexcept
Copy constructor.
Definition: SDL3pp_mutex.h:306
MutexRef & operator=(const MutexRef &other) noexcept
Assignment operator.
Definition: SDL3pp_mutex.h:321
~MutexRef()
Destructor.
Definition: SDL3pp_mutex.h:318
constexpr MutexRef(MutexRaw resource) noexcept
Constructs from raw Mutex.
Definition: SDL3pp_mutex.h:276
constexpr MutexRef(const Mutex &resource) noexcept
Constructs from Mutex.
Definition: SDL3pp_mutex.h:288
constexpr MutexRef(Mutex &&resource) noexcept
Constructs from Mutex.
Definition: SDL3pp_mutex.h:300
Reference for RWLock.
Definition: SDL3pp_mutex.h:764
constexpr RWLockRef(RWLock &&resource) noexcept
Constructs from RWLock.
Definition: SDL3pp_mutex.h:798
constexpr RWLockRef(const RWLockRef &other) noexcept
Copy constructor.
Definition: SDL3pp_mutex.h:804
constexpr RWLockRef(RWLockRaw resource) noexcept
Constructs from raw RWLock.
Definition: SDL3pp_mutex.h:774
constexpr RWLockRef(const RWLock &resource) noexcept
Constructs from RWLock.
Definition: SDL3pp_mutex.h:786
RWLockRef & operator=(const RWLockRef &other) noexcept
Assignment operator.
Definition: SDL3pp_mutex.h:819
RWLock()
Create a new read/write lock.
Definition: SDL3pp_mutex.h:874
constexpr RWLockRef(RWLockRef &&other) noexcept
Move constructor.
Definition: SDL3pp_mutex.h:810
~RWLockRef()
Destructor.
Definition: SDL3pp_mutex.h:816
Reference for Semaphore.
Definition: SDL3pp_mutex.h:1301
constexpr SemaphoreRef(const Semaphore &resource) noexcept
Constructs from Semaphore.
Definition: SDL3pp_mutex.h:1323
constexpr SemaphoreRef(SemaphoreRaw resource) noexcept
Constructs from raw Semaphore.
Definition: SDL3pp_mutex.h:1311
constexpr SemaphoreRef(SemaphoreRef &&other) noexcept
Move constructor.
Definition: SDL3pp_mutex.h:1347
~SemaphoreRef()
Destructor.
Definition: SDL3pp_mutex.h:1353
constexpr SemaphoreRef(Semaphore &&resource) noexcept
Constructs from Semaphore.
Definition: SDL3pp_mutex.h:1335
constexpr SemaphoreRef(const SemaphoreRef &other) noexcept
Copy constructor.
Definition: SDL3pp_mutex.h:1341
SemaphoreRef & operator=(const SemaphoreRef &other) noexcept
Assignment operator.
Definition: SDL3pp_mutex.h:1356