-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathstk_c_sync.cpp
More file actions
785 lines (599 loc) · 17.9 KB
/
Copy pathstk_c_sync.cpp
File metadata and controls
785 lines (599 loc) · 17.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
/*
* SuperTinyKernel(TM) RTOS: Lightweight High-Performance Deterministic C++ RTOS for Embedded Systems.
*
* Source: https://github.com/SuperTinyKernel-RTOS
*
* Copyright (c) 2022-2026 Neutron Code Limited <stk@neutroncode.com>. All Rights Reserved.
* License: MIT License, see LICENSE for a full text.
*/
#include <cstddef> // for std::size_t
#include "stk_config.h"
#include "stk.h"
#include "sync/stk_sync.h"
#include "memory/stk_memory.h"
#include "stk_c.h"
using namespace stk;
using namespace stk::sync;
// =============================================================================
// C-interface
// =============================================================================
extern "C" {
// -----------------------------------------------------------------------------
// Mutex
// -----------------------------------------------------------------------------
struct stk_mutex_t
{
Mutex handle;
};
stk_mutex_t *stk_mutex_create(stk_mutex_mem_t *memory, uint32_t memory_size)
{
STK_ASSERT(memory != nullptr);
STK_ASSERT(memory_size >= sizeof(stk_mutex_t));
if (memory_size < sizeof(stk_mutex_t))
return nullptr;
return new (memory->data) stk_mutex_t();
}
void stk_mutex_destroy(stk_mutex_t *mtx)
{
if (mtx != NULL)
mtx->~stk_mutex_t();
}
void stk_mutex_lock(stk_mutex_t *mtx)
{
STK_ASSERT(mtx != NULL);
mtx->handle.Lock();
}
bool stk_mutex_trylock(stk_mutex_t *mtx)
{
STK_ASSERT(mtx != NULL);
return mtx->handle.TryLock();
}
void stk_mutex_unlock(stk_mutex_t *mtx)
{
STK_ASSERT(mtx != NULL);
mtx->handle.Unlock();
}
bool stk_mutex_timed_lock(stk_mutex_t *mtx, stk_timeout_t timeout)
{
STK_ASSERT(mtx != NULL);
return mtx->handle.TimedLock(timeout);
}
// -----------------------------------------------------------------------------
// SpinLock
// -----------------------------------------------------------------------------
struct stk_spinlock_t
{
sync::SpinLock handle;
};
stk_spinlock_t *stk_spinlock_create(stk_spinlock_mem_t *memory, uint32_t memory_size)
{
STK_ASSERT(memory != nullptr);
STK_ASSERT(memory_size >= sizeof(stk_spinlock_t));
if (memory_size < sizeof(stk_spinlock_t))
return nullptr;
return new (memory->data) stk_spinlock_t();
}
void stk_spinlock_destroy(stk_spinlock_t *lock)
{
if (lock != nullptr)
lock->~stk_spinlock_t();
}
void stk_spinlock_lock(stk_spinlock_t *lock)
{
STK_ASSERT(lock != nullptr);
lock->handle.Lock();
}
bool stk_spinlock_trylock(stk_spinlock_t *lock)
{
STK_ASSERT(lock != nullptr);
return lock->handle.TryLock();
}
void stk_spinlock_unlock(stk_spinlock_t *lock)
{
STK_ASSERT(lock != nullptr);
lock->handle.Unlock();
}
// -----------------------------------------------------------------------------
// ConditionVariable
// -----------------------------------------------------------------------------
struct stk_cv_t
{
ConditionVariable handle;
};
stk_cv_t *stk_cv_create(stk_cv_mem_t *memory, uint32_t memory_size)
{
STK_ASSERT(memory != nullptr);
STK_ASSERT(memory_size >= sizeof(stk_cv_t));
if (memory_size < sizeof(stk_cv_t))
return nullptr;
return new (memory->data) stk_cv_t();
}
void stk_cv_destroy(stk_cv_t *cv)
{
if (cv != nullptr)
cv->~stk_cv_t();
}
bool stk_cv_wait(stk_cv_t *cv, stk_mutex_t *mtx, stk_timeout_t timeout)
{
STK_ASSERT(cv != nullptr);
STK_ASSERT(mtx != nullptr);
return cv->handle.Wait(mtx->handle, timeout);
}
void stk_cv_notify_one(stk_cv_t *cv)
{
STK_ASSERT(cv != nullptr);
cv->handle.NotifyOne();
}
void stk_cv_notify_all(stk_cv_t *cv)
{
STK_ASSERT(cv != nullptr);
cv->handle.NotifyAll();
}
// -----------------------------------------------------------------------------
// Event
// -----------------------------------------------------------------------------
struct stk_event_t
{
stk_event_t(bool manual_reset) : handle(manual_reset)
{}
Event handle;
};
stk_event_t *stk_event_create(stk_event_mem_t *memory, uint32_t memory_size, bool manual_reset)
{
STK_ASSERT(memory != nullptr);
STK_ASSERT(memory_size >= sizeof(stk_event_t));
if (memory_size < sizeof(stk_event_t))
return nullptr;
return new (memory->data) stk_event_t(manual_reset);
}
void stk_event_destroy(stk_event_t *ev)
{
if (ev != nullptr)
ev->~stk_event_t();
}
bool stk_event_wait(stk_event_t *ev, stk_timeout_t timeout)
{
STK_ASSERT(ev != nullptr);
return ev->handle.Wait(timeout);
}
bool stk_event_trywait(stk_event_t *ev)
{
STK_ASSERT(ev != nullptr);
return ev->handle.TryWait();
}
void stk_event_set(stk_event_t *ev)
{
STK_ASSERT(ev != nullptr);
ev->handle.Set();
}
void stk_event_reset(stk_event_t *ev)
{
STK_ASSERT(ev != nullptr);
ev->handle.Reset();
}
void stk_event_pulse(stk_event_t *ev)
{
STK_ASSERT(ev != nullptr);
ev->handle.Pulse();
}
// -----------------------------------------------------------------------------
// Semaphore
// -----------------------------------------------------------------------------
struct stk_sem_t
{
stk_sem_t(uint32_t initial_count, uint32_t max_count)
: handle(static_cast<uint16_t>(initial_count),
static_cast<uint16_t>(max_count))
{}
Semaphore handle;
};
stk_sem_t *stk_sem_create(stk_sem_mem_t *memory, uint32_t memory_size,
uint32_t initial_count, uint32_t max_count)
{
STK_ASSERT(memory != nullptr);
STK_ASSERT(memory_size >= sizeof(stk_sem_t));
STK_ASSERT(initial_count < (max_count == 0U ? Semaphore::COUNT_MAX : max_count));
if (memory_size < sizeof(stk_sem_t))
return nullptr;
const uint32_t effective_max = (max_count == 0U) ? Semaphore::COUNT_MAX : max_count;
return new (memory->data) stk_sem_t(initial_count, effective_max);
}
void stk_sem_destroy(stk_sem_t *sem)
{
if (sem != nullptr)
sem->~stk_sem_t();
}
bool stk_sem_wait(stk_sem_t *sem, stk_timeout_t timeout)
{
STK_ASSERT(sem != nullptr);
return sem->handle.Wait(timeout);
}
bool stk_sem_trywait(stk_sem_t *sem)
{
STK_ASSERT(sem != nullptr);
return sem->handle.TryWait();
}
void stk_sem_signal(stk_sem_t *sem)
{
STK_ASSERT(sem != nullptr);
sem->handle.Signal();
}
uint16_t stk_sem_get_count(const stk_sem_t *sem)
{
STK_ASSERT(sem != nullptr);
return sem->handle.GetCount();
}
// -----------------------------------------------------------------------------
// EventFlags
// -----------------------------------------------------------------------------
struct stk_ef_t
{
stk_ef_t(uint32_t initial_flags) : handle(initial_flags)
{}
EventFlags handle;
};
stk_ef_t *stk_ef_create(stk_ef_mem_t *memory, uint32_t memory_size, uint32_t initial_flags)
{
STK_ASSERT(memory != nullptr);
STK_ASSERT(memory_size >= sizeof(stk_ef_t));
if (memory_size < sizeof(stk_ef_t))
return nullptr;
return new (memory->data) stk_ef_t(initial_flags);
}
void stk_ef_destroy(stk_ef_t *ef)
{
if (ef != nullptr)
ef->~stk_ef_t();
}
uint32_t stk_ef_set(stk_ef_t *ef, uint32_t flags)
{
STK_ASSERT(ef != nullptr);
return ef->handle.Set(flags);
}
uint32_t stk_ef_clear(stk_ef_t *ef, uint32_t flags)
{
STK_ASSERT(ef != nullptr);
return ef->handle.Clear(flags);
}
uint32_t stk_ef_get(stk_ef_t *ef)
{
STK_ASSERT(ef != nullptr);
return ef->handle.Get();
}
uint32_t stk_ef_wait(stk_ef_t *ef, uint32_t flags, uint32_t options, stk_timeout_t timeout)
{
STK_ASSERT(ef != nullptr);
return ef->handle.Wait(flags, options, timeout);
}
uint32_t stk_ef_trywait(stk_ef_t *ef, uint32_t flags, uint32_t options)
{
STK_ASSERT(ef != nullptr);
return ef->handle.TryWait(flags, options);
}
// -----------------------------------------------------------------------------
// Pipe (runtime-sized, external-buffer; wraps sync::Pipe)
// -----------------------------------------------------------------------------
struct stk_pipe_t
{
Pipe handle;
stk_pipe_t(uint8_t *buf, size_t capacity, size_t element_size)
: handle(buf, capacity, element_size)
{}
};
stk_pipe_t *stk_pipe_create(stk_pipe_mem_t *memory,
uint32_t memory_size,
uint8_t *buf,
uint32_t buf_size,
size_t capacity,
size_t element_size)
{
STK_ASSERT(memory != nullptr);
STK_ASSERT(buf != nullptr);
STK_ASSERT(capacity >= 1U);
STK_ASSERT(element_size >= 1U);
STK_ASSERT(memory_size >= sizeof(stk_pipe_t));
STK_ASSERT(buf_size >= capacity * element_size);
if ((memory_size < sizeof(stk_pipe_t)) || (buf_size < (capacity * element_size)))
return nullptr;
return new (memory->data) stk_pipe_t(buf, capacity, element_size);
}
void stk_pipe_destroy(stk_pipe_t *pipe)
{
if (pipe != nullptr)
pipe->~stk_pipe_t();
}
bool stk_pipe_write(stk_pipe_t *pipe, const void *data, stk_timeout_t timeout)
{
STK_ASSERT(pipe != nullptr);
STK_ASSERT(data != nullptr);
return pipe->handle.Write(data, timeout);
}
bool stk_pipe_trywrite(stk_pipe_t *pipe, const void *data)
{
STK_ASSERT(pipe != nullptr);
STK_ASSERT(data != nullptr);
return pipe->handle.TryWrite(data);
}
bool stk_pipe_read(stk_pipe_t *pipe, void *data, stk_timeout_t timeout)
{
STK_ASSERT(pipe != nullptr);
STK_ASSERT(data != nullptr);
return pipe->handle.Read(data, timeout);
}
bool stk_pipe_tryread(stk_pipe_t *pipe, void *data)
{
STK_ASSERT(pipe != nullptr);
STK_ASSERT(data != nullptr);
return pipe->handle.TryRead(data);
}
size_t stk_pipe_write_bulk(stk_pipe_t *pipe, const void *src, size_t count, stk_timeout_t timeout)
{
STK_ASSERT(pipe != nullptr);
return pipe->handle.WriteBulk(src, count, timeout);
}
size_t stk_pipe_trywrite_bulk(stk_pipe_t *pipe, const void *src, size_t count)
{
STK_ASSERT(pipe != nullptr);
return pipe->handle.TryWriteBulk(src, count);
}
size_t stk_pipe_read_bulk(stk_pipe_t *pipe, void *dst, size_t count, stk_timeout_t timeout)
{
STK_ASSERT(pipe != nullptr);
return pipe->handle.ReadBulk(dst, count, timeout);
}
size_t stk_pipe_tryread_bulk(stk_pipe_t *pipe, void *dst, size_t count)
{
STK_ASSERT(pipe != nullptr);
return pipe->handle.TryReadBulk(dst, count);
}
size_t stk_pipe_read_bulk_triggered(stk_pipe_t *pipe, void *dst,
size_t trigger, size_t max_count, stk_timeout_t timeout)
{
STK_ASSERT(pipe != nullptr);
return pipe->handle.ReadBulkTriggered(dst, trigger, max_count, timeout);
}
size_t stk_pipe_tryread_bulk_triggered(stk_pipe_t *pipe, void *dst, size_t max_count)
{
STK_ASSERT(pipe != nullptr);
return pipe->handle.TryReadBulkTriggered(dst, max_count);
}
void stk_pipe_reset(stk_pipe_t *pipe)
{
STK_ASSERT(pipe != nullptr);
pipe->handle.Reset();
}
size_t stk_pipe_get_capacity(const stk_pipe_t *pipe)
{
STK_ASSERT(pipe != nullptr);
return pipe->handle.GetCapacity();
}
size_t stk_pipe_get_element_size(const stk_pipe_t *pipe)
{
STK_ASSERT(pipe != nullptr);
return pipe->handle.GetElementSize();
}
size_t stk_pipe_get_count(const stk_pipe_t *pipe)
{
STK_ASSERT(pipe != nullptr);
return pipe->handle.GetCount();
}
size_t stk_pipe_get_space(const stk_pipe_t *pipe)
{
STK_ASSERT(pipe != nullptr);
return pipe->handle.GetSpace();
}
bool stk_pipe_is_empty(const stk_pipe_t *pipe)
{
STK_ASSERT(pipe != nullptr);
return pipe->handle.IsEmpty();
}
bool stk_pipe_is_full(const stk_pipe_t *pipe)
{
STK_ASSERT(pipe != nullptr);
return pipe->handle.IsFull();
}
bool stk_pipe_is_storage_valid(const stk_pipe_t *pipe)
{
STK_ASSERT(pipe != nullptr);
return pipe->handle.IsStorageValid();
}
// -----------------------------------------------------------------------------
// MessageQueue
// -----------------------------------------------------------------------------
struct stk_msgq_t
{
stk_msgq_t(uint8_t *buf, size_t capacity, size_t msg_size)
: handle(buf, capacity, msg_size)
{}
MessageQueue handle;
};
stk_msgq_t *stk_msgq_create(stk_msgq_mem_t *memory,
uint32_t memory_size,
uint8_t *buf,
uint32_t buf_size,
size_t capacity,
size_t msg_size)
{
STK_ASSERT(memory != nullptr);
STK_ASSERT(buf != nullptr);
STK_ASSERT(capacity >= 1U);
STK_ASSERT(msg_size >= 1U);
STK_ASSERT(memory_size >= sizeof(stk_msgq_t));
STK_ASSERT(buf_size >= capacity * msg_size);
if ((memory_size < sizeof(stk_msgq_t)) || (buf_size < (capacity * msg_size)))
return nullptr;
return new (memory) stk_msgq_t(buf, capacity, msg_size);
}
void stk_msgq_destroy(stk_msgq_t *mq)
{
if (mq != nullptr)
mq->~stk_msgq_t();
}
bool stk_msgq_put(stk_msgq_t *mq, const void *msg, stk_timeout_t timeout)
{
STK_ASSERT(mq != nullptr);
STK_ASSERT(msg != nullptr);
return reinterpret_cast<stk_msgq_t *>(mq)->handle.Put(msg, timeout);
}
bool stk_msgq_tryput(stk_msgq_t *mq, const void *msg)
{
STK_ASSERT(mq != nullptr);
STK_ASSERT(msg != nullptr);
return reinterpret_cast<stk_msgq_t *>(mq)->handle.TryPut(msg);
}
bool stk_msgq_putfront(stk_msgq_t *mq, const void *msg, stk_timeout_t timeout)
{
STK_ASSERT(mq != nullptr);
STK_ASSERT(msg != nullptr);
return reinterpret_cast<stk_msgq_t *>(mq)->handle.PutFront(msg, timeout);
}
bool stk_msgq_tryputfront(stk_msgq_t *mq, const void *msg)
{
STK_ASSERT(mq != nullptr);
STK_ASSERT(msg != nullptr);
return reinterpret_cast<stk_msgq_t *>(mq)->handle.TryPutFront(msg);
}
bool stk_msgq_get(stk_msgq_t *mq, void *msg, stk_timeout_t timeout)
{
STK_ASSERT(mq != nullptr);
STK_ASSERT(msg != nullptr);
return reinterpret_cast<stk_msgq_t *>(mq)->handle.Get(msg, timeout);
}
bool stk_msgq_tryget(stk_msgq_t *mq, void *msg)
{
STK_ASSERT(mq != nullptr);
STK_ASSERT(msg != nullptr);
return reinterpret_cast<stk_msgq_t *>(mq)->handle.TryGet(msg);
}
bool stk_msgq_peek(stk_msgq_t *mq, void *msg, stk_timeout_t timeout)
{
STK_ASSERT(mq != nullptr);
STK_ASSERT(msg != nullptr);
return reinterpret_cast<stk_msgq_t *>(mq)->handle.Peek(msg, timeout);
}
bool stk_msgq_trypeek(stk_msgq_t *mq, void *msg)
{
STK_ASSERT(mq != nullptr);
STK_ASSERT(msg != nullptr);
return reinterpret_cast<stk_msgq_t *>(mq)->handle.TryPeek(msg);
}
bool stk_msgq_peekfront(stk_msgq_t *mq, void *msg, stk_timeout_t timeout)
{
STK_ASSERT(mq != nullptr);
STK_ASSERT(msg != nullptr);
return reinterpret_cast<stk_msgq_t *>(mq)->handle.PeekFront(msg, timeout);
}
bool stk_msgq_trypeekfront(stk_msgq_t *mq, void *msg)
{
STK_ASSERT(mq != nullptr);
STK_ASSERT(msg != nullptr);
return reinterpret_cast<stk_msgq_t *>(mq)->handle.TryPeekFront(msg);
}
void stk_msgq_reset(stk_msgq_t *mq)
{
STK_ASSERT(mq != nullptr);
reinterpret_cast<stk_msgq_t *>(mq)->handle.Reset();
}
size_t stk_msgq_get_capacity(const stk_msgq_t *mq)
{
STK_ASSERT(mq != nullptr);
return reinterpret_cast<const stk_msgq_t *>(mq)->handle.GetCapacity();
}
size_t stk_msgq_get_msg_size(const stk_msgq_t *mq)
{
STK_ASSERT(mq != nullptr);
return reinterpret_cast<const stk_msgq_t *>(mq)->handle.GetMsgSize();
}
size_t stk_msgq_get_count(const stk_msgq_t *mq)
{
STK_ASSERT(mq != nullptr);
return reinterpret_cast<const stk_msgq_t *>(mq)->handle.GetCount();
}
size_t stk_msgq_get_space(const stk_msgq_t *mq)
{
STK_ASSERT(mq != nullptr);
return reinterpret_cast<const stk_msgq_t *>(mq)->handle.GetSpace();
}
bool stk_msgq_is_empty(const stk_msgq_t *mq)
{
STK_ASSERT(mq != nullptr);
return reinterpret_cast<const stk_msgq_t *>(mq)->handle.IsEmpty();
}
bool stk_msgq_is_full(const stk_msgq_t *mq)
{
STK_ASSERT(mq != nullptr);
return reinterpret_cast<const stk_msgq_t *>(mq)->handle.IsFull();
}
uint8_t *stk_msgq_get_buffer(stk_msgq_t *mq)
{
STK_ASSERT(mq != nullptr);
return reinterpret_cast<stk_msgq_t *>(mq)->handle.GetBuffer();
}
bool stk_msgq_is_storage_valid(const stk_msgq_t *mq)
{
STK_ASSERT(mq != nullptr);
return reinterpret_cast<const stk_msgq_t *>(mq)->handle.IsStorageValid();
}
// -----------------------------------------------------------------------------
// RWMutex (Reader-Writer Lock)
// -----------------------------------------------------------------------------
struct stk_rwmutex_t
{
sync::RWMutex handle;
};
stk_rwmutex_t *stk_rwmutex_create(stk_rwmutex_mem_t *memory, uint32_t memory_size)
{
STK_ASSERT(memory != nullptr);
STK_ASSERT(memory_size >= sizeof(stk_rwmutex_t));
if (memory_size < sizeof(stk_rwmutex_t))
return nullptr;
return (stk_rwmutex_t *)new (memory->data) stk_rwmutex_t();
}
void stk_rwmutex_destroy(stk_rwmutex_t *rw)
{
if (rw != nullptr)
rw->~stk_rwmutex_t();
}
void stk_rwmutex_read_lock(stk_rwmutex_t *rw)
{
STK_ASSERT(rw != nullptr);
rw->handle.ReadLock();
}
bool stk_rwmutex_try_read_lock(stk_rwmutex_t *rw)
{
STK_ASSERT(rw != nullptr);
return rw->handle.TryReadLock();
}
bool stk_rwmutex_timed_read_lock(stk_rwmutex_t *rw, stk_timeout_t timeout)
{
STK_ASSERT(rw != nullptr);
return rw->handle.TimedReadLock(timeout);
}
void stk_rwmutex_read_unlock(stk_rwmutex_t *rw)
{
STK_ASSERT(rw != nullptr);
rw->handle.ReadUnlock();
}
void stk_rwmutex_lock(stk_rwmutex_t *rw)
{
STK_ASSERT(rw != nullptr);
rw->handle.Lock();
}
bool stk_rwmutex_trylock(stk_rwmutex_t *rw)
{
STK_ASSERT(rw != nullptr);
return rw->handle.TryLock();
}
bool stk_rwmutex_timed_lock(stk_rwmutex_t *rw, stk_timeout_t timeout)
{
STK_ASSERT(rw != nullptr);
return rw->handle.TimedLock(timeout);
}
void stk_rwmutex_unlock(stk_rwmutex_t *rw)
{
STK_ASSERT(rw != nullptr);
rw->handle.Unlock();
}
// =============================================================================
} // extern "C"
// =============================================================================