aboutsummaryrefslogtreecommitdiffstats
path: root/include/asm-m68knommu/semaphore-helper.h
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-16 18:20:36 -0400
committerLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-16 18:20:36 -0400
commit1da177e4c3f41524e886b7f1b8a0c1fc7321cac2 (patch)
tree0bba044c4ce775e45a88a51686b5d9f90697ea9d /include/asm-m68knommu/semaphore-helper.h
Linux-2.6.12-rc2
Initial git repository build. I'm not bothering with the full history, even though we have it. We can create a separate "historical" git archive of that later if we want to, and in the meantime it's about 3.2GB when imported into git - space that would just make the early git days unnecessarily complicated, when we don't have a lot of good infrastructure for it. Let it rip!
Diffstat (limited to 'include/asm-m68knommu/semaphore-helper.h')
-rw-r--r--include/asm-m68knommu/semaphore-helper.h83
1 files changed, 83 insertions, 0 deletions
diff --git a/include/asm-m68knommu/semaphore-helper.h b/include/asm-m68knommu/semaphore-helper.h
new file mode 100644
index 00000000000..a6586417c1c
--- /dev/null
+++ b/include/asm-m68knommu/semaphore-helper.h
@@ -0,0 +1,83 @@
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 */
17static inline void wake_one_more(struct semaphore * sem)
18{
19 atomic_inc(&sem->waking);
20}
21
22static 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 */
43static 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 */
67static 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