]>
git.saurik.com Git - apple/xnu.git/blob - iokit/IOKit/ppc/IOSharedLockImp.h
2 * Copyright (c) 1998-2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_OSREFERENCE_LICENSE_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 License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
29 * Copyright (c) 1998 Apple Computer, Inc. All rights reserved.
35 /* Copyright (c) 1992 NeXT Computer, Inc. All rights reserved.
37 * EventShmemLock.h - Shared memory area locks for use between the
38 * WindowServer and the Event Driver.
41 * 30 Nov 1992 Ben Fathi (benf@next.com)
44 * 29 April 1992 Mike Paquette at NeXT
47 * Multiprocessor locks used within the shared memory area between the
48 * kernel and event system. These must work in both user and kernel mode.
49 * The locks are defined in an include file so they get exported to the local
54 #ifndef _IOKIT_IOSHAREDLOCKIMP_H
55 #define _IOKIT_IOSHAREDLOCKIMP_H
57 #include <architecture/ppc/asm_help.h>
60 #include <mach/ppc/asm.h>
68 * Lock the lock pointed to by p. Spin (possibly forever) until
69 * the lock is available. Test and test and set logic used.
78 8: lwz a7
,0(a0
) // Get lock word
79 mr
. a7
,a7
// Is it held?
82 9: lwarx a7
,0,a0
// read the lock
83 mr
. a7
,a7
// Is it held?
84 bne
-- 7f
// yes, kill reservation
85 stwcx
. a6
,0,a0
// try to get the lock
86 bne
-- 9b
// failed, try again
90 7: li a7
,-4 // Point to a spot in the red zone
91 stwcx
. a7
,a7
,r1
// Kill reservation
92 b
8b
// Go wait some more...
101 8: lwz a7
,0(a0
) // Get lock word
102 mr
. a7
,a7
// Is it held?
105 9: lwarx a7
,0,a0
// read the lock
106 mr
. a7
,a7
// Is it held?
107 bne
-- 7f
// yes, kill reservation
108 stwcx
. a6
,0,a0
// try to get the lock
109 bne
-- 9b
// failed, try again
111 blr
// got it, return
113 7: li a7
,-4 // Point to a spot in the red zone
114 stwcx
. a7
,a7
,r1
// Kill reservation
115 b
8b
// Go wait some more...
124 * Unlock the lock pointed to by p.
146 * Try to lock p. Return TRUE if successful in obtaining lock.
150 li a6
,1 // lock value
152 lwz a7
,0(a0
) // Get lock word
153 mr
. a7
,a7
// Is it held?
156 9: lwarx a7
,0,a0
// read the lock
157 mr
. a7
,a7
// Is it held?
158 bne
-- 7f
// yes, kill reservation
159 stwcx
. a6
,0,a0
// try to get the lock
160 bne
-- 9b
// failed, try again
161 li a0
,1 // return TRUE
163 blr
// got it, return
165 7: li a7
,-4 // Point to a spot in the red zone
166 stwcx
. a7
,a7
,r1
// Kill reservation
169 li a0
,0 // return FALSE
175 li a6
,1 // lock value
177 lwz a7
,0(a0
) // Get lock word
178 mr
. a7
,a7
// Is it held?
181 9: lwarx a7
,0,a0
// read the lock
182 mr
. a7
,a7
// Is it held?
183 bne
-- 7f
// yes, kill reservation
184 stwcx
. a6
,0,a0
// try to get the lock
185 bne
-- 9b
// failed, try again
186 li a0
,1 // return TRUE
188 blr
// got it, return
190 7: li a7
,-4 // Point to a spot in the red zone
191 stwcx
. a7
,a7
,r1
// Kill reservation
194 li a0
,0 // return FALSE
199 #endif /* ! _IOKIT_IOSHAREDLOCKIMP_H */