nspy-version-c.patch
[linux-2.6/openmoko-kernel/knife-kernel.git] / include / asm-blackfin / semaphore-helper.h
blob9082b0dc3eb5243fa33675c887432c750af2f199
1 /* Based on M68K version, Lineo Inc. May 2001 */
3 #ifndef _BFIN_SEMAPHORE_HELPER_H
4 #define _BFIN_SEMAPHORE_HELPER_H
6 /*
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)
25 int ret;
26 unsigned long flags = 0;
28 spin_lock_irqsave(&semaphore_wake_lock, flags);
29 ret = 0;
30 if (atomic_read(&sem->waking) > 0) {
31 atomic_dec(&sem->waking);
32 ret = 1;
34 spin_unlock_irqrestore(&semaphore_wake_lock, flags);
35 return ret;
39 * waking_non_zero_interruptible:
40 * 1 got the lock
41 * 0 go to sleep
42 * -EINTR interrupted
44 static inline int waking_non_zero_interruptible(struct semaphore *sem,
45 struct task_struct *tsk)
47 int ret = 0;
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);
53 ret = 1;
54 } else if (signal_pending(tsk)) {
55 atomic_inc(&sem->count);
56 ret = -EINTR;
58 spin_unlock_irqrestore(&semaphore_wake_lock, flags);
59 return ret;
63 * waking_non_zero_trylock:
64 * 1 failed to lock
65 * 0 got the lock
67 static inline int waking_non_zero_trylock(struct semaphore *sem)
69 int ret = 1;
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);
75 ret = 0;
76 } else
77 atomic_inc(&sem->count);
78 spin_unlock_irqrestore(&semaphore_wake_lock, flags);
79 return ret;
82 #endif /* _BFIN_SEMAPHORE_HELPER_H */