1 #include <lunaix/ds/semaphore.h>
2 #include <lunaix/sched.h>
5 sem_init(struct sem_t* sem, unsigned int initial)
7 sem->counter = ATOMIC_VAR_INIT(initial);
11 sem_wait(struct sem_t* sem)
13 while (!atomic_load(&sem->counter)) {
14 // FIXME: better thing like wait queue
17 atomic_fetch_sub(&sem->counter, 1);
21 sem_post(struct sem_t* sem)
23 atomic_fetch_add(&sem->counter, 1);
24 // TODO: wake up a thread