X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=include%2Fasm-m32r%2Fsemaphore.h;fp=include%2Fasm-m32r%2Fsemaphore.h;h=bf447c52a0a126c8a26719885d5e081f73c3c728;hb=64ba3f394c830ec48a1c31b53dcae312c56f1604;hp=41e45d7b87ef2262c396872c87b3a143fd9ff88a;hpb=be1e6109ac94a859551f8e1774eb9a8469fe055c;p=linux-2.6.git diff --git a/include/asm-m32r/semaphore.h b/include/asm-m32r/semaphore.h index 41e45d7b8..bf447c52a 100644 --- a/include/asm-m32r/semaphore.h +++ b/include/asm-m32r/semaphore.h @@ -9,9 +9,10 @@ * SMP- and interrupt-safe semaphores.. * * Copyright (C) 1996 Linus Torvalds - * Copyright (C) 2004, 2006 Hirokazu Takata + * Copyright (C) 2004 Hirokazu Takata */ +#include #include #include #include @@ -76,8 +77,27 @@ asmlinkage void __up(struct semaphore * sem); */ static inline void down(struct semaphore * sem) { + unsigned long flags; + long count; + might_sleep(); - if (unlikely(atomic_dec_return(&sem->count) < 0)) + local_irq_save(flags); + __asm__ __volatile__ ( + "# down \n\t" + DCACHE_CLEAR("%0", "r4", "%1") + M32R_LOCK" %0, @%1; \n\t" + "addi %0, #-1; \n\t" + M32R_UNLOCK" %0, @%1; \n\t" + : "=&r" (count) + : "r" (&sem->count) + : "memory" +#ifdef CONFIG_CHIP_M32700_TS1 + , "r4" +#endif /* CONFIG_CHIP_M32700_TS1 */ + ); + local_irq_restore(flags); + + if (unlikely(count < 0)) __down(sem); } @@ -87,10 +107,28 @@ static inline void down(struct semaphore * sem) */ static inline int down_interruptible(struct semaphore * sem) { + unsigned long flags; + long count; int result = 0; might_sleep(); - if (unlikely(atomic_dec_return(&sem->count) < 0)) + local_irq_save(flags); + __asm__ __volatile__ ( + "# down_interruptible \n\t" + DCACHE_CLEAR("%0", "r4", "%1") + M32R_LOCK" %0, @%1; \n\t" + "addi %0, #-1; \n\t" + M32R_UNLOCK" %0, @%1; \n\t" + : "=&r" (count) + : "r" (&sem->count) + : "memory" +#ifdef CONFIG_CHIP_M32700_TS1 + , "r4" +#endif /* CONFIG_CHIP_M32700_TS1 */ + ); + local_irq_restore(flags); + + if (unlikely(count < 0)) result = __down_interruptible(sem); return result; @@ -136,7 +174,26 @@ static inline int down_trylock(struct semaphore * sem) */ static inline void up(struct semaphore * sem) { - if (unlikely(atomic_inc_return(&sem->count) <= 0)) + unsigned long flags; + long count; + + local_irq_save(flags); + __asm__ __volatile__ ( + "# up \n\t" + DCACHE_CLEAR("%0", "r4", "%1") + M32R_LOCK" %0, @%1; \n\t" + "addi %0, #1; \n\t" + M32R_UNLOCK" %0, @%1; \n\t" + : "=&r" (count) + : "r" (&sem->count) + : "memory" +#ifdef CONFIG_CHIP_M32700_TS1 + , "r4" +#endif /* CONFIG_CHIP_M32700_TS1 */ + ); + local_irq_restore(flags); + + if (unlikely(count <= 0)) __up(sem); }