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/locks.h>
18 wait_queue_head_t wait
;
21 #define __SEMAPHORE_INIT(name, cnt) \
23 .count = ATOMIC_INIT(cnt), \
24 .wait = __WAIT_QUEUE_HEAD_INITIALIZER((name).wait), \
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
)
35 atomic_set(&sem
->count
, val
);
37 init_waitqueue_head(&sem
->wait
);
40 static inline void init_MUTEX(struct semaphore
*sem
)
45 static inline void init_MUTEX_LOCKED(struct semaphore
*sem
)
50 static inline int sema_count(struct semaphore
*sem
)
52 return atomic_read(&sem
->count
);
56 * special register calling convention
58 asmlinkage
void __down_failed(void);
59 asmlinkage
int __down_interruptible_failed(void);
60 asmlinkage
int __down_trylock_failed(void);
61 asmlinkage
void __up_wakeup(void);
63 extern void __down(struct semaphore
* sem
);
64 extern int __down_interruptible(struct semaphore
* sem
);
65 extern int __down_trylock(struct semaphore
* sem
);
66 extern void __up(struct semaphore
* sem
);
69 * This is ugly, but we want the default case to fall through.
70 * "__down" is the actual routine that waits...
72 static inline void down(struct semaphore
* sem
)
75 __down_op(sem
, __down_failed
);
79 * This is ugly, but we want the default case to fall through.
80 * "__down_interruptible" is the actual routine that waits...
82 static inline int down_interruptible (struct semaphore
* sem
)
85 return __down_op_ret(sem
, __down_interruptible_failed
);
88 static inline int down_trylock(struct semaphore
*sem
)
90 return __down_op_ret(sem
, __down_trylock_failed
);
94 * Note! This is subtle. We jump to wake people up only if
95 * the semaphore was negative (== somebody was waiting on it).
96 * The default case (no contention) will result in NO
97 * jumps for both down() and up().
99 static inline void up(struct semaphore
* sem
)
101 __up_op(sem
, __up_wakeup
);