]> xenbits.xensource.com Git - xen.git/commitdiff
[Mini-OS] Make semaphores callback-safe
authorKeir Fraser <keir.fraser@citrix.com>
Sat, 24 Nov 2007 13:26:39 +0000 (13:26 +0000)
committerKeir Fraser <keir.fraser@citrix.com>
Sat, 24 Nov 2007 13:26:39 +0000 (13:26 +0000)
One may want to use semaphores in event handlers to wake threads
waiting for a resource, so semaphores then need to be callback-safe.

Signed-off-by: Samuel Thibault <samuel.thibault@citrix.com>
extras/mini-os/include/semaphore.h

index 47365d25fdc257bccf7398242af0c305a5a48613..2c6394265ec42b441f9a0f6f21c3f352ea9adb1c 100644 (file)
@@ -49,14 +49,25 @@ static inline void init_MUTEX(struct semaphore *sem)
 
 static void inline down(struct semaphore *sem)
 {
-    wait_event(sem->wait, sem->count > 0);
+    unsigned long flags;
+    while (1) {
+        wait_event(sem->wait, sem->count > 0);
+        local_irq_save(flags);
+        if (sem->count > 0)
+            break;
+        local_irq_restore(flags);
+    }
     sem->count--;
+    local_irq_restore(flags);
 }
 
 static void inline up(struct semaphore *sem)
 {
+    unsigned long flags;
+    local_irq_save(flags);
     sem->count++;
     wake_up(&sem->wait);
+    local_irq_restore(flags);
 }
 
 /* FIXME! Thre read/write semaphores are unimplemented! */