1 #ifndef _M68K_SEMAPHORE_H
2 #define _M68K_SEMAPHORE_H
4 #include <linux/linkage.h>
6 #include <asm/system.h>
7 #include <asm/atomic.h>
8 #include <asm/spinlock.h>
11 * SMP- and interrupt-safe semaphores..
13 * (C) Copyright 1996 Linus Torvalds
15 * m68k version by Andreas Schwab
21 wait_queue_head_t wait
;
24 #define MUTEX ((struct semaphore) { ATOMIC_INIT(1), ATOMIC_INIT(0), NULL })
25 #define MUTEX_LOCKED ((struct semaphore) { ATOMIC_INIT(0), ATOMIC_INIT(0), NULL })
27 asmlinkage
void __down_failed(void /* special register calling convention */);
28 asmlinkage
int __down_failed_interruptible(void /* params in registers */);
29 asmlinkage
int __down_failed_trylock(void /* params in registers */);
30 asmlinkage
void __up_wakeup(void /* special register calling convention */);
32 asmlinkage
void __down(struct semaphore
* sem
);
33 asmlinkage
int __down_interruptible(struct semaphore
* sem
);
34 asmlinkage
int __down_trylock(struct semaphore
* sem
);
35 asmlinkage
void __up(struct semaphore
* sem
);
37 #define sema_init(sem, val) atomic_set(&((sem)->count), val)
40 * This is ugly, but we want the default case to fall through.
41 * "down_failed" is a special asm handler that calls the C
42 * routine that actually waits. See arch/m68k/lib/semaphore.S
44 extern inline void down(struct semaphore
* sem
)
46 register struct semaphore
*sem1
__asm__ ("%a1") = sem
;
48 "| atomic down operation\n\t"
52 ".section .text.lock,\"ax\"\n"
55 "jbra __down_failed\n"
62 extern inline int down_interruptible(struct semaphore
* sem
)
64 register struct semaphore
*sem1
__asm__ ("%a1") = sem
;
65 register int result
__asm__ ("%d0");
68 "| atomic interruptible down operation\n\t"
73 ".section .text.lock,\"ax\"\n"
76 "jbra __down_failed_interruptible\n"
84 extern inline int down_trylock(struct semaphore
* sem
)
86 register struct semaphore
*sem1
__asm__ ("%a1") = sem
;
87 register int result
__asm__ ("%d0");
90 "| atomic down trylock operation\n\t"
95 ".section .text.lock,\"ax\"\n"
98 "jbra __down_failed_trylock\n"
107 * Note! This is subtle. We jump to wake people up only if
108 * the semaphore was negative (== somebody was waiting on it).
109 * The default case (no contention) will result in NO
110 * jumps for both down() and up().
112 extern inline void up(struct semaphore
* sem
)
114 register struct semaphore
*sem1
__asm__ ("%a1") = sem
;
115 __asm__
__volatile__(
116 "| atomic up operation\n\t"
120 ".section .text.lock,\"ax\"\n"