projects
/
oweals
/
musl.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
synchronize cond var destruction with exiting waits
[oweals/musl.git]
/
src
/
thread
/
sem_trywait.c
diff --git
a/src/thread/sem_trywait.c
b/src/thread/sem_trywait.c
index d0e928ef67d2048f4bbf1f1214a30407d8dbe7c8..55d90075e274a5e0a82359ffc96e6b45a279e286 100644
(file)
--- a/
src/thread/sem_trywait.c
+++ b/
src/thread/sem_trywait.c
@@
-3,9
+3,11
@@
int sem_trywait(sem_t *sem)
{
int sem_trywait(sem_t *sem)
{
- int val = a_fetch_add(sem->__val, -1);
- if (val > 0) return 0;
- a_inc(sem->__val);
+ int val = sem->__val[0];
+ if (val>0) {
+ int new = val-1-(val==1 && sem->__val[1]);
+ if (a_cas(sem->__val, val, new)==val) return 0;
+ }
errno = EAGAIN;
return -1;
}
errno = EAGAIN;
return -1;
}