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