Sign in
cobalt
/
cobalt
/
fc84fc2a551a0cf60d391fb3e7d8229e6f9a9daf
/
.
/
third_party
/
musl
/
src
/
thread
/
sem_trywait.c
blob: beb435da7c14af2e25b65d1d0eea74a3d95f6aa7 [
file
] [
log
] [
blame
]
#include
<semaphore.h>
#include
<limits.h>
#include
"pthread_impl.h"
int
sem_trywait
(
sem_t
*
sem
)
{
int
val
;
while
((
val
=
sem
->
__val
[
0
])
&
SEM_VALUE_MAX
)
{
if
(
a_cas
(
sem
->
__val
,
val
,
val
-
1
)==
val
)
return
0
;
}
errno
=
EAGAIN
;
return
-
1
;
}