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(
149 enum memory_order ord
,
152 #endif /* MACH_KERNEL_PRIVATE */
153 #if XNU_KERNEL_PRIVATE
155 struct usimple_lock_startup_spec
{
157 unsigned short lck_init_arg
;
160 extern void usimple_lock_startup_init(
161 struct usimple_lock_startup_spec
*spec
);
163 #define SIMPLE_LOCK_DECLARE(var, arg) \
164 decl_simple_lock_data(, var); \
165 static __startup_data struct usimple_lock_startup_spec \
166 __startup_usimple_lock_spec_ ## var = { &var, arg }; \
167 STARTUP_ARG(LOCKS_EARLY, STARTUP_RANK_FOURTH, usimple_lock_startup_init, \
168 &__startup_usimple_lock_spec_ ## var)
170 #endif /* XNU_KERNEL_PRIVATE */
174 extern void * hw_wait_while_equals(
178 extern void usimple_lock_init(
183 extern void usimple_lock(
187 extern unsigned int usimple_lock_try(
191 extern void usimple_lock_try_lock_loop(
195 #if defined(__x86_64__)
196 extern unsigned int usimple_lock_try_lock_mp_signal_safe_loop_deadline(
201 extern unsigned int usimple_lock_try_lock_mp_signal_safe_loop_duration(
208 extern void usimple_lock(
210 #define usimple_lock(lck, grp) usimple_lock(lck)
213 extern unsigned int usimple_lock_try(
216 #define usimple_lock_try(lck, grp) usimple_lock_try(lck)
218 extern void usimple_lock_try_lock_loop(
220 #define usimple_lock_try_lock_loop(lck, grp) usimple_lock_try_lock_loop(lck)
222 #if defined(__x86_64__)
223 extern unsigned int usimple_lock_try_lock_mp_signal_safe_loop_deadline(
226 #define usimple_lock_try_lock_mp_signal_safe_loop_deadline(lck, ddl, grp) usimple_lock_try_lock_mp_signal_safe_loop_deadline(lck, ddl)
228 extern unsigned int usimple_lock_try_lock_mp_signal_safe_loop_duration(
231 #define usimple_lock_try_lock_mp_signal_safe_loop_duration(lck, dur, grp) usimple_lock_try_lock_mp_signal_safe_loop_duration(lck, dur)
234 #endif /* LOCK_STATS */
236 extern void usimple_unlock(
242 #define ETAP_NO_TRACE 0
243 #define ETAP_IO_AHA 0
246 * If we got to here and we still don't have simple_lock_init
247 * defined, then we must either be outside the osfmk component,
248 * running on a true SMP, or need debug.
250 #if !defined(simple_lock_init)
251 #define simple_lock_init(l, t) usimple_lock_init(l,t)
252 #define simple_lock(l, grp) usimple_lock(l, grp)
253 #define simple_unlock(l) usimple_unlock(l)
254 #define simple_lock_try(l, grp) usimple_lock_try(l, grp)
255 #define simple_lock_try_lock_loop(l, grp) usimple_lock_try_lock_loop(l, grp)
256 #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)
257 #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)
258 #define simple_lock_addr(l) (&(l))
259 #endif /* !defined(simple_lock_init) */
261 #ifdef MACH_KERNEL_PRIVATE
263 typedef uint32_t hw_lock_bit_t
;
266 extern void hw_lock_bit(
271 extern void hw_lock_bit_nopreempt(
276 extern unsigned int hw_lock_bit_try(
281 extern unsigned int hw_lock_bit_to(
288 extern void hw_lock_bit(
291 #define hw_lock_bit(lck, bit, grp) hw_lock_bit(lck, bit)
293 extern void hw_lock_bit_nopreempt(
296 #define hw_lock_bit_nopreempt(lck, bit, grp) hw_lock_bit_nopreempt(lck, bit)
298 extern unsigned int hw_lock_bit_try(
301 #define hw_lock_bit_try(lck, bit, grp) hw_lock_bit_try(lck, bit)
303 extern unsigned int hw_lock_bit_to(
307 #define hw_lock_bit_to(lck, bit, timeout, grp) hw_lock_bit_to(lck, bit, timeout)
309 #endif /* LOCK_STATS */
311 extern void hw_unlock_bit(
315 extern void hw_unlock_bit_nopreempt(
319 #define hw_lock_bit_held(l, b) (((*(l))&(1<<b))!=0)
321 #endif /* MACH_KERNEL_PRIVATE */
323 #endif /*!_KERN_SIMPLE_LOCK_H_*/
325 #endif /* KERNEL_PRIVATE */