1#ifndef __ASM_SH64_SEMAPHORE_H
2#define __ASM_SH64_SEMAPHORE_H
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22#include <linux/linkage.h>
23#include <linux/spinlock.h>
24#include <linux/wait.h>
25#include <linux/rwsem.h>
26
27#include <asm/system.h>
28#include <asm/atomic.h>
29
30struct semaphore {
31 atomic_t count;
32 int sleepers;
33 wait_queue_head_t wait;
34};
35
36#define __SEMAPHORE_INITIALIZER(name, n) \
37{ \
38 .count = ATOMIC_INIT(n), \
39 .sleepers = 0, \
40 .wait = __WAIT_QUEUE_HEAD_INITIALIZER((name).wait) \
41}
42
43#define __DECLARE_SEMAPHORE_GENERIC(name,count) \
44 struct semaphore name = __SEMAPHORE_INITIALIZER(name,count)
45
46#define DECLARE_MUTEX(name) __DECLARE_SEMAPHORE_GENERIC(name,1)
47
48static inline void sema_init (struct semaphore *sem, int val)
49{
50
51
52
53
54
55
56 atomic_set(&sem->count, val);
57 sem->sleepers = 0;
58 init_waitqueue_head(&sem->wait);
59}
60
61static inline void init_MUTEX (struct semaphore *sem)
62{
63 sema_init(sem, 1);
64}
65
66static inline void init_MUTEX_LOCKED (struct semaphore *sem)
67{
68 sema_init(sem, 0);
69}
70
71#if 0
72asmlinkage void __down_failed(void );
73asmlinkage int __down_failed_interruptible(void );
74asmlinkage int __down_failed_trylock(void );
75asmlinkage void __up_wakeup(void );
76#endif
77
78asmlinkage void __down(struct semaphore * sem);
79asmlinkage int __down_interruptible(struct semaphore * sem);
80asmlinkage int __down_trylock(struct semaphore * sem);
81asmlinkage void __up(struct semaphore * sem);
82
83extern spinlock_t semaphore_wake_lock;
84
85static inline void down(struct semaphore * sem)
86{
87 if (atomic_dec_return(&sem->count) < 0)
88 __down(sem);
89}
90
91static inline int down_interruptible(struct semaphore * sem)
92{
93 int ret = 0;
94
95 if (atomic_dec_return(&sem->count) < 0)
96 ret = __down_interruptible(sem);
97 return ret;
98}
99
100static inline int down_trylock(struct semaphore * sem)
101{
102 int ret = 0;
103
104 if (atomic_dec_return(&sem->count) < 0)
105 ret = __down_trylock(sem);
106 return ret;
107}
108
109
110
111
112
113static inline void up(struct semaphore * sem)
114{
115 if (atomic_inc_return(&sem->count) <= 0)
116 __up(sem);
117}
118
119#endif
120