bits/syscall.h: add landlock syscalls from linux v5.13
[musl.git] / src / thread / sem_trywait.c
blob04edf46b524de72a575b1db7687f56d93fc1e291
1 #include <semaphore.h>
2 #include "pthread_impl.h"
4 int sem_trywait(sem_t *sem)
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;
11 errno = EAGAIN;
12 return -1;