8
8
#if defined(TEMPEST_WIN_THREADS)
9
9
#include < windows.h>
10
10
#elif defined(TEMPEST_POSIX_THREADS)
11
-
11
+ # include < pthread.h >
12
12
#else
13
13
#error "Unsupported platform"
14
14
#endif
@@ -21,6 +21,7 @@ namespace tempest
21
21
#if defined(TEMPEST_WIN_THREADS)
22
22
using native_handle_type = HANDLE;
23
23
#elif defined(TEMPEST_POSIX_THREADS)
24
+ using native_handle_type = pthread_mutex_t ;
24
25
#else
25
26
#error "Unsupported platform"
26
27
#endif
@@ -42,6 +43,7 @@ namespace tempest
42
43
};
43
44
44
45
#if defined(TEMPEST_WIN_THREADS)
46
+
45
47
inline constexpr mutex::mutex () noexcept
46
48
{
47
49
if (is_constant_evaluated ())
@@ -53,7 +55,21 @@ namespace tempest
53
55
_handle = CreateMutexW (nullptr , FALSE , nullptr );
54
56
}
55
57
}
58
+
56
59
#elif defined(TEMPEST_POSIX_THREADS)
60
+
61
+ inline constexpr mutex::mutex () noexcept
62
+ {
63
+ if (is_constant_evaluated ())
64
+ {
65
+ _handle = {};
66
+ }
67
+ else
68
+ {
69
+ pthread_mutex_init (&_handle, nullptr );
70
+ }
71
+ }
72
+
57
73
#else
58
74
#error "Unsupported platform"
59
75
#endif
@@ -69,6 +85,7 @@ namespace tempest
69
85
#if defined(TEMPEST_WIN_THREADS)
70
86
using native_handle_type = SRWLOCK;
71
87
#elif defined(TEMPEST_POSIX_THREADS)
88
+ using native_handle_type = pthread_rwlock_t ;
72
89
#else
73
90
#error "Unsupported platform"
74
91
#endif
@@ -94,6 +111,7 @@ namespace tempest
94
111
};
95
112
96
113
#if defined(TEMPEST_WIN_THREADS)
114
+
97
115
inline constexpr shared_mutex::shared_mutex () noexcept
98
116
{
99
117
if (is_constant_evaluated ())
@@ -105,7 +123,21 @@ namespace tempest
105
123
InitializeSRWLock (&_handle);
106
124
}
107
125
}
126
+
108
127
#elif defined(TEMPEST_POSIX_THREADS)
128
+
129
+ inline constexpr shared_mutex::shared_mutex () noexcept
130
+ {
131
+ if (is_constant_evaluated ())
132
+ {
133
+ _handle = {};
134
+ }
135
+ else
136
+ {
137
+ pthread_rwlock_init (&_handle, nullptr );
138
+ }
139
+ }
140
+
109
141
#else
110
142
#error "Unsupported platform"
111
143
#endif
@@ -228,7 +260,7 @@ namespace tempest
228
260
template <lockable Mutex>
229
261
inline unique_lock<Mutex>::unique_lock(mutex_type& m) : _mutex{&m}
230
262
{
231
- _mutex. lock ();
263
+ _mutex-> lock ();
232
264
_owns_lock = true ;
233
265
}
234
266
@@ -247,7 +279,7 @@ namespace tempest
247
279
{
248
280
if (_owns_lock)
249
281
{
250
- _mutex. unlock ();
282
+ _mutex-> unlock ();
251
283
}
252
284
253
285
_mutex = nullptr ;
@@ -264,7 +296,7 @@ namespace tempest
264
296
265
297
if (_owns_lock)
266
298
{
267
- _mutex. unlock ();
299
+ _mutex-> unlock ();
268
300
}
269
301
270
302
_mutex = exchange (rhs._mutex , nullptr );
@@ -281,7 +313,7 @@ namespace tempest
281
313
std::terminate ();
282
314
}
283
315
284
- _mutex. lock ();
316
+ _mutex-> lock ();
285
317
_owns_lock = true ;
286
318
}
287
319
@@ -292,7 +324,7 @@ namespace tempest
292
324
{
293
325
std::terminate ();
294
326
}
295
- _owns_lock = _mutex. try_lock ();
327
+ _owns_lock = _mutex-> try_lock ();
296
328
return _owns_lock;
297
329
}
298
330
@@ -303,7 +335,7 @@ namespace tempest
303
335
{
304
336
std::terminate ();
305
337
}
306
- _mutex. unlock ();
338
+ _mutex-> unlock ();
307
339
_owns_lock = false ;
308
340
}
309
341
0 commit comments