Second Extended Filesystem (ext2) and other improvements (#33)
[lunaix-os.git] / lunaix-os / kernel / ds / semaphore.c
index 7b059a63d2c1907d0618041da6152edd3de68ff9..b4d0674438b78323eab6acbd8bd9a87c8650a1c8 100644 (file)
@@ -1,18 +1,25 @@
 #include <lunaix/ds/semaphore.h>
-#include <lunaix/sched.h>
+#include <lunaix/kpreempt.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)) {
-        schedule();
+        // FIXME: better thing like wait queue
+        preempt_current();
     }
     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