]>
Commit | Line | Data |
---|---|---|
91447636 A |
1 | /* |
2 | * Copyright (c) 2003-2005 Apple Computer, Inc. All rights reserved. | |
3 | * | |
4 | * @APPLE_LICENSE_HEADER_START@ | |
37839358 A |
5 | * |
6 | * The contents of this file constitute Original Code as defined in and | |
7 | * are subject to the Apple Public Source License Version 1.1 (the | |
8 | * "License"). You may not use this file except in compliance with the | |
9 | * License. Please obtain a copy of the License at | |
10 | * http://www.apple.com/publicsource and read it before using this file. | |
11 | * | |
12 | * This Original Code and all software distributed under the License are | |
13 | * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER | |
91447636 A |
14 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, |
15 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
37839358 A |
16 | * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the |
17 | * License for the specific language governing rights and limitations | |
18 | * under the License. | |
19 | * | |
91447636 A |
20 | * @APPLE_LICENSE_HEADER_END@ |
21 | */ | |
22 | ||
23 | #ifndef _KERN_LOCKS_H_ | |
24 | #define _KERN_LOCKS_H_ | |
25 | ||
26 | #include <sys/cdefs.h> | |
27 | #include <sys/appleapiopts.h> | |
28 | #include <mach/boolean.h> | |
29 | #include <mach/mach_types.h> | |
30 | #include <kern/kern_types.h> | |
31 | #include <machine/locks.h> | |
32 | ||
33 | #ifdef MACH_KERNEL_PRIVATE | |
34 | #include <kern/queue.h> | |
35 | ||
36 | extern void lck_mod_init( | |
37 | void); | |
38 | ||
39 | typedef unsigned int lck_type_t; | |
40 | ||
41 | #define LCK_TYPE_SPIN 1 | |
42 | #define LCK_TYPE_MTX 2 | |
43 | #define LCK_TYPE_RW 3 | |
44 | ||
45 | #endif | |
46 | ||
47 | typedef unsigned int lck_sleep_action_t; | |
48 | ||
49 | #define LCK_SLEEP_DEFAULT 0x00 /* Release the lock while waiting for the event, then reclaim */ | |
50 | /* RW locks are returned in the same mode */ | |
51 | #define LCK_SLEEP_UNLOCK 0x01 /* Release the lock and return unheld */ | |
52 | #define LCK_SLEEP_SHARED 0x02 /* Reclaim the lock in shared mode (RW only) */ | |
53 | #define LCK_SLEEP_EXCLUSIVE 0x04 /* Reclaim the lock in exclusive mode (RW only) */ | |
54 | ||
55 | #define LCK_SLEEP_MASK 0x07 /* Valid actions */ | |
56 | ||
57 | #ifdef MACH_KERNEL_PRIVATE | |
58 | ||
59 | typedef struct { | |
60 | uint64_t lck_grp_spin_util_cnt; | |
61 | uint64_t lck_grp_spin_held_cnt; | |
62 | uint64_t lck_grp_spin_miss_cnt; | |
63 | uint64_t lck_grp_spin_held_max; | |
64 | uint64_t lck_grp_spin_held_cum; | |
65 | } lck_grp_spin_stat_t; | |
66 | ||
67 | typedef struct { | |
68 | uint64_t lck_grp_mtx_util_cnt; | |
69 | uint64_t lck_grp_mtx_held_cnt; | |
70 | uint64_t lck_grp_mtx_miss_cnt; | |
71 | uint64_t lck_grp_mtx_wait_cnt; | |
72 | uint64_t lck_grp_mtx_held_max; | |
73 | uint64_t lck_grp_mtx_held_cum; | |
74 | uint64_t lck_grp_mtx_wait_max; | |
75 | uint64_t lck_grp_mtx_wait_cum; | |
76 | } lck_grp_mtx_stat_t; | |
77 | ||
78 | typedef struct { | |
79 | uint64_t lck_grp_rw_util_cnt; | |
80 | uint64_t lck_grp_rw_held_cnt; | |
81 | uint64_t lck_grp_rw_miss_cnt; | |
82 | uint64_t lck_grp_rw_wait_cnt; | |
83 | uint64_t lck_grp_rw_held_max; | |
84 | uint64_t lck_grp_rw_held_cum; | |
85 | uint64_t lck_grp_rw_wait_max; | |
86 | uint64_t lck_grp_rw_wait_cum; | |
87 | } lck_grp_rw_stat_t; | |
88 | ||
89 | typedef struct _lck_grp_stat_ { | |
90 | lck_grp_spin_stat_t lck_grp_spin_stat; | |
91 | lck_grp_mtx_stat_t lck_grp_mtx_stat; | |
92 | lck_grp_rw_stat_t lck_grp_rw_stat; | |
93 | } lck_grp_stat_t; | |
94 | ||
95 | #define LCK_GRP_MAX_NAME 64 | |
96 | ||
97 | typedef struct _lck_grp_ { | |
98 | queue_chain_t lck_grp_link; | |
99 | unsigned int lck_grp_refcnt; | |
100 | unsigned int lck_grp_spincnt; | |
101 | unsigned int lck_grp_mtxcnt; | |
102 | unsigned int lck_grp_rwcnt; | |
103 | unsigned int lck_grp_attr; | |
104 | char lck_grp_name[LCK_GRP_MAX_NAME]; | |
105 | lck_grp_stat_t lck_grp_stat; | |
106 | } lck_grp_t; | |
107 | ||
108 | #define LCK_GRP_NULL (lck_grp_t *)0 | |
109 | ||
110 | #else | |
111 | typedef struct __lck_grp__ lck_grp_t; | |
112 | #endif | |
113 | ||
114 | #ifdef MACH_KERNEL_PRIVATE | |
115 | typedef struct _lck_grp_attr_ { | |
116 | unsigned int grp_attr_val; | |
117 | } lck_grp_attr_t; | |
118 | ||
119 | extern lck_grp_attr_t LockDefaultGroupAttr; | |
120 | ||
121 | #define LCK_GRP_ATTR_STAT 0x1 | |
122 | ||
123 | #else | |
124 | typedef struct __lck_grp_attr__ lck_grp_attr_t; | |
125 | #endif | |
126 | ||
127 | #define LCK_GRP_ATTR_NULL (lck_grp_attr_t *)0 | |
128 | ||
129 | __BEGIN_DECLS | |
130 | ||
131 | extern lck_grp_attr_t *lck_grp_attr_alloc_init( | |
132 | void); | |
133 | ||
134 | extern void lck_grp_attr_setdefault( | |
135 | lck_grp_attr_t *attr); | |
136 | ||
137 | extern void lck_grp_attr_setstat( | |
138 | lck_grp_attr_t *attr); | |
139 | ||
140 | extern void lck_grp_attr_free( | |
141 | lck_grp_attr_t *attr); | |
142 | ||
143 | extern lck_grp_t *lck_grp_alloc_init( | |
144 | const char* grp_name, | |
145 | lck_grp_attr_t *attr); | |
146 | ||
147 | __END_DECLS | |
148 | ||
149 | #ifdef MACH_KERNEL_PRIVATE | |
150 | extern void lck_grp_init( | |
151 | lck_grp_t *grp, | |
152 | const char* grp_name, | |
153 | lck_grp_attr_t *attr); | |
154 | ||
155 | extern void lck_grp_reference( | |
156 | lck_grp_t *grp); | |
157 | ||
158 | extern void lck_grp_deallocate( | |
159 | lck_grp_t *grp); | |
160 | ||
161 | extern void lck_grp_lckcnt_incr( | |
162 | lck_grp_t *grp, | |
163 | lck_type_t lck_type); | |
164 | ||
165 | extern void lck_grp_lckcnt_decr( | |
166 | lck_grp_t *grp, | |
167 | lck_type_t lck_type); | |
168 | #endif | |
169 | ||
170 | __BEGIN_DECLS | |
171 | ||
172 | extern void lck_grp_free( | |
173 | lck_grp_t *grp); | |
174 | ||
175 | __END_DECLS | |
176 | ||
177 | #ifdef MACH_KERNEL_PRIVATE | |
178 | typedef struct _lck_attr_ { | |
179 | unsigned int lck_attr_val; | |
180 | } lck_attr_t; | |
181 | ||
182 | extern lck_attr_t LockDefaultLckAttr; | |
183 | ||
c0fea474 A |
184 | #define LCK_ATTR_NONE 0 |
185 | ||
186 | #define LCK_ATTR_DEBUG 0x00000001 | |
187 | #define LCK_ATTR_RW_SHARED_PRIORITY 0x00010000 | |
91447636 A |
188 | |
189 | #else | |
190 | typedef struct __lck_attr__ lck_attr_t; | |
191 | #endif | |
192 | ||
193 | #define LCK_ATTR_NULL (lck_attr_t *)0 | |
194 | ||
195 | __BEGIN_DECLS | |
196 | ||
197 | extern lck_attr_t *lck_attr_alloc_init( | |
198 | void); | |
199 | ||
200 | extern void lck_attr_setdefault( | |
201 | lck_attr_t *attr); | |
202 | ||
203 | extern void lck_attr_setdebug( | |
204 | lck_attr_t *attr); | |
205 | ||
c0fea474 A |
206 | #ifdef XNU_KERNEL_PRIVATE |
207 | extern void lck_attr_rw_shared_priority( | |
208 | lck_attr_t *attr); | |
209 | #endif | |
210 | ||
91447636 A |
211 | extern void lck_attr_free( |
212 | lck_attr_t *attr); | |
213 | ||
214 | #define decl_lck_spin_data(class,name) class lck_spin_t name; | |
215 | ||
216 | extern lck_spin_t *lck_spin_alloc_init( | |
217 | lck_grp_t *grp, | |
218 | lck_attr_t *attr); | |
219 | ||
220 | extern void lck_spin_init( | |
221 | lck_spin_t *lck, | |
222 | lck_grp_t *grp, | |
223 | lck_attr_t *attr); | |
224 | ||
225 | extern void lck_spin_lock( | |
226 | lck_spin_t *lck); | |
227 | ||
228 | extern void lck_spin_unlock( | |
229 | lck_spin_t *lck); | |
230 | ||
231 | extern void lck_spin_destroy( | |
232 | lck_spin_t *lck, | |
233 | lck_grp_t *grp); | |
234 | ||
235 | extern void lck_spin_free( | |
236 | lck_spin_t *lck, | |
237 | lck_grp_t *grp); | |
238 | ||
239 | extern wait_result_t lck_spin_sleep( | |
240 | lck_spin_t *lck, | |
241 | lck_sleep_action_t lck_sleep_action, | |
242 | event_t event, | |
243 | wait_interrupt_t interruptible); | |
244 | ||
245 | extern wait_result_t lck_spin_sleep_deadline( | |
246 | lck_spin_t *lck, | |
247 | lck_sleep_action_t lck_sleep_action, | |
248 | event_t event, | |
249 | wait_interrupt_t interruptible, | |
250 | uint64_t deadline); | |
251 | ||
252 | #ifdef KERNEL_PRIVATE | |
253 | ||
254 | extern boolean_t lck_spin_try_lock( | |
255 | lck_spin_t *lck); | |
256 | ||
257 | #endif | |
258 | ||
259 | ||
260 | #define decl_lck_mtx_data(class,name) class lck_mtx_t name; | |
261 | ||
262 | extern lck_mtx_t *lck_mtx_alloc_init( | |
263 | lck_grp_t *grp, | |
264 | lck_attr_t *attr); | |
265 | ||
266 | extern void lck_mtx_init( | |
267 | lck_mtx_t *lck, | |
268 | lck_grp_t *grp, | |
269 | lck_attr_t *attr); | |
270 | ||
271 | extern void lck_mtx_lock( | |
272 | lck_mtx_t *lck); | |
273 | ||
274 | extern void lck_mtx_unlock( | |
275 | lck_mtx_t *lck); | |
276 | ||
277 | extern void lck_mtx_destroy( | |
278 | lck_mtx_t *lck, | |
279 | lck_grp_t *grp); | |
280 | ||
281 | extern void lck_mtx_free( | |
282 | lck_mtx_t *lck, | |
283 | lck_grp_t *grp); | |
284 | ||
285 | extern wait_result_t lck_mtx_sleep( | |
286 | lck_mtx_t *lck, | |
287 | lck_sleep_action_t lck_sleep_action, | |
288 | event_t event, | |
289 | wait_interrupt_t interruptible); | |
290 | ||
291 | extern wait_result_t lck_mtx_sleep_deadline( | |
292 | lck_mtx_t *lck, | |
293 | lck_sleep_action_t lck_sleep_action, | |
294 | event_t event, | |
295 | wait_interrupt_t interruptible, | |
296 | uint64_t deadline); | |
297 | ||
298 | #ifdef KERNEL_PRIVATE | |
299 | ||
300 | extern boolean_t lck_mtx_try_lock( | |
301 | lck_mtx_t *lck); | |
302 | ||
303 | #endif /* KERNEL_PRIVATE */ | |
304 | ||
305 | extern void lck_mtx_assert( | |
306 | lck_mtx_t *lck, | |
307 | unsigned int type); | |
308 | ||
309 | __END_DECLS | |
310 | ||
311 | #define LCK_MTX_ASSERT_OWNED 0x01 | |
312 | #define LCK_MTX_ASSERT_NOTOWNED 0x02 | |
313 | ||
314 | #ifdef MACH_KERNEL_PRIVATE | |
315 | extern void lck_mtx_lock_wait( | |
316 | lck_mtx_t *lck, | |
317 | thread_t holder); | |
318 | ||
319 | extern int lck_mtx_lock_acquire( | |
320 | lck_mtx_t *lck); | |
321 | ||
322 | extern void lck_mtx_unlock_wakeup( | |
323 | lck_mtx_t *lck, | |
324 | thread_t holder); | |
325 | ||
326 | extern boolean_t lck_mtx_ilk_unlock( | |
327 | lck_mtx_t *lck); | |
328 | #endif | |
329 | ||
330 | #define decl_lck_rw_data(class,name) class lck_rw_t name; | |
331 | ||
332 | typedef unsigned int lck_rw_type_t; | |
333 | ||
334 | #define LCK_RW_TYPE_SHARED 0x01 | |
335 | #define LCK_RW_TYPE_EXCLUSIVE 0x02 | |
336 | ||
337 | __BEGIN_DECLS | |
338 | ||
339 | extern lck_rw_t *lck_rw_alloc_init( | |
340 | lck_grp_t *grp, | |
341 | lck_attr_t *attr); | |
342 | ||
343 | extern void lck_rw_init( | |
344 | lck_rw_t *lck, | |
345 | lck_grp_t *grp, | |
346 | lck_attr_t *attr); | |
347 | ||
348 | extern void lck_rw_lock( | |
349 | lck_rw_t *lck, | |
350 | lck_rw_type_t lck_rw_type); | |
351 | ||
352 | extern void lck_rw_unlock( | |
353 | lck_rw_t *lck, | |
354 | lck_rw_type_t lck_rw_type); | |
355 | ||
356 | extern void lck_rw_lock_shared( | |
357 | lck_rw_t *lck); | |
358 | ||
359 | extern void lck_rw_unlock_shared( | |
360 | lck_rw_t *lck); | |
361 | ||
362 | extern void lck_rw_lock_exclusive( | |
363 | lck_rw_t *lck); | |
364 | ||
365 | extern void lck_rw_unlock_exclusive( | |
366 | lck_rw_t *lck); | |
367 | ||
368 | #ifdef KERNEL_PRIVATE | |
369 | ||
370 | extern lck_rw_type_t lck_rw_done( | |
371 | lck_rw_t *lck); | |
372 | #endif | |
373 | ||
374 | extern void lck_rw_destroy( | |
375 | lck_rw_t *lck, | |
376 | lck_grp_t *grp); | |
377 | ||
378 | extern void lck_rw_free( | |
379 | lck_rw_t *lck, | |
380 | lck_grp_t *grp); | |
381 | ||
382 | extern wait_result_t lck_rw_sleep( | |
383 | lck_rw_t *lck, | |
384 | lck_sleep_action_t lck_sleep_action, | |
385 | event_t event, | |
386 | wait_interrupt_t interruptible); | |
387 | ||
388 | extern wait_result_t lck_rw_sleep_deadline( | |
389 | lck_rw_t *lck, | |
390 | lck_sleep_action_t lck_sleep_action, | |
391 | event_t event, | |
392 | wait_interrupt_t interruptible, | |
393 | uint64_t deadline); | |
394 | ||
395 | #ifdef KERNEL_PRIVATE | |
396 | ||
397 | extern boolean_t lck_rw_lock_shared_to_exclusive( | |
398 | lck_rw_t *lck); | |
399 | ||
400 | extern void lck_rw_lock_exclusive_to_shared( | |
401 | lck_rw_t *lck); | |
402 | ||
403 | extern boolean_t lck_rw_try_lock( | |
404 | lck_rw_t *lck, | |
405 | lck_rw_type_t lck_rw_type); | |
406 | ||
407 | extern boolean_t lck_rw_try_lock_shared( | |
408 | lck_rw_t *lck); | |
409 | ||
410 | extern boolean_t lck_rw_try_lock_exclusive( | |
411 | lck_rw_t *lck); | |
412 | #endif | |
413 | ||
414 | __END_DECLS | |
415 | ||
416 | #endif /* _KERN_LOCKS_H_ */ |