Gitiles
Code Review
Sign In
gerrit-public.fairphone.software
/
platform
/
external
/
musl
/
6d6102427d8d5450bd28788c792f97ef90cce274
/
.
/
src
/
thread
/
sem_trywait.c
blob: 04edf46b524de72a575b1db7687f56d93fc1e291 [
file
] [
log
] [
blame
]
#include
<semaphore.h>
#include
"pthread_impl.h"
int
sem_trywait
(
sem_t
*
sem
)
{
int
val
;
while
((
val
=
sem
->
__val
[
0
])
>
0
)
{
int
new
=
val
-
1
-(
val
==
1
&&
sem
->
__val
[
1
]);
if
(
a_cas
(
sem
->
__val
,
val
,
new
)==
val
)
return
0
;
}
errno
=
EAGAIN
;
return
-
1
;
}