PatchworkOS
Loading...
Searching...
No Matches
thrd_detach.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
thrd_detach
(
thrd_t
thr)
11
{
12
_thread_t
* thread =
_thread_get
(thr.
id
);
13
if
(thread ==
NULL
)
14
{
15
return
thrd_error
;
16
}
17
18
uint64_t
expected =
_THREAD_ATTACHED
;
19
if
(!
atomic_compare_exchange_strong
(&thread->
state
, &expected,
_THREAD_DETACHED
))
20
{
21
return
thrd_error
;
22
}
23
24
return
thrd_success
;
25
}
NULL
#define NULL
Pointer error value.
Definition
NULL.h:23
_thread_get
_thread_t * _thread_get(tid_t id)
Definition
thread.c:72
proc.h
syscalls.h
thread.h
_THREAD_DETACHED
#define _THREAD_DETACHED
Definition
thread.h:19
_THREAD_ATTACHED
#define _THREAD_ATTACHED
Definition
thread.h:18
stdatomic.h
atomic_compare_exchange_strong
#define atomic_compare_exchange_strong(object, expected, desired)
Definition
stdatomic.h:278
stdbool.h
uint64_t
__UINT64_TYPE__ uint64_t
Definition
stdint.h:17
stdio.h
_thread_t
Definition
thread.h:24
_thread_t::state
atomic_uint64_t state
Definition
thread.h:26
thrd_t
Definition
threads.h:37
thrd_t::id
tid_t id
Definition
threads.h:38
thrd_detach
int thrd_detach(thrd_t thr)
Definition
thrd_detach.c:10
threads.h
thrd_success
@ thrd_success
Definition
threads.h:74
thrd_error
@ thrd_error
Definition
threads.h:76
src
libstd
user
functions
thread
thrd_detach.c
Generated by
1.9.8