feat: better rtc framework which aims to remove single rtc restrictions.
[lunaix-os.git] / lunaix-os / kernel / ds / semaphore.c
index 21d0e3399d761f3aaf2d3528a83dd55187144143..c3b10828cf4c753adf69859e881361d933ebe808 100644 (file)
@@ -1,17 +1,25 @@
 #include <lunaix/ds/semaphore.h>
+#include <lunaix/sched.h>
 
-void sem_init(struct sem_t *sem, unsigned int initial) {
+void
+sem_init(struct sem_t* sem, unsigned int initial)
+{
     sem->counter = ATOMIC_VAR_INIT(initial);
 }
 
-void sem_wait(struct sem_t *sem) {
+void
+sem_wait(struct sem_t* sem)
+{
     while (!atomic_load(&sem->counter)) {
-        // TODO: yield the cpu
+        // FIXME: better thing like wait queue
+        sched_yieldk();
     }
     atomic_fetch_sub(&sem->counter, 1);
 }
 
-void sem_post(struct sem_t *sem) {
+void
+sem_post(struct sem_t* sem)
+{
     atomic_fetch_add(&sem->counter, 1);
     // TODO: wake up a thread
 }
\ No newline at end of file