aboutsummaryrefslogtreecommitdiffstats
path: root/include/asm-sh64/semaphore.h
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-16 18:20:36 -0400
committerLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-16 18:20:36 -0400
commit1da177e4c3f41524e886b7f1b8a0c1fc7321cac2 (patch)
tree0bba044c4ce775e45a88a51686b5d9f90697ea9d /include/asm-sh64/semaphore.h
Linux-2.6.12-rc2v2.6.12-rc2
Initial git repository build. I'm not bothering with the full history, even though we have it. We can create a separate "historical" git archive of that later if we want to, and in the meantime it's about 3.2GB when imported into git - space that would just make the early git days unnecessarily complicated, when we don't have a lot of good infrastructure for it. Let it rip!
Diffstat (limited to 'include/asm-sh64/semaphore.h')
-rw-r--r--include/asm-sh64/semaphore.h123
1 files changed, 123 insertions, 0 deletions
diff --git a/include/asm-sh64/semaphore.h b/include/asm-sh64/semaphore.h
new file mode 100644
index 000000000000..fce22bb9a546
--- /dev/null
+++ b/include/asm-sh64/semaphore.h
@@ -0,0 +1,123 @@
1#ifndef __ASM_SH64_SEMAPHORE_H
2#define __ASM_SH64_SEMAPHORE_H
3
4/*
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
7 * for more details.
8 *
9 * include/asm-sh64/semaphore.h
10 *
11 * Copyright (C) 2000, 2001 Paolo Alberelli
12 *
13 * SMP- and interrupt-safe semaphores.
14 *
15 * (C) Copyright 1996 Linus Torvalds
16 *
17 * SuperH verison by Niibe Yutaka
18 * (Currently no asm implementation but generic C code...)
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 __MUTEX_INITIALIZER(name) \
44 __SEMAPHORE_INITIALIZER(name,1)
45
46#define __DECLARE_SEMAPHORE_GENERIC(name,count) \
47 struct semaphore name = __SEMAPHORE_INITIALIZER(name,count)
48
49#define DECLARE_MUTEX(name) __DECLARE_SEMAPHORE_GENERIC(name,1)
50#define DECLARE_MUTEX_LOCKED(name) __DECLARE_SEMAPHORE_GENERIC(name,0)
51
52static inline void sema_init (struct semaphore *sem, int val)
53{
54/*
55 * *sem = (struct semaphore)__SEMAPHORE_INITIALIZER((*sem),val);
56 *
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.
59 */
60 atomic_set(&sem->count, val);
61 sem->sleepers = 0;
62 init_waitqueue_head(&sem->wait);
63}
64
65static inline void init_MUTEX (struct semaphore *sem)
66{
67 sema_init(sem, 1);
68}
69
70static inline void init_MUTEX_LOCKED (struct semaphore *sem)
71{
72 sema_init(sem, 0);
73}
74
75#if 0
76asmlinkage void __down_failed(void /* special register calling convention */);
77asmlinkage int __down_failed_interruptible(void /* params in registers */);
78asmlinkage int __down_failed_trylock(void /* params in registers */);
79asmlinkage void __up_wakeup(void /* special register calling convention */);
80#endif
81
82asmlinkage void __down(struct semaphore * sem);
83asmlinkage int __down_interruptible(struct semaphore * sem);
84asmlinkage int __down_trylock(struct semaphore * sem);
85asmlinkage void __up(struct semaphore * sem);
86
87extern spinlock_t semaphore_wake_lock;
88
89static inline void down(struct semaphore * sem)
90{
91 if (atomic_dec_return(&sem->count) < 0)
92 __down(sem);
93}
94
95static inline int down_interruptible(struct semaphore * sem)
96{
97 int ret = 0;
98
99 if (atomic_dec_return(&sem->count) < 0)
100 ret = __down_interruptible(sem);
101 return ret;
102}
103
104static inline int down_trylock(struct semaphore * sem)
105{
106 int ret = 0;
107
108 if (atomic_dec_return(&sem->count) < 0)
109 ret = __down_trylock(sem);
110 return ret;
111}
112
113/*
114 * Note! This is subtle. We jump to wake people up only if
115 * the semaphore was negative (== somebody was waiting on it).
116 */
117static inline void up(struct semaphore * sem)
118{
119 if (atomic_inc_return(&sem->count) <= 0)
120 __up(sem);
121}
122
123#endif /* __ASM_SH64_SEMAPHORE_H */