]>
git.saurik.com Git - apple/xnu.git/blob - osfmk/kern/simple_lock.h
2 * Copyright (c) 2000-2005 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
36 * Mach Operating System
37 * Copyright (c) 1991,1990,1989,1988,1987 Carnegie Mellon University
38 * All Rights Reserved.
40 * Permission to use, copy, modify and distribute this software and its
41 * documentation is hereby granted, provided that both the copyright
42 * notice and this permission notice appear in all copies of the
43 * software, derivative works or modified versions, and any portions
44 * thereof, and that both notices appear in supporting documentation.
46 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
47 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
48 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
50 * Carnegie Mellon requests users of this software to return to
52 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
53 * School of Computer Science
54 * Carnegie Mellon University
55 * Pittsburgh PA 15213-3890
57 * any improvements or extensions that they make and grant Carnegie Mellon
58 * the rights to redistribute these changes.
61 * File: kern/simple_lock.h (derived from kern/lock.h)
62 * Author: Avadis Tevanian, Jr., Michael Wayne Young
65 * Atomic primitives and Simple Locking primitives definitions
70 #ifndef _KERN_SIMPLE_LOCK_H_
71 #define _KERN_SIMPLE_LOCK_H_
73 #include <sys/cdefs.h>
74 #include <mach/boolean.h>
75 #include <kern/kern_types.h>
76 #include <kern/lock_group.h>
77 #include <machine/simple_lock.h>
79 #ifdef MACH_KERNEL_PRIVATE
80 #include <machine/atomic.h>
81 #include <mach_ldebug.h>
83 extern void hw_lock_init(
87 extern void hw_lock_lock(
91 extern void hw_lock_lock_nopreempt(
95 extern unsigned int hw_lock_to(
100 extern unsigned int hw_lock_try(
104 extern unsigned int hw_lock_try_nopreempt(
110 extern void hw_lock_lock(
113 #define hw_lock_lock(lck, grp) hw_lock_lock(lck)
115 extern void hw_lock_lock_nopreempt(
117 #define hw_lock_lock_nopreempt(lck, grp) hw_lock_lock_nopreempt(lck)
119 extern unsigned int hw_lock_to(
122 #define hw_lock_to(lck, timeout, grp) hw_lock_to(lck, timeout)
125 extern unsigned int hw_lock_try(
127 #define hw_lock_try(lck, grp) hw_lock_try(lck)
129 extern unsigned int hw_lock_try_nopreempt(
131 #define hw_lock_try_nopreempt(lck, grp) hw_lock_try_nopreempt(lck)
134 #endif /* LOCK_STATS */
136 extern void hw_lock_unlock(
139 extern void hw_lock_unlock_nopreempt(
142 extern unsigned int hw_lock_held(
145 extern boolean_t
hw_atomic_test_and_set32(uint32_t *target
, uint32_t test_mask
, uint32_t set_mask
, enum memory_order ord
, boolean_t wait
);
146 #endif /* MACH_KERNEL_PRIVATE */
150 extern void * hw_wait_while_equals(
154 extern void usimple_lock_init(
159 extern void usimple_lock(
163 extern unsigned int usimple_lock_try(
167 extern void usimple_lock_try_lock_loop(
171 #if defined(__x86_64__)
172 extern unsigned int usimple_lock_try_lock_mp_signal_safe_loop_deadline(
177 extern unsigned int usimple_lock_try_lock_mp_signal_safe_loop_duration(
184 extern void usimple_lock(
186 #define usimple_lock(lck, grp) usimple_lock(lck)
189 extern unsigned int usimple_lock_try(
192 #define usimple_lock_try(lck, grp) usimple_lock_try(lck)
194 extern void usimple_lock_try_lock_loop(
196 #define usimple_lock_try_lock_loop(lck, grp) usimple_lock_try_lock_loop(lck)
198 #if defined(__x86_64__)
199 extern unsigned int usimple_lock_try_lock_mp_signal_safe_loop_deadline(
202 #define usimple_lock_try_lock_mp_signal_safe_loop_deadline(lck, ddl, grp) usimple_lock_try_lock_mp_signal_safe_loop_deadline(lck, ddl)
204 extern unsigned int usimple_lock_try_lock_mp_signal_safe_loop_duration(
207 #define usimple_lock_try_lock_mp_signal_safe_loop_duration(lck, dur, grp) usimple_lock_try_lock_mp_signal_safe_loop_duration(lck, dur)
210 #endif /* LOCK_STATS */
212 extern void usimple_unlock(
218 #define ETAP_NO_TRACE 0
219 #define ETAP_IO_AHA 0
222 * If we got to here and we still don't have simple_lock_init
223 * defined, then we must either be outside the osfmk component,
224 * running on a true SMP, or need debug.
226 #if !defined(simple_lock_init)
227 #define simple_lock_init(l, t) usimple_lock_init(l,t)
228 #define simple_lock(l, grp) usimple_lock(l, grp)
229 #define simple_unlock(l) usimple_unlock(l)
230 #define simple_lock_try(l, grp) usimple_lock_try(l, grp)
231 #define simple_lock_try_lock_loop(l, grp) usimple_lock_try_lock_loop(l, grp)
232 #define simple_lock_try_lock_mp_signal_safe_loop_deadline(l, ddl, grp) usimple_lock_try_lock_mp_signal_safe_loop_deadline(l, ddl, grp)
233 #define simple_lock_try_lock_mp_signal_safe_loop_duration(l, dur, grp) usimple_lock_try_lock_mp_signal_safe_loop_duration(l, dur, grp)
234 #define simple_lock_addr(l) (&(l))
235 #endif /* !defined(simple_lock_init) */
237 #ifdef MACH_KERNEL_PRIVATE
239 typedef uint32_t hw_lock_bit_t
;
242 extern void hw_lock_bit(
247 extern void hw_lock_bit_nopreempt(
252 extern unsigned int hw_lock_bit_try(
257 extern unsigned int hw_lock_bit_to(
264 extern void hw_lock_bit(
267 #define hw_lock_bit(lck, bit, grp) hw_lock_bit(lck, bit)
269 extern void hw_lock_bit_nopreempt(
272 #define hw_lock_bit_nopreempt(lck, bit, grp) hw_lock_bit_nopreempt(lck, bit)
274 extern unsigned int hw_lock_bit_try(
277 #define hw_lock_bit_try(lck, bit, grp) hw_lock_bit_try(lck, bit)
279 extern unsigned int hw_lock_bit_to(
283 #define hw_lock_bit_to(lck, bit, timeout, grp) hw_lock_bit_to(lck, bit, timeout)
285 #endif /* LOCK_STATS */
287 extern void hw_unlock_bit(
291 extern void hw_unlock_bit_nopreempt(
295 #define hw_lock_bit_held(l, b) (((*(l))&(1<<b))!=0)
297 #endif /* MACH_KERNEL_PRIVATE */
299 #endif /*!_KERN_SIMPLE_LOCK_H_*/
301 #endif /* KERNEL_PRIVATE */