aboutsummaryrefslogtreecommitdiffstats
path: root/include/asm-m32r
diff options
context:
space:
mode:
authorHirokazu Takata <takata@linux-m32r.org>2006-04-19 01:21:25 -0400
committerLinus Torvalds <torvalds@g5.osdl.org>2006-04-19 12:13:50 -0400
commitfa372810e51979c5044e036a34015845e9c6aedd (patch)
tree788adb758256488a7760c02384ad387071cf2d50 /include/asm-m32r
parent8e8ff02c0b61d9b7c15c7996a2eddbedf51a105b (diff)
[PATCH] m32r: update include/asm-m32r/semaphore.h
This patch updates include/asm-m32r/semaphore.h for good readability and maintainability. Signed-off-by: Hirokazu Takata <takata@linux-m32r.org> Signed-off-by: Andrew Morton <akpm@osdl.org> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Diffstat (limited to 'include/asm-m32r')
-rw-r--r--include/asm-m32r/semaphore.h64
1 files changed, 4 insertions, 60 deletions
diff --git a/include/asm-m32r/semaphore.h b/include/asm-m32r/semaphore.h
index bf447c52a0a1..81750edc8916 100644
--- a/include/asm-m32r/semaphore.h
+++ b/include/asm-m32r/semaphore.h
@@ -9,7 +9,7 @@
9 * SMP- and interrupt-safe semaphores.. 9 * SMP- and interrupt-safe semaphores..
10 * 10 *
11 * Copyright (C) 1996 Linus Torvalds 11 * Copyright (C) 1996 Linus Torvalds
12 * Copyright (C) 2004 Hirokazu Takata <takata at linux-m32r.org> 12 * Copyright (C) 2004, 2006 Hirokazu Takata <takata at linux-m32r.org>
13 */ 13 */
14 14
15#include <linux/config.h> 15#include <linux/config.h>
@@ -77,27 +77,8 @@ asmlinkage void __up(struct semaphore * sem);
77 */ 77 */
78static inline void down(struct semaphore * sem) 78static inline void down(struct semaphore * sem)
79{ 79{
80 unsigned long flags;
81 long count;
82
83 might_sleep(); 80 might_sleep();
84 local_irq_save(flags); 81 if (unlikely(atomic_dec_return(&sem->count) < 0))
85 __asm__ __volatile__ (
86 "# down \n\t"
87 DCACHE_CLEAR("%0", "r4", "%1")
88 M32R_LOCK" %0, @%1; \n\t"
89 "addi %0, #-1; \n\t"
90 M32R_UNLOCK" %0, @%1; \n\t"
91 : "=&r" (count)
92 : "r" (&sem->count)
93 : "memory"
94#ifdef CONFIG_CHIP_M32700_TS1
95 , "r4"
96#endif /* CONFIG_CHIP_M32700_TS1 */
97 );
98 local_irq_restore(flags);
99
100 if (unlikely(count < 0))
101 __down(sem); 82 __down(sem);
102} 83}
103 84
@@ -107,28 +88,10 @@ static inline void down(struct semaphore * sem)
107 */ 88 */
108static inline int down_interruptible(struct semaphore * sem) 89static inline int down_interruptible(struct semaphore * sem)
109{ 90{
110 unsigned long flags;
111 long count;
112 int result = 0; 91 int result = 0;
113 92
114 might_sleep(); 93 might_sleep();
115 local_irq_save(flags); 94 if (unlikely(atomic_dec_return(&sem->count) < 0))
116 __asm__ __volatile__ (
117 "# down_interruptible \n\t"
118 DCACHE_CLEAR("%0", "r4", "%1")
119 M32R_LOCK" %0, @%1; \n\t"
120 "addi %0, #-1; \n\t"
121 M32R_UNLOCK" %0, @%1; \n\t"
122 : "=&r" (count)
123 : "r" (&sem->count)
124 : "memory"
125#ifdef CONFIG_CHIP_M32700_TS1
126 , "r4"
127#endif /* CONFIG_CHIP_M32700_TS1 */
128 );
129 local_irq_restore(flags);
130
131 if (unlikely(count < 0))
132 result = __down_interruptible(sem); 95 result = __down_interruptible(sem);
133 96
134 return result; 97 return result;
@@ -174,26 +137,7 @@ static inline int down_trylock(struct semaphore * sem)
174 */ 137 */
175static inline void up(struct semaphore * sem) 138static inline void up(struct semaphore * sem)
176{ 139{
177 unsigned long flags; 140 if (unlikely(atomic_inc_return(&sem->count) <= 0))
178 long count;
179
180 local_irq_save(flags);
181 __asm__ __volatile__ (
182 "# up \n\t"
183 DCACHE_CLEAR("%0", "r4", "%1")
184 M32R_LOCK" %0, @%1; \n\t"
185 "addi %0, #1; \n\t"
186 M32R_UNLOCK" %0, @%1; \n\t"
187 : "=&r" (count)
188 : "r" (&sem->count)
189 : "memory"
190#ifdef CONFIG_CHIP_M32700_TS1
191 , "r4"
192#endif /* CONFIG_CHIP_M32700_TS1 */
193 );
194 local_irq_restore(flags);
195
196 if (unlikely(count <= 0))
197 __up(sem); 141 __up(sem);
198} 142}
199 143