Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/jmorris...
[linux-2.6/verdex.git] / include / asm-m68knommu / semaphore-helper.h
blob43da7bc483c79ad00ddf4f09666557324f613de6
1 #ifndef _M68K_SEMAPHORE_HELPER_H
2 #define _M68K_SEMAPHORE_HELPER_H
4 /*
5 * SMP- and interrupt-safe semaphores helper functions.
7 * (C) Copyright 1996 Linus Torvalds
9 * m68k version by Andreas Schwab
14 * These two _must_ execute atomically wrt each other.
16 static inline void wake_one_more(struct semaphore * sem)
18 atomic_inc(&sem->waking);
21 static inline int waking_non_zero(struct semaphore *sem)
23 int ret;
24 unsigned long flags;
26 spin_lock_irqsave(&semaphore_wake_lock, flags);
27 ret = 0;
28 if (atomic_read(&sem->waking) > 0) {
29 atomic_dec(&sem->waking);
30 ret = 1;
32 spin_unlock_irqrestore(&semaphore_wake_lock, flags);
33 return ret;
37 * waking_non_zero_interruptible:
38 * 1 got the lock
39 * 0 go to sleep
40 * -EINTR interrupted
42 static inline int waking_non_zero_interruptible(struct semaphore *sem,
43 struct task_struct *tsk)
45 int ret;
46 unsigned long flags;
48 spin_lock_irqsave(&semaphore_wake_lock, flags);
49 ret = 0;
50 if (atomic_read(&sem->waking) > 0) {
51 atomic_dec(&sem->waking);
52 ret = 1;
53 } else if (signal_pending(tsk)) {
54 atomic_inc(&sem->count);
55 ret = -EINTR;
57 spin_unlock_irqrestore(&semaphore_wake_lock, flags);
58 return ret;
62 * waking_non_zero_trylock:
63 * 1 failed to lock
64 * 0 got the lock
66 static inline int waking_non_zero_trylock(struct semaphore *sem)
68 int ret;
69 unsigned long flags;
71 spin_lock_irqsave(&semaphore_wake_lock, flags);
72 ret = 1;
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