2 * linux/include/asm-arm/semaphore.h
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/proc/locks.h>
18 wait_queue_head_t wait
;
25 # define __SEM_DEBUG_INIT(name) .__magic = (long)&(name).__magic
27 # define __SEM_DEBUG_INIT(name)
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
);
48 init_waitqueue_head(&sem
->wait
);
50 sem
->__magic
= (long)&sem
->__magic
;
54 static inline void init_MUTEX(struct semaphore
*sem
)
59 static inline void init_MUTEX_LOCKED(struct semaphore
*sem
)
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
)
89 CHECK_MAGIC(sem
->__magic
);
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
)
102 CHECK_MAGIC(sem
->__magic
);
105 return __down_op_ret(sem
, __down_interruptible_failed
);
108 static inline int down_trylock(struct semaphore
*sem
)
111 CHECK_MAGIC(sem
->__magic
);
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
)
126 CHECK_MAGIC(sem
->__magic
);
129 __up_op(sem
, __up_wakeup
);