ia64/linux-2.6.18-xen.hg

view include/asm-arm/semaphore.h @ 782:9ab1c319531f

merge with linux-2.6.18-xen.hg
author Isaku Yamahata <yamahata@valinux.co.jp>
date Wed Jan 28 13:07:23 2009 +0900 (2009-01-28)
parents 831230e53067
children
line source
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 };
21 #define __SEMAPHORE_INIT(name, cnt) \
22 { \
23 .count = ATOMIC_INIT(cnt), \
24 .wait = __WAIT_QUEUE_HEAD_INITIALIZER((name).wait), \
25 }
27 #define __DECLARE_SEMAPHORE_GENERIC(name,count) \
28 struct semaphore name = __SEMAPHORE_INIT(name,count)
30 #define DECLARE_MUTEX(name) __DECLARE_SEMAPHORE_GENERIC(name,1)
31 #define DECLARE_MUTEX_LOCKED(name) __DECLARE_SEMAPHORE_GENERIC(name,0)
33 static inline void sema_init(struct semaphore *sem, int val)
34 {
35 atomic_set(&sem->count, val);
36 sem->sleepers = 0;
37 init_waitqueue_head(&sem->wait);
38 }
40 static inline void init_MUTEX(struct semaphore *sem)
41 {
42 sema_init(sem, 1);
43 }
45 static inline void init_MUTEX_LOCKED(struct semaphore *sem)
46 {
47 sema_init(sem, 0);
48 }
50 /*
51 * special register calling convention
52 */
53 asmlinkage void __down_failed(void);
54 asmlinkage int __down_interruptible_failed(void);
55 asmlinkage int __down_trylock_failed(void);
56 asmlinkage void __up_wakeup(void);
58 extern void __down(struct semaphore * sem);
59 extern int __down_interruptible(struct semaphore * sem);
60 extern int __down_trylock(struct semaphore * sem);
61 extern void __up(struct semaphore * sem);
63 /*
64 * This is ugly, but we want the default case to fall through.
65 * "__down" is the actual routine that waits...
66 */
67 static inline void down(struct semaphore * sem)
68 {
69 might_sleep();
70 __down_op(sem, __down_failed);
71 }
73 /*
74 * This is ugly, but we want the default case to fall through.
75 * "__down_interruptible" is the actual routine that waits...
76 */
77 static inline int down_interruptible (struct semaphore * sem)
78 {
79 might_sleep();
80 return __down_op_ret(sem, __down_interruptible_failed);
81 }
83 static inline int down_trylock(struct semaphore *sem)
84 {
85 return __down_op_ret(sem, __down_trylock_failed);
86 }
88 /*
89 * Note! This is subtle. We jump to wake people up only if
90 * the semaphore was negative (== somebody was waiting on it).
91 * The default case (no contention) will result in NO
92 * jumps for both down() and up().
93 */
94 static inline void up(struct semaphore * sem)
95 {
96 __up_op(sem, __up_wakeup);
97 }
99 #endif