1 #ifndef __ASM_SH64_SEMAPHORE_H
2 #define __ASM_SH64_SEMAPHORE_H
5 * This file is subject to the terms and conditions of the GNU General Public
6 * License. See the file "COPYING" in the main directory of this archive
9 * include/asm-sh64/semaphore.h
11 * Copyright (C) 2000, 2001 Paolo Alberelli
13 * SMP- and interrupt-safe semaphores.
15 * (C) Copyright 1996 Linus Torvalds
17 * SuperH verison by Niibe Yutaka
18 * (Currently no asm implementation but generic C code...)
22 #include <linux/linkage.h>
23 #include <linux/spinlock.h>
24 #include <linux/wait.h>
25 #include <linux/rwsem.h>
27 #include <asm/system.h>
28 #include <asm/atomic.h>
33 wait_queue_head_t wait
;
36 #define __SEMAPHORE_INITIALIZER(name, n) \
38 .count = ATOMIC_INIT(n), \
40 .wait = __WAIT_QUEUE_HEAD_INITIALIZER((name).wait) \
43 #define __MUTEX_INITIALIZER(name) \
44 __SEMAPHORE_INITIALIZER(name,1)
46 #define __DECLARE_SEMAPHORE_GENERIC(name,count) \
47 struct semaphore name = __SEMAPHORE_INITIALIZER(name,count)
49 #define DECLARE_MUTEX(name) __DECLARE_SEMAPHORE_GENERIC(name,1)
50 #define DECLARE_MUTEX_LOCKED(name) __DECLARE_SEMAPHORE_GENERIC(name,0)
52 static inline void sema_init (struct semaphore
*sem
, int val
)
55 * *sem = (struct semaphore)__SEMAPHORE_INITIALIZER((*sem),val);
57 * i'd rather use the more flexible initialization above, but sadly
58 * GCC 2.7.2.3 emits a bogus warning. EGCS doesnt. Oh well.
60 atomic_set(&sem
->count
, val
);
62 init_waitqueue_head(&sem
->wait
);
65 static inline void init_MUTEX (struct semaphore
*sem
)
70 static inline void init_MUTEX_LOCKED (struct semaphore
*sem
)
76 asmlinkage
void __down_failed(void /* special register calling convention */);
77 asmlinkage
int __down_failed_interruptible(void /* params in registers */);
78 asmlinkage
int __down_failed_trylock(void /* params in registers */);
79 asmlinkage
void __up_wakeup(void /* special register calling convention */);
82 asmlinkage
void __down(struct semaphore
* sem
);
83 asmlinkage
int __down_interruptible(struct semaphore
* sem
);
84 asmlinkage
int __down_trylock(struct semaphore
* sem
);
85 asmlinkage
void __up(struct semaphore
* sem
);
87 extern spinlock_t semaphore_wake_lock
;
89 static inline void down(struct semaphore
* sem
)
91 if (atomic_dec_return(&sem
->count
) < 0)
95 static inline int down_interruptible(struct semaphore
* sem
)
99 if (atomic_dec_return(&sem
->count
) < 0)
100 ret
= __down_interruptible(sem
);
104 static inline int down_trylock(struct semaphore
* sem
)
108 if (atomic_dec_return(&sem
->count
) < 0)
109 ret
= __down_trylock(sem
);
114 * Note! This is subtle. We jump to wake people up only if
115 * the semaphore was negative (== somebody was waiting on it).
117 static inline void up(struct semaphore
* sem
)
119 if (atomic_inc_return(&sem
->count
) <= 0)
123 #endif /* __ASM_SH64_SEMAPHORE_H */