Import 2.1.22
[davej-history.git] / include / asm-i386 / semaphore.h
blob0c6c13e9c062d99e718f7921fed4a7a4f5aa4ac2
1 #ifndef _I386_SEMAPHORE_H
2 #define _I386_SEMAPHORE_H
4 #include <linux/linkage.h>
6 /*
7 * SMP- and interrupt-safe semaphores..
9 * (C) Copyright 1996 Linus Torvalds
11 * Modified 1996-12-23 by Dave Grothe <dave@gcom.com> to fix bugs in
12 * the original code and to make semaphore waits
13 * interruptible so that processes waiting on
14 * semaphores can be killed.
16 * If you would like to see an analysis of this implementation, please
17 * ftp to gcom.com and download the file
18 * /pub/linux/src/semaphore/semaphore-2.0.24.tar.gz.
22 struct semaphore {
23 int count;
24 int waking;
25 struct wait_queue * wait;
28 #define MUTEX ((struct semaphore) { 1, 0, NULL })
29 #define MUTEX_LOCKED ((struct semaphore) { 0, 0, NULL })
31 asmlinkage void__down_failed(void/* special register calling convention */);
32 asmlinkage int__down_failed_interruptible(void/* params in registers */);
33 asmlinkage void__up_wakeup(void/* special register calling convention */);
35 externvoid__down(struct semaphore * sem);
36 externvoid__up(struct semaphore * sem);
39 * This is ugly, but we want the default case to fall through.
40 * "down_failed" is a special asm handler that calls the C
41 * routine that actually waits. See arch/i386/lib/semaphore.S
43 extern inlinevoiddown(struct semaphore * sem)
45 __asm__ __volatile__(
46 "# atomic down operation\n\t"
47 "movl $1f,%%eax\n\t"
48 #ifdef __SMP__
49 "lock ; "
50 #endif
51 "decl 0(%0)\n\t"
52 "js "SYMBOL_NAME_STR(__down_failed)
53 "\n1:"
54 :/* no outputs */
55 :"c"(sem)
56 :"ax","memory");
60 * This version waits in interruptible state so that the waiting
61 * process can be killed. The down_failed_interruptible routine
62 * returns negative for signalled and zero for semaphore acquired.
64 extern inlineintdown_interruptible(struct semaphore * sem)
66 int ret;
68 __asm__ __volatile__(
69 "# atomic interruptible down operation\n\t"
70 "movl $1f,%0\n\t"
71 #ifdef __SMP__
72 "lock ; "
73 #endif
74 "decl 0(%1)\n\t"
75 "js "SYMBOL_NAME_STR(__down_failed_interruptible)"\n\t"
76 "xorl %0,%0"
77 "\n1:"
78 :"=a"(ret)
79 :"c"(sem)
80 :"memory");
82 return ret;
86 * Note! This is subtle. We jump to wake people up only if
87 * the semaphore was negative (== somebody was waiting on it).
88 * The default case (no contention) will result in NO
89 * jumps for both down() and up().
91 extern inlinevoidup(struct semaphore * sem)
93 __asm__ __volatile__(
94 "# atomic up operation\n\t"
95 "movl $1f,%%eax\n\t"
96 #ifdef __SMP__
97 "lock ; "
98 #endif
99 "incl 0(%0)\n\t"
100 "jle "SYMBOL_NAME_STR(__up_wakeup)
101 "\n1:"
102 :/* no outputs */
103 :"c"(sem)
104 :"ax","memory");
107 #endif
close