1 #include <semaphore.h>
2 
3 #include <stdatomic.h>
4 
sem_getvalue(sem_t * restrict sem,int * restrict valp)5 int sem_getvalue(sem_t* restrict sem, int* restrict valp) {
6     int val = atomic_load(&sem->_s_value);
7     *valp = val < 0 ? 0 : val;
8     return 0;
9 }
10