]> git.saurik.com Git - apple/xnu.git/blob - osfmk/kern/simple_lock.h
xnu-7195.60.75.tar.gz
[apple/xnu.git] / osfmk / kern / simple_lock.h
1 /*
2 * Copyright (c) 2000-2005 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
5 *
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.
14 *
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
17 *
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.
25 *
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
27 */
28 /*
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.
39 *
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.
45 *
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.
49 *
50 * Carnegie Mellon requests users of this software to return to
51 *
52 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
53 * School of Computer Science
54 * Carnegie Mellon University
55 * Pittsburgh PA 15213-3890
56 *
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 *
65 * Atomic primitives and Simple Locking primitives definitions
66 */
67
68 #ifdef KERNEL_PRIVATE
69
70 #ifndef _KERN_SIMPLE_LOCK_H_
71 #define _KERN_SIMPLE_LOCK_H_
72
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>
78
79 #ifdef MACH_KERNEL_PRIVATE
80 #include <machine/atomic.h>
81 #include <mach_ldebug.h>
82
83 extern void hw_lock_init(
84 hw_lock_t);
85
86 #if LOCK_STATS
87 extern void hw_lock_lock(
88 hw_lock_t,
89 lck_grp_t*);
90
91 extern void hw_lock_lock_nopreempt(
92 hw_lock_t,
93 lck_grp_t*);
94
95 extern unsigned int hw_lock_to(
96 hw_lock_t,
97 uint64_t,
98 lck_grp_t*);
99
100 extern unsigned int hw_lock_try(
101 hw_lock_t,
102 lck_grp_t*);
103
104 extern unsigned int hw_lock_try_nopreempt(
105 hw_lock_t,
106 lck_grp_t*);
107
108 #else
109
110 extern void hw_lock_lock(
111 hw_lock_t);
112
113 #define hw_lock_lock(lck, grp) hw_lock_lock(lck)
114
115 extern void hw_lock_lock_nopreempt(
116 hw_lock_t);
117 #define hw_lock_lock_nopreempt(lck, grp) hw_lock_lock_nopreempt(lck)
118
119 extern unsigned int hw_lock_to(
120 hw_lock_t,
121 uint64_t);
122 #define hw_lock_to(lck, timeout, grp) hw_lock_to(lck, timeout)
123
124
125 extern unsigned int hw_lock_try(
126 hw_lock_t);
127 #define hw_lock_try(lck, grp) hw_lock_try(lck)
128
129 extern unsigned int hw_lock_try_nopreempt(
130 hw_lock_t);
131 #define hw_lock_try_nopreempt(lck, grp) hw_lock_try_nopreempt(lck)
132
133
134 #endif /* LOCK_STATS */
135
136 extern void hw_lock_unlock(
137 hw_lock_t);
138
139 extern void hw_lock_unlock_nopreempt(
140 hw_lock_t);
141
142 extern unsigned int hw_lock_held(
143 hw_lock_t);
144
145 extern boolean_t hw_atomic_test_and_set32(
146 uint32_t *target,
147 uint32_t test_mask,
148 uint32_t set_mask,
149 enum memory_order ord,
150 boolean_t wait);
151
152 #endif /* MACH_KERNEL_PRIVATE */
153 #if XNU_KERNEL_PRIVATE
154
155 struct usimple_lock_startup_spec {
156 usimple_lock_t lck;
157 unsigned short lck_init_arg;
158 };
159
160 extern void usimple_lock_startup_init(
161 struct usimple_lock_startup_spec *spec);
162
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)
169
170 #endif /* XNU_KERNEL_PRIVATE */
171
172 __BEGIN_DECLS
173
174 extern void * hw_wait_while_equals(
175 void **address,
176 void *current);
177
178 extern void usimple_lock_init(
179 usimple_lock_t,
180 unsigned short);
181
182 #if LOCK_STATS
183 extern void usimple_lock(
184 usimple_lock_t,
185 lck_grp_t*);
186
187 extern unsigned int usimple_lock_try(
188 usimple_lock_t,
189 lck_grp_t*);
190
191 extern void usimple_lock_try_lock_loop(
192 usimple_lock_t,
193 lck_grp_t*);
194
195 #if defined(__x86_64__)
196 extern unsigned int usimple_lock_try_lock_mp_signal_safe_loop_deadline(
197 usimple_lock_t,
198 uint64_t,
199 lck_grp_t*);
200
201 extern unsigned int usimple_lock_try_lock_mp_signal_safe_loop_duration(
202 usimple_lock_t,
203 uint64_t,
204 lck_grp_t*);
205 #endif
206
207 #else
208 extern void usimple_lock(
209 usimple_lock_t);
210 #define usimple_lock(lck, grp) usimple_lock(lck)
211
212
213 extern unsigned int usimple_lock_try(
214 usimple_lock_t);
215
216 #define usimple_lock_try(lck, grp) usimple_lock_try(lck)
217
218 extern void usimple_lock_try_lock_loop(
219 usimple_lock_t);
220 #define usimple_lock_try_lock_loop(lck, grp) usimple_lock_try_lock_loop(lck)
221
222 #if defined(__x86_64__)
223 extern unsigned int usimple_lock_try_lock_mp_signal_safe_loop_deadline(
224 usimple_lock_t,
225 uint64_t);
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)
227
228 extern unsigned int usimple_lock_try_lock_mp_signal_safe_loop_duration(
229 usimple_lock_t,
230 uint64_t);
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)
232 #endif
233
234 #endif /* LOCK_STATS */
235
236 extern void usimple_unlock(
237 usimple_lock_t);
238
239
240 __END_DECLS
241
242 #define ETAP_NO_TRACE 0
243 #define ETAP_IO_AHA 0
244
245 /*
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.
249 */
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) */
260
261 #ifdef MACH_KERNEL_PRIVATE
262
263 typedef uint32_t hw_lock_bit_t;
264
265 #if LOCK_STATS
266 extern void hw_lock_bit(
267 hw_lock_bit_t *,
268 unsigned int,
269 lck_grp_t*);
270
271 extern void hw_lock_bit_nopreempt(
272 hw_lock_bit_t *,
273 unsigned int,
274 lck_grp_t*);
275
276 extern unsigned int hw_lock_bit_try(
277 hw_lock_bit_t *,
278 unsigned int,
279 lck_grp_t*);
280
281 extern unsigned int hw_lock_bit_to(
282 hw_lock_bit_t *,
283 unsigned int,
284 uint32_t,
285 lck_grp_t*);
286
287 #else
288 extern void hw_lock_bit(
289 hw_lock_bit_t *,
290 unsigned int);
291 #define hw_lock_bit(lck, bit, grp) hw_lock_bit(lck, bit)
292
293 extern void hw_lock_bit_nopreempt(
294 hw_lock_bit_t *,
295 unsigned int);
296 #define hw_lock_bit_nopreempt(lck, bit, grp) hw_lock_bit_nopreempt(lck, bit)
297
298 extern unsigned int hw_lock_bit_try(
299 hw_lock_bit_t *,
300 unsigned int);
301 #define hw_lock_bit_try(lck, bit, grp) hw_lock_bit_try(lck, bit)
302
303 extern unsigned int hw_lock_bit_to(
304 hw_lock_bit_t *,
305 unsigned int,
306 uint32_t);
307 #define hw_lock_bit_to(lck, bit, timeout, grp) hw_lock_bit_to(lck, bit, timeout)
308
309 #endif /* LOCK_STATS */
310
311 extern void hw_unlock_bit(
312 hw_lock_bit_t *,
313 unsigned int);
314
315 extern void hw_unlock_bit_nopreempt(
316 hw_lock_bit_t *,
317 unsigned int);
318
319 #define hw_lock_bit_held(l, b) (((*(l))&(1<<b))!=0)
320
321 #endif /* MACH_KERNEL_PRIVATE */
322
323 #endif /*!_KERN_SIMPLE_LOCK_H_*/
324
325 #endif /* KERNEL_PRIVATE */