]>
Commit | Line | Data |
---|---|---|
1 | /* | |
2 | * Copyright (c) 2003-2005 Apple Computer, Inc. All rights reserved. | |
3 | * | |
4 | * @APPLE_LICENSE_HEADER_START@ | |
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 | |
14 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, | |
15 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
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 | * | |
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 | ||
184 | #define LCK_ATTR_NONE 0 | |
185 | #define LCK_ATTR_DEBUG 0x1 | |
186 | ||
187 | #else | |
188 | typedef struct __lck_attr__ lck_attr_t; | |
189 | #endif | |
190 | ||
191 | #define LCK_ATTR_NULL (lck_attr_t *)0 | |
192 | ||
193 | __BEGIN_DECLS | |
194 | ||
195 | extern lck_attr_t *lck_attr_alloc_init( | |
196 | void); | |
197 | ||
198 | extern void lck_attr_setdefault( | |
199 | lck_attr_t *attr); | |
200 | ||
201 | extern void lck_attr_setdebug( | |
202 | lck_attr_t *attr); | |
203 | ||
204 | extern void lck_attr_free( | |
205 | lck_attr_t *attr); | |
206 | ||
207 | #define decl_lck_spin_data(class,name) class lck_spin_t name; | |
208 | ||
209 | extern lck_spin_t *lck_spin_alloc_init( | |
210 | lck_grp_t *grp, | |
211 | lck_attr_t *attr); | |
212 | ||
213 | extern void lck_spin_init( | |
214 | lck_spin_t *lck, | |
215 | lck_grp_t *grp, | |
216 | lck_attr_t *attr); | |
217 | ||
218 | extern void lck_spin_lock( | |
219 | lck_spin_t *lck); | |
220 | ||
221 | extern void lck_spin_unlock( | |
222 | lck_spin_t *lck); | |
223 | ||
224 | extern void lck_spin_destroy( | |
225 | lck_spin_t *lck, | |
226 | lck_grp_t *grp); | |
227 | ||
228 | extern void lck_spin_free( | |
229 | lck_spin_t *lck, | |
230 | lck_grp_t *grp); | |
231 | ||
232 | extern wait_result_t lck_spin_sleep( | |
233 | lck_spin_t *lck, | |
234 | lck_sleep_action_t lck_sleep_action, | |
235 | event_t event, | |
236 | wait_interrupt_t interruptible); | |
237 | ||
238 | extern wait_result_t lck_spin_sleep_deadline( | |
239 | lck_spin_t *lck, | |
240 | lck_sleep_action_t lck_sleep_action, | |
241 | event_t event, | |
242 | wait_interrupt_t interruptible, | |
243 | uint64_t deadline); | |
244 | ||
245 | #ifdef KERNEL_PRIVATE | |
246 | ||
247 | extern boolean_t lck_spin_try_lock( | |
248 | lck_spin_t *lck); | |
249 | ||
250 | #endif | |
251 | ||
252 | ||
253 | #define decl_lck_mtx_data(class,name) class lck_mtx_t name; | |
254 | ||
255 | extern lck_mtx_t *lck_mtx_alloc_init( | |
256 | lck_grp_t *grp, | |
257 | lck_attr_t *attr); | |
258 | ||
259 | extern void lck_mtx_init( | |
260 | lck_mtx_t *lck, | |
261 | lck_grp_t *grp, | |
262 | lck_attr_t *attr); | |
263 | ||
264 | extern void lck_mtx_lock( | |
265 | lck_mtx_t *lck); | |
266 | ||
267 | extern void lck_mtx_unlock( | |
268 | lck_mtx_t *lck); | |
269 | ||
270 | extern void lck_mtx_destroy( | |
271 | lck_mtx_t *lck, | |
272 | lck_grp_t *grp); | |
273 | ||
274 | extern void lck_mtx_free( | |
275 | lck_mtx_t *lck, | |
276 | lck_grp_t *grp); | |
277 | ||
278 | extern wait_result_t lck_mtx_sleep( | |
279 | lck_mtx_t *lck, | |
280 | lck_sleep_action_t lck_sleep_action, | |
281 | event_t event, | |
282 | wait_interrupt_t interruptible); | |
283 | ||
284 | extern wait_result_t lck_mtx_sleep_deadline( | |
285 | lck_mtx_t *lck, | |
286 | lck_sleep_action_t lck_sleep_action, | |
287 | event_t event, | |
288 | wait_interrupt_t interruptible, | |
289 | uint64_t deadline); | |
290 | ||
291 | #ifdef KERNEL_PRIVATE | |
292 | ||
293 | extern boolean_t lck_mtx_try_lock( | |
294 | lck_mtx_t *lck); | |
295 | ||
296 | #endif /* KERNEL_PRIVATE */ | |
297 | ||
298 | extern void lck_mtx_assert( | |
299 | lck_mtx_t *lck, | |
300 | unsigned int type); | |
301 | ||
302 | __END_DECLS | |
303 | ||
304 | #define LCK_MTX_ASSERT_OWNED 0x01 | |
305 | #define LCK_MTX_ASSERT_NOTOWNED 0x02 | |
306 | ||
307 | #ifdef MACH_KERNEL_PRIVATE | |
308 | extern void lck_mtx_lock_wait( | |
309 | lck_mtx_t *lck, | |
310 | thread_t holder); | |
311 | ||
312 | extern int lck_mtx_lock_acquire( | |
313 | lck_mtx_t *lck); | |
314 | ||
315 | extern void lck_mtx_unlock_wakeup( | |
316 | lck_mtx_t *lck, | |
317 | thread_t holder); | |
318 | ||
319 | extern boolean_t lck_mtx_ilk_unlock( | |
320 | lck_mtx_t *lck); | |
321 | #endif | |
322 | ||
323 | #define decl_lck_rw_data(class,name) class lck_rw_t name; | |
324 | ||
325 | typedef unsigned int lck_rw_type_t; | |
326 | ||
327 | #define LCK_RW_TYPE_SHARED 0x01 | |
328 | #define LCK_RW_TYPE_EXCLUSIVE 0x02 | |
329 | ||
330 | __BEGIN_DECLS | |
331 | ||
332 | extern lck_rw_t *lck_rw_alloc_init( | |
333 | lck_grp_t *grp, | |
334 | lck_attr_t *attr); | |
335 | ||
336 | extern void lck_rw_init( | |
337 | lck_rw_t *lck, | |
338 | lck_grp_t *grp, | |
339 | lck_attr_t *attr); | |
340 | ||
341 | extern void lck_rw_lock( | |
342 | lck_rw_t *lck, | |
343 | lck_rw_type_t lck_rw_type); | |
344 | ||
345 | extern void lck_rw_unlock( | |
346 | lck_rw_t *lck, | |
347 | lck_rw_type_t lck_rw_type); | |
348 | ||
349 | extern void lck_rw_lock_shared( | |
350 | lck_rw_t *lck); | |
351 | ||
352 | extern void lck_rw_unlock_shared( | |
353 | lck_rw_t *lck); | |
354 | ||
355 | extern void lck_rw_lock_exclusive( | |
356 | lck_rw_t *lck); | |
357 | ||
358 | extern void lck_rw_unlock_exclusive( | |
359 | lck_rw_t *lck); | |
360 | ||
361 | #ifdef KERNEL_PRIVATE | |
362 | ||
363 | extern lck_rw_type_t lck_rw_done( | |
364 | lck_rw_t *lck); | |
365 | #endif | |
366 | ||
367 | extern void lck_rw_destroy( | |
368 | lck_rw_t *lck, | |
369 | lck_grp_t *grp); | |
370 | ||
371 | extern void lck_rw_free( | |
372 | lck_rw_t *lck, | |
373 | lck_grp_t *grp); | |
374 | ||
375 | extern wait_result_t lck_rw_sleep( | |
376 | lck_rw_t *lck, | |
377 | lck_sleep_action_t lck_sleep_action, | |
378 | event_t event, | |
379 | wait_interrupt_t interruptible); | |
380 | ||
381 | extern wait_result_t lck_rw_sleep_deadline( | |
382 | lck_rw_t *lck, | |
383 | lck_sleep_action_t lck_sleep_action, | |
384 | event_t event, | |
385 | wait_interrupt_t interruptible, | |
386 | uint64_t deadline); | |
387 | ||
388 | #ifdef KERNEL_PRIVATE | |
389 | ||
390 | extern boolean_t lck_rw_lock_shared_to_exclusive( | |
391 | lck_rw_t *lck); | |
392 | ||
393 | extern void lck_rw_lock_exclusive_to_shared( | |
394 | lck_rw_t *lck); | |
395 | ||
396 | extern boolean_t lck_rw_try_lock( | |
397 | lck_rw_t *lck, | |
398 | lck_rw_type_t lck_rw_type); | |
399 | ||
400 | extern boolean_t lck_rw_try_lock_shared( | |
401 | lck_rw_t *lck); | |
402 | ||
403 | extern boolean_t lck_rw_try_lock_exclusive( | |
404 | lck_rw_t *lck); | |
405 | #endif | |
406 | ||
407 | __END_DECLS | |
408 | ||
409 | #endif /* _KERN_LOCKS_H_ */ |