PatchworkOS
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/thread.h
"
9
10
int
mtx_init
(
mtx_t
*
mutex
,
int
type)
11
{
12
(void)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
}
ERR
#define ERR
Integer error value.
Definition
ERR.h:17
mutex
static mtx_t mutex
Definition
heap.c:35
mtx_init
int mtx_init(mtx_t *mutex, int type)
Definition
mtx_init.c:10
proc.h
syscalls.h
thread.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
threads.h
_MTX_UNLOCKED
#define _MTX_UNLOCKED
Definition
threads.h:47
thrd_success
@ thrd_success
Definition
threads.h:74
src
libstd
user
functions
thread
mtx_init.c
Generated by
1.9.8