diff options
author | Linus Torvalds <torvalds@ppc970.osdl.org> | 2005-04-16 18:20:36 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@ppc970.osdl.org> | 2005-04-16 18:20:36 -0400 |
commit | 1da177e4c3f41524e886b7f1b8a0c1fc7321cac2 (patch) | |
tree | 0bba044c4ce775e45a88a51686b5d9f90697ea9d /include/asm-arm26/semaphore.h |
Linux-2.6.12-rc2v2.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-arm26/semaphore.h')
-rw-r--r-- | include/asm-arm26/semaphore.h | 103 |
1 files changed, 103 insertions, 0 deletions
diff --git a/include/asm-arm26/semaphore.h b/include/asm-arm26/semaphore.h new file mode 100644 index 000000000000..c1b6a1edad92 --- /dev/null +++ b/include/asm-arm26/semaphore.h | |||
@@ -0,0 +1,103 @@ | |||
1 | /* | ||
2 | * linux/include/asm-arm/semaphore.h | ||
3 | */ | ||
4 | #ifndef __ASM_ARM_SEMAPHORE_H | ||
5 | #define __ASM_ARM_SEMAPHORE_H | ||
6 | |||
7 | #include <linux/linkage.h> | ||
8 | #include <linux/spinlock.h> | ||
9 | #include <linux/wait.h> | ||
10 | #include <linux/rwsem.h> | ||
11 | |||
12 | #include <asm/atomic.h> | ||
13 | #include <asm/locks.h> | ||
14 | |||
15 | struct semaphore { | ||
16 | atomic_t count; | ||
17 | int sleepers; | ||
18 | wait_queue_head_t wait; | ||
19 | }; | ||
20 | |||
21 | #define __SEMAPHORE_INIT(name, n) \ | ||
22 | { \ | ||
23 | .count = ATOMIC_INIT(n), \ | ||
24 | .sleepers = 0, \ | ||
25 | .wait = __WAIT_QUEUE_HEAD_INITIALIZER((name).wait), \ | ||
26 | } | ||
27 | |||
28 | #define __MUTEX_INITIALIZER(name) \ | ||
29 | __SEMAPHORE_INIT(name,1) | ||
30 | |||
31 | #define __DECLARE_SEMAPHORE_GENERIC(name,count) \ | ||
32 | struct semaphore name = __SEMAPHORE_INIT(name,count) | ||
33 | |||
34 | #define DECLARE_MUTEX(name) __DECLARE_SEMAPHORE_GENERIC(name,1) | ||
35 | #define DECLARE_MUTEX_LOCKED(name) __DECLARE_SEMAPHORE_GENERIC(name,0) | ||
36 | |||
37 | static inline void sema_init(struct semaphore *sem, int val) | ||
38 | { | ||
39 | atomic_set(&sem->count, val); | ||
40 | sem->sleepers = 0; | ||
41 | init_waitqueue_head(&sem->wait); | ||
42 | } | ||
43 | |||
44 | static inline void init_MUTEX(struct semaphore *sem) | ||
45 | { | ||
46 | sema_init(sem, 1); | ||
47 | } | ||
48 | |||
49 | static inline void init_MUTEX_LOCKED(struct semaphore *sem) | ||
50 | { | ||
51 | sema_init(sem, 0); | ||
52 | } | ||
53 | |||
54 | /* | ||
55 | * special register calling convention | ||
56 | */ | ||
57 | asmlinkage void __down_failed(void); | ||
58 | asmlinkage int __down_interruptible_failed(void); | ||
59 | asmlinkage int __down_trylock_failed(void); | ||
60 | asmlinkage void __up_wakeup(void); | ||
61 | |||
62 | extern void __down(struct semaphore * sem); | ||
63 | extern int __down_interruptible(struct semaphore * sem); | ||
64 | extern int __down_trylock(struct semaphore * sem); | ||
65 | extern void __up(struct semaphore * sem); | ||
66 | |||
67 | /* | ||
68 | * This is ugly, but we want the default case to fall through. | ||
69 | * "__down" is the actual routine that waits... | ||
70 | */ | ||
71 | static inline void down(struct semaphore * sem) | ||
72 | { | ||
73 | might_sleep(); | ||
74 | __down_op(sem, __down_failed); | ||
75 | } | ||
76 | |||
77 | /* | ||
78 | * This is ugly, but we want the default case to fall through. | ||
79 | * "__down_interruptible" is the actual routine that waits... | ||
80 | */ | ||
81 | static inline int down_interruptible (struct semaphore * sem) | ||
82 | { | ||
83 | might_sleep(); | ||
84 | return __down_op_ret(sem, __down_interruptible_failed); | ||
85 | } | ||
86 | |||
87 | static inline int down_trylock(struct semaphore *sem) | ||
88 | { | ||
89 | return __down_op_ret(sem, __down_trylock_failed); | ||
90 | } | ||
91 | |||
92 | /* | ||
93 | * Note! This is subtle. We jump to wake people up only if | ||
94 | * the semaphore was negative (== somebody was waiting on it). | ||
95 | * The default case (no contention) will result in NO | ||
96 | * jumps for both down() and up(). | ||
97 | */ | ||
98 | static inline void up(struct semaphore * sem) | ||
99 | { | ||
100 | __up_op(sem, __up_wakeup); | ||
101 | } | ||
102 | |||
103 | #endif | ||