semaphores: fix missed wakes from ABA bug in waiter count logic
[musl] / src / thread / sem_getvalue.c
index d9d8307..c0b7762 100644 (file)
@@ -1,8 +1,9 @@
 #include <semaphore.h>
+#include <limits.h>
 
 int sem_getvalue(sem_t *restrict sem, int *restrict valp)
 {
        int val = sem->__val[0];
-       *valp = val < 0 ? 0 : val;
+       *valp = val & SEM_VALUE_MAX;
        return 0;
 }