[PATCH] CREDITS update
[linux-2.6/history.git] / include / asm-arm / semaphore.h
blob2e47880be261821f2aca608da3116f8fc3bc0e5c
1 /*
2 * linux/include/asm-arm/semaphore.h
3 */
4 #ifndef __ASM_ARM_SEMAPHORE_H
5 #define __ASM_ARM_SEMAPHORE_H
7 #include <linux/linkage.h>
8 #include <linux/spinlock.h>
9 #include <linux/wait.h>
10 #include <linux/rwsem.h>
12 #include <asm/atomic.h>
13 #include <asm/locks.h>
15 struct semaphore {
16 atomic_t count;
17 int sleepers;
18 wait_queue_head_t wait;
19 #ifdef WAITQUEUE_DEBUG
20 long __magic;
21 #endif
24 #ifdef WAITQUEUE_DEBUG
25 # define __SEM_DEBUG_INIT(name) .__magic = (long)&(name).__magic
26 #else
27 # define __SEM_DEBUG_INIT(name)
28 #endif
30 #define __SEMAPHORE_INIT(name,cnt) { \
31 .count = ATOMIC_INIT(cnt), \
32 .wait = __WAIT_QUEUE_HEAD_INITIALIZER((name).wait), \
33 __SEM_DEBUG_INIT(name) \
36 #define __MUTEX_INITIALIZER(name) __SEMAPHORE_INIT(name,1)
38 #define __DECLARE_SEMAPHORE_GENERIC(name,count) \
39 struct semaphore name = __SEMAPHORE_INIT(name,count)
41 #define DECLARE_MUTEX(name) __DECLARE_SEMAPHORE_GENERIC(name,1)
42 #define DECLARE_MUTEX_LOCKED(name) __DECLARE_SEMAPHORE_GENERIC(name,0)
44 static inline void sema_init(struct semaphore *sem, int val)
46 atomic_set(&sem->count, val);
47 sem->sleepers = 0;
48 init_waitqueue_head(&sem->wait);
49 #ifdef WAITQUEUE_DEBUG
50 sem->__magic = (long)&sem->__magic;
51 #endif
54 static inline void init_MUTEX(struct semaphore *sem)
56 sema_init(sem, 1);
59 static inline void init_MUTEX_LOCKED(struct semaphore *sem)
61 sema_init(sem, 0);
64 static inline int sema_count(struct semaphore *sem)
66 return atomic_read(&sem->count);
70 * special register calling convention
72 asmlinkage void __down_failed(void);
73 asmlinkage int __down_interruptible_failed(void);
74 asmlinkage int __down_trylock_failed(void);
75 asmlinkage void __up_wakeup(void);
77 extern void __down(struct semaphore * sem);
78 extern int __down_interruptible(struct semaphore * sem);
79 extern int __down_trylock(struct semaphore * sem);
80 extern void __up(struct semaphore * sem);
83 * This is ugly, but we want the default case to fall through.
84 * "__down" is the actual routine that waits...
86 static inline void down(struct semaphore * sem)
88 #ifdef WAITQUEUE_DEBUG
89 CHECK_MAGIC(sem->__magic);
90 #endif
91 might_sleep();
92 __down_op(sem, __down_failed);
96 * This is ugly, but we want the default case to fall through.
97 * "__down_interruptible" is the actual routine that waits...
99 static inline int down_interruptible (struct semaphore * sem)
101 #ifdef WAITQUEUE_DEBUG
102 CHECK_MAGIC(sem->__magic);
103 #endif
104 might_sleep();
105 return __down_op_ret(sem, __down_interruptible_failed);
108 static inline int down_trylock(struct semaphore *sem)
110 #ifdef WAITQUEUE_DEBUG
111 CHECK_MAGIC(sem->__magic);
112 #endif
114 return __down_op_ret(sem, __down_trylock_failed);
118 * Note! This is subtle. We jump to wake people up only if
119 * the semaphore was negative (== somebody was waiting on it).
120 * The default case (no contention) will result in NO
121 * jumps for both down() and up().
123 static inline void up(struct semaphore * sem)
125 #ifdef WAITQUEUE_DEBUG
126 CHECK_MAGIC(sem->__magic);
127 #endif
129 __up_op(sem, __up_wakeup);
132 #endif