PatchworkOS
19e446b
A non-POSIX operating system.
Theme:
Default
Round
Robot
Loading...
Searching...
No Matches
mtx_init.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
7
#include "
user/common/syscalls.h
"
8
#include "
user/common/threading.h
"
9
10
int
mtx_init
(
mtx_t
* mutex,
int
type)
11
{
12
UNUSED
(type);
// We don't care about the type, we just implement all types the same way as the C specifcation says
13
// that, for example, if a non-recursive mutex is locked recursively, the behavior is undefined so we
14
// just say that it works.
15
16
atomic_init
(&mutex->
state
,
_MTX_UNLOCKED
);
17
mutex->
owner
=
ERR
;
18
mutex->
depth
= 0;
19
20
return
thrd_success
;
21
}
UNUSED
#define UNUSED(x)
Mark a variable as unused.
Definition
defs.h:96
ERR
#define ERR
Integer error value.
Definition
ERR.h:17
mtx_init
int mtx_init(mtx_t *mutex, int type)
Definition
mtx_init.c:10
proc.h
stdatomic.h
atomic_init
#define atomic_init(obj, value)
Definition
stdatomic.h:75
stdbool.h
stdio.h
mtx_t
Definition
threads.h:52
mtx_t::owner
tid_t owner
Definition
threads.h:54
mtx_t::depth
uint64_t depth
Definition
threads.h:55
mtx_t::state
atomic_uint64_t state
Definition
threads.h:53
syscalls.h
threading.h
threads.h
thrd_success
@ thrd_success
Definition
threads.h:74
_MTX_UNLOCKED
#define _MTX_UNLOCKED
Definition
threads.h:47
src
libstd
user
functions
thread
mtx_init.c
Generated on Sat Jan 24 2026 10:59:25 for PatchworkOS by
1.9.8