]>
git.saurik.com Git - apple/xnu.git/blob - iokit/IOKit/ppc/IOSharedLockImp.h
465a8d43768ea08a23da21b03085cfefd25c3b5f
2 * Copyright (c) 1998-2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_OSREFERENCE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the
10 * License may not be used to create, or enable the creation or
11 * redistribution of, unlawful or unlicensed copies of an Apple operating
12 * system, or to circumvent, violate, or enable the circumvention or
13 * violation of, any terms of an Apple operating system software license
16 * Please obtain a copy of the License at
17 * http://www.opensource.apple.com/apsl/ and read it before using this
20 * The Original Code and all software distributed under the License are
21 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
22 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
23 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
24 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
25 * Please see the License for the specific language governing rights and
26 * limitations under the License.
28 * @APPLE_LICENSE_OSREFERENCE_HEADER_END@
31 * Copyright (c) 1998 Apple Computer, Inc. All rights reserved.
37 /* Copyright (c) 1992 NeXT Computer, Inc. All rights reserved.
39 * EventShmemLock.h - Shared memory area locks for use between the
40 * WindowServer and the Event Driver.
43 * 30 Nov 1992 Ben Fathi (benf@next.com)
46 * 29 April 1992 Mike Paquette at NeXT
49 * Multiprocessor locks used within the shared memory area between the
50 * kernel and event system. These must work in both user and kernel mode.
51 * The locks are defined in an include file so they get exported to the local
56 #ifndef _IOKIT_IOSHAREDLOCKIMP_H
57 #define _IOKIT_IOSHAREDLOCKIMP_H
59 #include <architecture/ppc/asm_help.h>
62 #include <mach/ppc/asm.h>
70 * Lock the lock pointed to by p. Spin (possibly forever) until
71 * the lock is available. Test and test and set logic used.
80 8: lwz a7
,0(a0
) // Get lock word
81 mr
. a7
,a7
// Is it held?
84 9: lwarx a7
,0,a0
// read the lock
85 mr
. a7
,a7
// Is it held?
86 bne
-- 7f
// yes, kill reservation
87 stwcx
. a6
,0,a0
// try to get the lock
88 bne
-- 9b
// failed, try again
92 7: li a7
,-4 // Point to a spot in the red zone
93 stwcx
. a7
,a7
,r1
// Kill reservation
94 b
8b
// Go wait some more...
101 li a6
,1 // lock value
103 8: lwz a7
,0(a0
) // Get lock word
104 mr
. a7
,a7
// Is it held?
107 9: lwarx a7
,0,a0
// read the lock
108 mr
. a7
,a7
// Is it held?
109 bne
-- 7f
// yes, kill reservation
110 stwcx
. a6
,0,a0
// try to get the lock
111 bne
-- 9b
// failed, try again
113 blr
// got it, return
115 7: li a7
,-4 // Point to a spot in the red zone
116 stwcx
. a7
,a7
,r1
// Kill reservation
117 b
8b
// Go wait some more...
126 * Unlock the lock pointed to by p.
148 * Try to lock p. Return TRUE if successful in obtaining lock.
152 li a6
,1 // lock value
154 lwz a7
,0(a0
) // Get lock word
155 mr
. a7
,a7
// Is it held?
158 9: lwarx a7
,0,a0
// read the lock
159 mr
. a7
,a7
// Is it held?
160 bne
-- 7f
// yes, kill reservation
161 stwcx
. a6
,0,a0
// try to get the lock
162 bne
-- 9b
// failed, try again
163 li a0
,1 // return TRUE
165 blr
// got it, return
167 7: li a7
,-4 // Point to a spot in the red zone
168 stwcx
. a7
,a7
,r1
// Kill reservation
171 li a0
,0 // return FALSE
177 li a6
,1 // lock value
179 lwz a7
,0(a0
) // Get lock word
180 mr
. a7
,a7
// Is it held?
183 9: lwarx a7
,0,a0
// read the lock
184 mr
. a7
,a7
// Is it held?
185 bne
-- 7f
// yes, kill reservation
186 stwcx
. a6
,0,a0
// try to get the lock
187 bne
-- 9b
// failed, try again
188 li a0
,1 // return TRUE
190 blr
// got it, return
192 7: li a7
,-4 // Point to a spot in the red zone
193 stwcx
. a7
,a7
,r1
// Kill reservation
196 li a0
,0 // return FALSE
201 #endif /* ! _IOKIT_IOSHAREDLOCKIMP_H */