hot fix: remove outdated objcpy
[lunaix-os.git] / lunaix-os / kernel / ds / semaphore.c
1 #include <lunaix/ds/semaphore.h>
2 #include <lunaix/sched.h>
3
4 void
5 sem_init(struct sem_t* sem, unsigned int initial)
6 {
7     sem->counter = ATOMIC_VAR_INIT(initial);
8 }
9
10 void
11 sem_wait(struct sem_t* sem)
12 {
13     while (!atomic_load(&sem->counter)) {
14         // FIXME: better thing like wait queue
15         sched_pass();
16     }
17     atomic_fetch_sub(&sem->counter, 1);
18 }
19
20 void
21 sem_post(struct sem_t* sem)
22 {
23     atomic_fetch_add(&sem->counter, 1);
24     // TODO: wake up a thread
25 }