1 #include <lunaix/ds/semaphore.h>
3 void sem_init(struct sem_t *sem, unsigned int initial) {
4 sem->counter = ATOMIC_VAR_INIT(initial);
7 void sem_wait(struct sem_t *sem) {
8 while (!atomic_load(&sem->counter)) {
11 atomic_fetch_sub(&sem->counter, 1);
14 void sem_post(struct sem_t *sem) {
15 atomic_fetch_add(&sem->counter, 1);
16 // TODO: wake up a thread