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 XNU_KERNEL_PRIVATE
81 #if MACH_KERNEL_PRIVATE
82 #include <machine/atomic.h>
83 #include <mach_ldebug.h>
88 #pragma GCC visibility push(hidden)
90 #ifdef MACH_KERNEL_PRIVATE
91 extern void hw_lock_init(
95 extern void hw_lock_lock(
99 extern void hw_lock_lock_nopreempt(
103 extern unsigned int hw_lock_to(
108 extern unsigned int hw_lock_to_nopreempt(
113 extern unsigned int hw_lock_try(
117 extern unsigned int hw_lock_try_nopreempt(
123 extern void hw_lock_lock(
125 #define hw_lock_lock(lck, grp) \
128 extern void hw_lock_lock_nopreempt(
130 #define hw_lock_lock_nopreempt(lck, grp) \
131 hw_lock_lock_nopreempt(lck)
133 extern unsigned int hw_lock_to(
136 #define hw_lock_to(lck, timeout, grp) \
137 hw_lock_to(lck, timeout)
139 extern unsigned int hw_lock_to_nopreempt(
142 #define hw_lock_to_nopreempt(lck, timeout, grp) \
143 hw_lock_to_nopreempt(lck, timeout)
146 extern unsigned int hw_lock_try(
148 #define hw_lock_try(lck, grp) \
151 extern unsigned int hw_lock_try_nopreempt(
153 #define hw_lock_try_nopreempt(lck, grp) \
154 hw_lock_try_nopreempt(lck)
156 #endif /* LOCK_STATS */
158 extern void hw_lock_unlock(
161 extern void hw_lock_unlock_nopreempt(
164 extern unsigned int hw_lock_held(
167 extern boolean_t
hw_atomic_test_and_set32(
171 enum memory_order ord
,
174 extern void usimple_unlock_nopreempt(
177 #endif /* MACH_KERNEL_PRIVATE */
179 struct usimple_lock_startup_spec
{
181 unsigned short lck_init_arg
;
184 extern void usimple_lock_startup_init(
185 struct usimple_lock_startup_spec
*spec
);
187 #define SIMPLE_LOCK_DECLARE(var, arg) \
188 decl_simple_lock_data(, var); \
189 static __startup_data struct usimple_lock_startup_spec \
190 __startup_usimple_lock_spec_ ## var = { &var, arg }; \
191 STARTUP_ARG(LOCKS_EARLY, STARTUP_RANK_FOURTH, usimple_lock_startup_init, \
192 &__startup_usimple_lock_spec_ ## var)
194 extern void * hw_wait_while_equals(
198 extern void usimple_lock_init(
203 extern void usimple_lock(
207 extern unsigned int usimple_lock_try(
211 extern void usimple_lock_try_lock_loop(
215 #if defined(__x86_64__)
216 extern unsigned int usimple_lock_try_lock_mp_signal_safe_loop_deadline(
221 extern unsigned int usimple_lock_try_lock_mp_signal_safe_loop_duration(
227 extern void usimple_lock(
229 #define usimple_lock(lck, grp) \
233 extern unsigned int usimple_lock_try(
235 #define usimple_lock_try(lck, grp) \
236 usimple_lock_try(lck)
238 extern void usimple_lock_try_lock_loop(
240 #define usimple_lock_try_lock_loop(lck, grp) \
241 usimple_lock_try_lock_loop(lck)
243 #if defined(__x86_64__)
244 extern unsigned int usimple_lock_try_lock_mp_signal_safe_loop_deadline(
247 #define usimple_lock_try_lock_mp_signal_safe_loop_deadline(lck, ddl, grp) \
248 usimple_lock_try_lock_mp_signal_safe_loop_deadline(lck, ddl)
250 extern unsigned int usimple_lock_try_lock_mp_signal_safe_loop_duration(
253 #define usimple_lock_try_lock_mp_signal_safe_loop_duration(lck, dur, grp) \
254 usimple_lock_try_lock_mp_signal_safe_loop_duration(lck, dur)
257 #endif /* LOCK_STATS */
259 extern void usimple_unlock(
264 * If we got to here and we still don't have simple_lock_init
265 * defined, then we must either be outside the osfmk component,
266 * running on a true SMP, or need debug.
268 #if !defined(simple_lock_init)
269 #define simple_lock_init(l, t) usimple_lock_init(l,t)
270 #define simple_lock(l, grp) usimple_lock(l, grp)
271 #define simple_unlock(l) usimple_unlock(l)
272 #define simple_lock_try(l, grp) usimple_lock_try(l, grp)
273 #define simple_lock_try_lock_loop(l, grp) usimple_lock_try_lock_loop(l, grp)
274 #define simple_lock_try_lock_mp_signal_safe_loop_deadline(l, ddl, grp) \
275 usimple_lock_try_lock_mp_signal_safe_loop_deadline(l, ddl, grp)
276 #define simple_lock_try_lock_mp_signal_safe_loop_duration(l, dur, grp) \
277 usimple_lock_try_lock_mp_signal_safe_loop_duration(l, dur, grp)
278 #define simple_lock_addr(l) (&(l))
279 #endif /* !defined(simple_lock_init) */
281 #ifdef MACH_KERNEL_PRIVATE
283 typedef uint32_t hw_lock_bit_t
;
286 extern void hw_lock_bit(
291 extern void hw_lock_bit_nopreempt(
296 extern unsigned int hw_lock_bit_try(
301 extern unsigned int hw_lock_bit_to(
308 extern void hw_lock_bit(
311 #define hw_lock_bit(lck, bit, grp) \
312 hw_lock_bit(lck, bit)
314 extern void hw_lock_bit_nopreempt(
317 #define hw_lock_bit_nopreempt(lck, bit, grp) \
318 hw_lock_bit_nopreempt(lck, bit)
320 extern unsigned int hw_lock_bit_try(
323 #define hw_lock_bit_try(lck, bit, grp) \
324 hw_lock_bit_try(lck, bit)
326 extern unsigned int hw_lock_bit_to(
330 #define hw_lock_bit_to(lck, bit, timeout, grp) \
331 hw_lock_bit_to(lck, bit, timeout)
333 #endif /* LOCK_STATS */
335 extern void hw_unlock_bit(
339 extern void hw_unlock_bit_nopreempt(
343 #define hw_lock_bit_held(l, b) \
344 (((*(l)) & (1 << (b))) != 0)
346 #endif /* MACH_KERNEL_PRIVATE */
350 #pragma GCC visibility pop
352 #endif /* XNU_KERNEL_PRIVATE */
353 #endif /*!_KERN_SIMPLE_LOCK_H_*/
355 #endif /* KERNEL_PRIVATE */