Pull update-default-configs into release branch
[linux-2.6] / include / asm-m68knommu / semaphore-helper.h
1 #ifndef _M68K_SEMAPHORE_HELPER_H
2 #define _M68K_SEMAPHORE_HELPER_H
3
4 /*
5  * SMP- and interrupt-safe semaphores helper functions.
6  *
7  * (C) Copyright 1996 Linus Torvalds
8  *
9  * m68k version by Andreas Schwab
10  */
11
12 #include <linux/config.h>
13
14 /*
15  * These two _must_ execute atomically wrt each other.
16  */
17 static inline void wake_one_more(struct semaphore * sem)
18 {
19         atomic_inc(&sem->waking);
20 }
21
22 static inline int waking_non_zero(struct semaphore *sem)
23 {
24         int ret;
25         unsigned long flags;
26
27         spin_lock_irqsave(&semaphore_wake_lock, flags);
28         ret = 0;
29         if (atomic_read(&sem->waking) > 0) {
30                 atomic_dec(&sem->waking);
31                 ret = 1;
32         }
33         spin_unlock_irqrestore(&semaphore_wake_lock, flags);
34         return ret;
35 }
36
37 /*
38  * waking_non_zero_interruptible:
39  *      1       got the lock
40  *      0       go to sleep
41  *      -EINTR  interrupted
42  */
43 static inline int waking_non_zero_interruptible(struct semaphore *sem,
44                                                 struct task_struct *tsk)
45 {
46         int ret;
47         unsigned long flags;
48
49         spin_lock_irqsave(&semaphore_wake_lock, flags);
50         ret = 0;
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;
57         }
58         spin_unlock_irqrestore(&semaphore_wake_lock, flags);
59         return ret;
60 }
61
62 /*
63  * waking_non_zero_trylock:
64  *      1       failed to lock
65  *      0       got the lock
66  */
67 static inline int waking_non_zero_trylock(struct semaphore *sem)
68 {
69         int ret;
70         unsigned long flags;
71
72         spin_lock_irqsave(&semaphore_wake_lock, flags);
73         ret = 1;
74         if (atomic_read(&sem->waking) > 0) {
75                 atomic_dec(&sem->waking);
76                 ret = 0;
77         } else
78                 atomic_inc(&sem->count);
79         spin_unlock_irqrestore(&semaphore_wake_lock, flags);
80         return ret;
81 }
82
83 #endif