repo.or.cz
/
musl.git
/
blob
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
log
|
graphiclog1
|
graphiclog2
|
commit
|
commitdiff
|
tree
|
refs
|
edit
|
fork
blame
|
history
|
raw
|
HEAD
bits/syscall.h: add landlock syscalls from linux v5.13
[musl.git]
/
src
/
thread
/
sem_trywait.c
blob
04edf46b524de72a575b1db7687f56d93fc1e291
1
#include <semaphore.h>
2
#include
"pthread_impl.h"
3
4
int
sem_trywait
(
sem_t
*
sem
)
5
{
6
int
val
;
7
while
((
val
=
sem
->
__val
[
0
]) >
0
) {
8
int
new
=
val
-
1
-(
val
==
1
&&
sem
->
__val
[
1
]);
9
if
(
a_cas
(
sem
->
__val
,
val
,
new
)==
val
)
return
0
;
10
}
11
errno
=
EAGAIN
;
12
return
-
1
;
13
}