| Index: fusl/src/thread/sem_trywait.c
|
| diff --git a/fusl/src/thread/sem_trywait.c b/fusl/src/thread/sem_trywait.c
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..04edf46b524de72a575b1db7687f56d93fc1e291
|
| --- /dev/null
|
| +++ b/fusl/src/thread/sem_trywait.c
|
| @@ -0,0 +1,13 @@
|
| +#include <semaphore.h>
|
| +#include "pthread_impl.h"
|
| +
|
| +int sem_trywait(sem_t *sem)
|
| +{
|
| + int val;
|
| + while ((val=sem->__val[0]) > 0) {
|
| + int new = val-1-(val==1 && sem->__val[1]);
|
| + if (a_cas(sem->__val, val, new)==val) return 0;
|
| + }
|
| + errno = EAGAIN;
|
| + return -1;
|
| +}
|
|
|