]> git.saurik.com Git - apple/xnu.git/blame - osfmk/kern/simple_lock.h
xnu-7195.101.1.tar.gz
[apple/xnu.git] / osfmk / kern / simple_lock.h
CommitLineData
1c79356b 1/*
91447636 2 * Copyright (c) 2000-2005 Apple Computer, Inc. All rights reserved.
1c79356b 3 *
2d21ac55 4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
0a7de745 5 *
2d21ac55
A
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.
0a7de745 14 *
2d21ac55
A
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
0a7de745 17 *
2d21ac55
A
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
8f6c56a5
A
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
2d21ac55
A
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.
0a7de745 25 *
2d21ac55 26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
1c79356b 27 */
0a7de745 28/*
1c79356b
A
29 * Copyright (C) 1998 Apple Computer
30 * All Rights Reserved
31 */
32/*
33 * @OSF_COPYRIGHT@
34 */
35/*
36 * Mach Operating System
37 * Copyright (c) 1991,1990,1989,1988,1987 Carnegie Mellon University
38 * All Rights Reserved.
0a7de745 39 *
1c79356b
A
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.
0a7de745 45 *
1c79356b
A
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.
0a7de745 49 *
1c79356b 50 * Carnegie Mellon requests users of this software to return to
0a7de745 51 *
1c79356b
A
52 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
53 * School of Computer Science
54 * Carnegie Mellon University
55 * Pittsburgh PA 15213-3890
0a7de745 56 *
1c79356b
A
57 * any improvements or extensions that they make and grant Carnegie Mellon
58 * the rights to redistribute these changes.
59 */
60/*
61 * File: kern/simple_lock.h (derived from kern/lock.h)
62 * Author: Avadis Tevanian, Jr., Michael Wayne Young
63 * Date: 1985
64 *
91447636 65 * Atomic primitives and Simple Locking primitives definitions
1c79356b
A
66 */
67
0a7de745 68#ifdef KERNEL_PRIVATE
1c79356b 69
0a7de745
A
70#ifndef _KERN_SIMPLE_LOCK_H_
71#define _KERN_SIMPLE_LOCK_H_
1c79356b 72
91447636 73#include <sys/cdefs.h>
1c79356b
A
74#include <mach/boolean.h>
75#include <kern/kern_types.h>
0a7de745 76#include <kern/lock_group.h>
91447636 77#include <machine/simple_lock.h>
9bccf70c 78
c3c9b80d
A
79#ifdef XNU_KERNEL_PRIVATE
80
81#if MACH_KERNEL_PRIVATE
cb323159 82#include <machine/atomic.h>
91447636 83#include <mach_ldebug.h>
c3c9b80d
A
84#endif
85
86__BEGIN_DECLS
87
88#pragma GCC visibility push(hidden)
9bccf70c 89
c3c9b80d 90#ifdef MACH_KERNEL_PRIVATE
0a7de745
A
91extern void hw_lock_init(
92 hw_lock_t);
93
94#if LOCK_STATS
95extern void hw_lock_lock(
96 hw_lock_t,
97 lck_grp_t*);
98
99extern void hw_lock_lock_nopreempt(
100 hw_lock_t,
101 lck_grp_t*);
102
103extern unsigned int hw_lock_to(
104 hw_lock_t,
105 uint64_t,
106 lck_grp_t*);
9bccf70c 107
c3c9b80d
A
108extern unsigned int hw_lock_to_nopreempt(
109 hw_lock_t,
110 uint64_t,
111 lck_grp_t*);
112
0a7de745
A
113extern unsigned int hw_lock_try(
114 hw_lock_t,
115 lck_grp_t*);
9bccf70c 116
0a7de745
A
117extern unsigned int hw_lock_try_nopreempt(
118 hw_lock_t,
119 lck_grp_t*);
d9a64523 120
0a7de745 121#else
1c79356b 122
0a7de745
A
123extern void hw_lock_lock(
124 hw_lock_t);
c3c9b80d
A
125#define hw_lock_lock(lck, grp) \
126 hw_lock_lock(lck)
9bccf70c 127
0a7de745
A
128extern void hw_lock_lock_nopreempt(
129 hw_lock_t);
c3c9b80d
A
130#define hw_lock_lock_nopreempt(lck, grp) \
131 hw_lock_lock_nopreempt(lck)
9bccf70c 132
0a7de745
A
133extern unsigned int hw_lock_to(
134 hw_lock_t,
135 uint64_t);
c3c9b80d
A
136#define hw_lock_to(lck, timeout, grp) \
137 hw_lock_to(lck, timeout)
138
139extern unsigned int hw_lock_to_nopreempt(
140 hw_lock_t,
141 uint64_t);
142#define hw_lock_to_nopreempt(lck, timeout, grp) \
143 hw_lock_to_nopreempt(lck, timeout)
d9a64523 144
9bccf70c 145
0a7de745
A
146extern unsigned int hw_lock_try(
147 hw_lock_t);
c3c9b80d
A
148#define hw_lock_try(lck, grp) \
149 hw_lock_try(lck)
0a7de745
A
150
151extern unsigned int hw_lock_try_nopreempt(
152 hw_lock_t);
c3c9b80d
A
153#define hw_lock_try_nopreempt(lck, grp) \
154 hw_lock_try_nopreempt(lck)
0a7de745
A
155
156#endif /* LOCK_STATS */
157
158extern void hw_lock_unlock(
159 hw_lock_t);
160
161extern void hw_lock_unlock_nopreempt(
162 hw_lock_t);
163
164extern unsigned int hw_lock_held(
165 hw_lock_t);
166
f427ee49
A
167extern boolean_t hw_atomic_test_and_set32(
168 uint32_t *target,
169 uint32_t test_mask,
170 uint32_t set_mask,
171 enum memory_order ord,
172 boolean_t wait);
173
c3c9b80d
A
174extern void usimple_unlock_nopreempt(
175 usimple_lock_t);
176
f427ee49 177#endif /* MACH_KERNEL_PRIVATE */
f427ee49
A
178
179struct usimple_lock_startup_spec {
180 usimple_lock_t lck;
181 unsigned short lck_init_arg;
182};
183
184extern void usimple_lock_startup_init(
185 struct usimple_lock_startup_spec *spec);
186
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)
193
cb323159
A
194extern void * hw_wait_while_equals(
195 void **address,
196 void *current);
0a7de745
A
197
198extern void usimple_lock_init(
199 usimple_lock_t,
200 unsigned short);
201
202#if LOCK_STATS
203extern void usimple_lock(
204 usimple_lock_t,
205 lck_grp_t*);
1c79356b 206
0a7de745
A
207extern unsigned int usimple_lock_try(
208 usimple_lock_t,
209 lck_grp_t*);
1c79356b 210
0a7de745
A
211extern void usimple_lock_try_lock_loop(
212 usimple_lock_t,
213 lck_grp_t*);
cb323159
A
214
215#if defined(__x86_64__)
216extern unsigned int usimple_lock_try_lock_mp_signal_safe_loop_deadline(
217 usimple_lock_t,
218 uint64_t,
219 lck_grp_t*);
220
221extern unsigned int usimple_lock_try_lock_mp_signal_safe_loop_duration(
222 usimple_lock_t,
223 uint64_t,
224 lck_grp_t*);
225#endif
0a7de745
A
226#else
227extern void usimple_lock(
228 usimple_lock_t);
c3c9b80d
A
229#define usimple_lock(lck, grp) \
230 usimple_lock(lck)
1c79356b 231
1c79356b 232
0a7de745
A
233extern unsigned int usimple_lock_try(
234 usimple_lock_t);
c3c9b80d
A
235#define usimple_lock_try(lck, grp) \
236 usimple_lock_try(lck)
9bccf70c 237
0a7de745
A
238extern void usimple_lock_try_lock_loop(
239 usimple_lock_t);
c3c9b80d
A
240#define usimple_lock_try_lock_loop(lck, grp) \
241 usimple_lock_try_lock_loop(lck)
1c79356b 242
cb323159
A
243#if defined(__x86_64__)
244extern unsigned int usimple_lock_try_lock_mp_signal_safe_loop_deadline(
245 usimple_lock_t,
246 uint64_t);
c3c9b80d
A
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)
cb323159
A
249
250extern unsigned int usimple_lock_try_lock_mp_signal_safe_loop_duration(
251 usimple_lock_t,
252 uint64_t);
c3c9b80d
A
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)
cb323159
A
255#endif
256
0a7de745 257#endif /* LOCK_STATS */
1c79356b 258
0a7de745
A
259extern void usimple_unlock(
260 usimple_lock_t);
1c79356b 261
39037602 262
1c79356b
A
263/*
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.
267 */
268#if !defined(simple_lock_init)
c3c9b80d
A
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)
0a7de745 273#define simple_lock_try_lock_loop(l, grp) usimple_lock_try_lock_loop(l, grp)
c3c9b80d
A
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)
0a7de745 278#define simple_lock_addr(l) (&(l))
55e303ae 279#endif /* !defined(simple_lock_init) */
1c79356b 280
cb323159
A
281#ifdef MACH_KERNEL_PRIVATE
282
283typedef uint32_t hw_lock_bit_t;
284
285#if LOCK_STATS
286extern void hw_lock_bit(
287 hw_lock_bit_t *,
288 unsigned int,
289 lck_grp_t*);
290
291extern void hw_lock_bit_nopreempt(
292 hw_lock_bit_t *,
293 unsigned int,
294 lck_grp_t*);
295
296extern unsigned int hw_lock_bit_try(
297 hw_lock_bit_t *,
298 unsigned int,
299 lck_grp_t*);
300
301extern unsigned int hw_lock_bit_to(
302 hw_lock_bit_t *,
303 unsigned int,
304 uint32_t,
305 lck_grp_t*);
306
307#else
308extern void hw_lock_bit(
309 hw_lock_bit_t *,
310 unsigned int);
c3c9b80d
A
311#define hw_lock_bit(lck, bit, grp) \
312 hw_lock_bit(lck, bit)
cb323159
A
313
314extern void hw_lock_bit_nopreempt(
315 hw_lock_bit_t *,
316 unsigned int);
c3c9b80d
A
317#define hw_lock_bit_nopreempt(lck, bit, grp) \
318 hw_lock_bit_nopreempt(lck, bit)
cb323159
A
319
320extern unsigned int hw_lock_bit_try(
321 hw_lock_bit_t *,
322 unsigned int);
c3c9b80d
A
323#define hw_lock_bit_try(lck, bit, grp) \
324 hw_lock_bit_try(lck, bit)
cb323159
A
325
326extern unsigned int hw_lock_bit_to(
327 hw_lock_bit_t *,
328 unsigned int,
329 uint32_t);
c3c9b80d
A
330#define hw_lock_bit_to(lck, bit, timeout, grp) \
331 hw_lock_bit_to(lck, bit, timeout)
cb323159
A
332
333#endif /* LOCK_STATS */
334
335extern void hw_unlock_bit(
336 hw_lock_bit_t *,
337 unsigned int);
338
339extern void hw_unlock_bit_nopreempt(
340 hw_lock_bit_t *,
341 unsigned int);
342
c3c9b80d
A
343#define hw_lock_bit_held(l, b) \
344 (((*(l)) & (1 << (b))) != 0)
cb323159
A
345
346#endif /* MACH_KERNEL_PRIVATE */
347
c3c9b80d
A
348__END_DECLS
349
350#pragma GCC visibility pop
351
352#endif /* XNU_KERNEL_PRIVATE */
91447636 353#endif /*!_KERN_SIMPLE_LOCK_H_*/
1c79356b 354
0a7de745 355#endif /* KERNEL_PRIVATE */