]> git.saurik.com Git - apple/xnu.git/blob - osfmk/kern/simple_lock.h
xnu-6153.121.1.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(uint32_t *target, uint32_t test_mask, uint32_t set_mask, enum memory_order ord, boolean_t wait);
146 #endif /* MACH_KERNEL_PRIVATE */
147
148 __BEGIN_DECLS
149
150 extern void * hw_wait_while_equals(
151 void **address,
152 void *current);
153
154 extern void usimple_lock_init(
155 usimple_lock_t,
156 unsigned short);
157
158 #if LOCK_STATS
159 extern void usimple_lock(
160 usimple_lock_t,
161 lck_grp_t*);
162
163 extern unsigned int usimple_lock_try(
164 usimple_lock_t,
165 lck_grp_t*);
166
167 extern void usimple_lock_try_lock_loop(
168 usimple_lock_t,
169 lck_grp_t*);
170
171 #if defined(__x86_64__)
172 extern unsigned int usimple_lock_try_lock_mp_signal_safe_loop_deadline(
173 usimple_lock_t,
174 uint64_t,
175 lck_grp_t*);
176
177 extern unsigned int usimple_lock_try_lock_mp_signal_safe_loop_duration(
178 usimple_lock_t,
179 uint64_t,
180 lck_grp_t*);
181 #endif
182
183 #else
184 extern void usimple_lock(
185 usimple_lock_t);
186 #define usimple_lock(lck, grp) usimple_lock(lck)
187
188
189 extern unsigned int usimple_lock_try(
190 usimple_lock_t);
191
192 #define usimple_lock_try(lck, grp) usimple_lock_try(lck)
193
194 extern void usimple_lock_try_lock_loop(
195 usimple_lock_t);
196 #define usimple_lock_try_lock_loop(lck, grp) usimple_lock_try_lock_loop(lck)
197
198 #if defined(__x86_64__)
199 extern unsigned int usimple_lock_try_lock_mp_signal_safe_loop_deadline(
200 usimple_lock_t,
201 uint64_t);
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)
203
204 extern unsigned int usimple_lock_try_lock_mp_signal_safe_loop_duration(
205 usimple_lock_t,
206 uint64_t);
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)
208 #endif
209
210 #endif /* LOCK_STATS */
211
212 extern void usimple_unlock(
213 usimple_lock_t);
214
215
216 __END_DECLS
217
218 #define ETAP_NO_TRACE 0
219 #define ETAP_IO_AHA 0
220
221 /*
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.
225 */
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) */
236
237 #ifdef MACH_KERNEL_PRIVATE
238
239 typedef uint32_t hw_lock_bit_t;
240
241 #if LOCK_STATS
242 extern void hw_lock_bit(
243 hw_lock_bit_t *,
244 unsigned int,
245 lck_grp_t*);
246
247 extern void hw_lock_bit_nopreempt(
248 hw_lock_bit_t *,
249 unsigned int,
250 lck_grp_t*);
251
252 extern unsigned int hw_lock_bit_try(
253 hw_lock_bit_t *,
254 unsigned int,
255 lck_grp_t*);
256
257 extern unsigned int hw_lock_bit_to(
258 hw_lock_bit_t *,
259 unsigned int,
260 uint32_t,
261 lck_grp_t*);
262
263 #else
264 extern void hw_lock_bit(
265 hw_lock_bit_t *,
266 unsigned int);
267 #define hw_lock_bit(lck, bit, grp) hw_lock_bit(lck, bit)
268
269 extern void hw_lock_bit_nopreempt(
270 hw_lock_bit_t *,
271 unsigned int);
272 #define hw_lock_bit_nopreempt(lck, bit, grp) hw_lock_bit_nopreempt(lck, bit)
273
274 extern unsigned int hw_lock_bit_try(
275 hw_lock_bit_t *,
276 unsigned int);
277 #define hw_lock_bit_try(lck, bit, grp) hw_lock_bit_try(lck, bit)
278
279 extern unsigned int hw_lock_bit_to(
280 hw_lock_bit_t *,
281 unsigned int,
282 uint32_t);
283 #define hw_lock_bit_to(lck, bit, timeout, grp) hw_lock_bit_to(lck, bit, timeout)
284
285 #endif /* LOCK_STATS */
286
287 extern void hw_unlock_bit(
288 hw_lock_bit_t *,
289 unsigned int);
290
291 extern void hw_unlock_bit_nopreempt(
292 hw_lock_bit_t *,
293 unsigned int);
294
295 #define hw_lock_bit_held(l, b) (((*(l))&(1<<b))!=0)
296
297 #endif /* MACH_KERNEL_PRIVATE */
298
299 #endif /*!_KERN_SIMPLE_LOCK_H_*/
300
301 #endif /* KERNEL_PRIVATE */