1 /* Based on M68K version, Lineo Inc. May 2001 */
3 #ifndef _BFIN_SEMAPHORE_HELPER_H
4 #define _BFIN_SEMAPHORE_HELPER_H
7 * SMP- and interrupt-safe semaphores helper functions.
9 * (C) Copyright 1996 Linus Torvalds
13 #include <asm/errno.h>
16 * These two _must_ execute atomically wrt each other.
18 static inline void wake_one_more(struct semaphore *sem)
20 atomic_inc(&sem->waking);
23 static inline int waking_non_zero(struct semaphore *sem)
26 unsigned long flags = 0;
28 spin_lock_irqsave(&semaphore_wake_lock, flags);
30 if (atomic_read(&sem->waking) > 0) {
31 atomic_dec(&sem->waking);
34 spin_unlock_irqrestore(&semaphore_wake_lock, flags);
39 * waking_non_zero_interruptible:
44 static inline int waking_non_zero_interruptible(struct semaphore *sem,
45 struct task_struct *tsk)
48 unsigned long flags = 0;
50 spin_lock_irqsave(&semaphore_wake_lock, flags);
51 if (atomic_read(&sem->waking) > 0) {
52 atomic_dec(&sem->waking);
54 } else if (signal_pending(tsk)) {
55 atomic_inc(&sem->count);
58 spin_unlock_irqrestore(&semaphore_wake_lock, flags);
63 * waking_non_zero_trylock:
67 static inline int waking_non_zero_trylock(struct semaphore *sem)
70 unsigned long flags = 0;
72 spin_lock_irqsave(&semaphore_wake_lock, flags);
73 if (atomic_read(&sem->waking) > 0) {
74 atomic_dec(&sem->waking);
77 atomic_inc(&sem->count);
78 spin_unlock_irqrestore(&semaphore_wake_lock, flags);
82 #endif /* _BFIN_SEMAPHORE_HELPER_H */