PatchworkOS
Loading...
Searching...
No Matches
mtx_unlock.c
Go to the documentation of this file.
1#include <stdatomic.h>
2#include <stdbool.h>
3#include <stdio.h>
4#include <sys/proc.h>
5#include <threads.h>
6
9
11{
12 tid_t self = gettid();
13 if (mutex->owner != self)
14 {
15 return thrd_error;
16 }
17
18 mutex->depth--;
19 if (mutex->depth > 0)
20 {
21 return thrd_success;
22 }
23 mutex->owner = ERR;
24
26 {
28 }
29 return thrd_success;
30}
#define CLOCKS_NEVER
Definition clock_t.h:16
tid_t gettid(void)
System call to retrieve the current tid.
Definition gettid.c:6
uint64_t futex(atomic_uint64_t *addr, uint64_t val, futex_op_t op, clock_t timeout)
System call for fast user space mutual exclusion.
Definition futex.c:6
@ FUTEX_WAKE
The futex operation for waking up a amount of threads specified by the val argument.
Definition proc.h:228
#define ERR
Integer error value.
Definition ERR.h:17
__UINT64_TYPE__ tid_t
Thread Identifier.
Definition tid_t.h:12
static mtx_t mutex
Definition heap.c:35
int mtx_unlock(mtx_t *mutex)
Definition mtx_unlock.c:10
#define atomic_exchange(object, desired)
Definition stdatomic.h:282
tid_t owner
Definition threads.h:54
uint64_t depth
Definition threads.h:55
atomic_uint64_t state
Definition threads.h:53
#define _MTX_UNLOCKED
Definition threads.h:47
#define _MTX_CONTESTED
Definition threads.h:49
@ thrd_success
Definition threads.h:74
@ thrd_error
Definition threads.h:76