sync hh.org
[hh.org.git] / include / asm-cris / semaphore-helper.h
blobdbd0f30b85b6aa7653da1e85edd9165d41c9d3a4
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...
6 */
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 extern inline void wake_one_more(struct semaphore * sem)
25 atomic_inc(&sem->waking);
28 extern inline int waking_non_zero(struct semaphore *sem)
30 unsigned long flags;
31 int ret = 0;
33 local_save_flags(flags);
34 local_irq_disable();
35 if (read(&sem->waking) > 0) {
36 dec(&sem->waking);
37 ret = 1;
39 local_irq_restore(flags);
40 return ret;
43 extern inline int waking_non_zero_interruptible(struct semaphore *sem,
44 struct task_struct *tsk)
46 int ret = 0;
47 unsigned long flags;
49 local_save_flags(flags);
50 local_irq_disable();
51 if (read(&sem->waking) > 0) {
52 dec(&sem->waking);
53 ret = 1;
54 } else if (signal_pending(tsk)) {
55 inc(&sem->count);
56 ret = -EINTR;
58 local_irq_restore(flags);
59 return ret;
62 extern inline int waking_non_zero_trylock(struct semaphore *sem)
64 int ret = 1;
65 unsigned long flags;
67 local_save_flags(flags);
68 local_irq_disable();
69 if (read(&sem->waking) <= 0)
70 inc(&sem->count);
71 else {
72 dec(&sem->waking);
73 ret = 0;
75 local_irq_restore(flags);
76 return ret;
79 #endif /* _ASM_SEMAPHORE_HELPER_H */