1 #include <semaphore.h> 2 #include <limits.h> 3 #include "pthread_impl.h" 4 sem_trywait(sem_t * sem)5 int sem_trywait(sem_t *sem) 6 { 7 int val; 8 while ((val=sem->__val[0]) & SEM_VALUE_MAX) { 9 if (a_cas(sem->__val, val, val-1)==val) return 0; 10 } 11 errno = EAGAIN; 12 return -1; 13 } 14