ia64/xen-unstable

changeset 16441:9e88db95ddc7

[Mini-OS] Make semaphores callback-safe

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>
author Keir Fraser <keir.fraser@citrix.com>
date Sat Nov 24 13:26:39 2007 +0000 (2007-11-24)
parents 0814fb0f8a4d
children ebb61551565b
files extras/mini-os/include/semaphore.h
line diff
     1.1 --- a/extras/mini-os/include/semaphore.h	Sat Nov 24 13:23:22 2007 +0000
     1.2 +++ b/extras/mini-os/include/semaphore.h	Sat Nov 24 13:26:39 2007 +0000
     1.3 @@ -49,14 +49,25 @@ static inline void init_MUTEX(struct sem
     1.4  
     1.5  static void inline down(struct semaphore *sem)
     1.6  {
     1.7 -    wait_event(sem->wait, sem->count > 0);
     1.8 +    unsigned long flags;
     1.9 +    while (1) {
    1.10 +        wait_event(sem->wait, sem->count > 0);
    1.11 +        local_irq_save(flags);
    1.12 +        if (sem->count > 0)
    1.13 +            break;
    1.14 +        local_irq_restore(flags);
    1.15 +    }
    1.16      sem->count--;
    1.17 +    local_irq_restore(flags);
    1.18  }
    1.19  
    1.20  static void inline up(struct semaphore *sem)
    1.21  {
    1.22 +    unsigned long flags;
    1.23 +    local_irq_save(flags);
    1.24      sem->count++;
    1.25      wake_up(&sem->wait);
    1.26 +    local_irq_restore(flags);
    1.27  }
    1.28  
    1.29  /* FIXME! Thre read/write semaphores are unimplemented! */