1 /* $Id: semaphore-helper.h,v 1.3 2001/03/26 15:00:33 orjanf Exp $
3 * SMP- and interrupt-safe semaphores helper functions. Generic versions, no
4 * optimizations whatsoever...
8 #ifndef _ASM_SEMAPHORE_HELPER_H
9 #define _ASM_SEMAPHORE_HELPER_H
11 #include <asm/atomic.h>
12 #include <linux/errno.h>
14 #define read(a) ((a)->counter)
15 #define inc(a) (((a)->counter)++)
16 #define dec(a) (((a)->counter)--)
18 #define count_inc(a) ((*(a))++)
21 * These two _must_ execute atomically wrt each other.
23 static inline void wake_one_more(struct semaphore * sem)
25 atomic_inc(&sem->waking);
28 static inline int waking_non_zero(struct semaphore *sem)
33 local_irq_save(flags);
34 if (read(&sem->waking) > 0) {
38 local_irq_restore(flags);
42 static inline int waking_non_zero_interruptible(struct semaphore *sem,
43 struct task_struct *tsk)
48 local_irq_save(flags);
49 if (read(&sem->waking) > 0) {
52 } else if (signal_pending(tsk)) {
56 local_irq_restore(flags);
60 static inline int waking_non_zero_trylock(struct semaphore *sem)
65 local_irq_save(flags);
66 if (read(&sem->waking) <= 0)
72 local_irq_restore(flags);
76 #endif /* _ASM_SEMAPHORE_HELPER_H */