blob: 999f5dcb0b223c02872bd3c3d7dab305f566560e (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
# Mutex
---
## Object Definitions
```c
typedef struct {
kpl_atomic_queue queue;
_Atomic int32_t lock;
} kpl_mutex;
```
## Usage
1. Before adding to the `queue` do `value = lock++`
2. Add to the queue
3. If `value` is `0` the thread does an async schedule of the mutex task, otherwise the thread moves on
### Mutex Task
1. Get task from `queue` and run task
2. After task completion, do `value = --lock`, stop if `value` is `0`, otherwise repeat
|