2 * Copyright 1996 1995 by Open Software Foundation, Inc. 1997 1996 1995 1994 1993 1992 1991
5 * Permission to use, copy, modify, and distribute this software and
6 * its documentation for any purpose and without fee is hereby granted,
7 * provided that the above copyright notice appears in all copies and
8 * that both the copyright notice and this permission notice appear in
9 * supporting documentation.
11 * OSF DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE
12 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
13 * FOR A PARTICULAR PURPOSE.
15 * IN NO EVENT SHALL OSF BE LIABLE FOR ANY SPECIAL, INDIRECT, OR
16 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
17 * LOSS OF USE, DATA OR PROFITS, WHETHER IN ACTION OF CONTRACT,
18 * NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
19 * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
28 #import <architecture/ppc/asm_help.h>
29 #import <architecture/ppc/pseudo_inst.h>
31 /* void spin_lock(int *p);
33 * Lock the lock pointed to by `p'. Spin (possibly forever) until
34 * the lock is available. Test and test and set logic used.
41 lwarx r5,0,r3 // Read the lock
42 addi r4,0,0x1 // Lock value
43 cmpwi r5,0x0 // Is it busy?
44 bne- 2f // Yes, return 0
45 stwcx. r4,0,r3 // Try to lock the lock
46 bne- 1b // Lost reservation, try again
47 addi r3,0,1 // Got the lock
48 isync // Sync instruction stream
50 2: addi r3,0,0 // Could not get the lock
57 addi r4,0,0x1 // Lock value
59 lwarx r5,0,r3 // Read the lock
60 cmpwi r5,0x0 // Is it busy?
62 stwcx. r4,0,r3 // Try to lock the lock
63 bne- 1b // Lost reservation, try again
64 isync // Sync instruction stream
68 /* void spin_unlock(int *p);
70 * Unlock the lock pointed to by p.
81 #elif defined(__i386__)
83 #include <architecture/i386/asm_help.h>
90 * Lock the lock pointed to by p. Spin (possibly forever) until the next
96 LEAF(__spin_lock_try, 0)
112 movl $0xFFFFFFFF, %eax
124 * Unlock the lock pointed to by p.
127 LEAF(__spin_unlock, 0)
135 #error spin_locks not defined for this architecture