summaryrefslogblamecommitdiff
path: root/src/thread/sem_trywait.c
blob: dd8f57e36a0bd54a60a5b4c21516b9a1b6a8bba5 (plain) (tree)
1
2
3
4
5
6
7
8
9
10




                           

                                                                  


                       
#include <semaphore.h>
#include "pthread_impl.h"

int sem_trywait(sem_t *sem)
{
	int val = sem->__val[0];
	if (val>0 && a_cas(sem->__val, val, val-1)==val) return 0;
	errno = EAGAIN;
	return -1;
}