]> git.saurik.com Git - apple/xnu.git/blame - osfmk/kern/locks.h
xnu-792.10.96.tar.gz
[apple/xnu.git] / osfmk / kern / locks.h
CommitLineData
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
36extern void lck_mod_init(
37 void);
38
39typedef 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
47typedef 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
59typedef 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
67typedef 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
78typedef 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
89typedef 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
97typedef 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
111typedef struct __lck_grp__ lck_grp_t;
112#endif
113
114#ifdef MACH_KERNEL_PRIVATE
115typedef struct _lck_grp_attr_ {
116 unsigned int grp_attr_val;
117} lck_grp_attr_t;
118
119extern lck_grp_attr_t LockDefaultGroupAttr;
120
121#define LCK_GRP_ATTR_STAT 0x1
122
123#else
124typedef 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
131extern lck_grp_attr_t *lck_grp_attr_alloc_init(
132 void);
133
134extern void lck_grp_attr_setdefault(
135 lck_grp_attr_t *attr);
136
137extern void lck_grp_attr_setstat(
138 lck_grp_attr_t *attr);
139
140extern void lck_grp_attr_free(
141 lck_grp_attr_t *attr);
142
143extern 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
150extern void lck_grp_init(
151 lck_grp_t *grp,
152 const char* grp_name,
153 lck_grp_attr_t *attr);
154
155extern void lck_grp_reference(
156 lck_grp_t *grp);
157
158extern void lck_grp_deallocate(
159 lck_grp_t *grp);
160
161extern void lck_grp_lckcnt_incr(
162 lck_grp_t *grp,
163 lck_type_t lck_type);
164
165extern void lck_grp_lckcnt_decr(
166 lck_grp_t *grp,
167 lck_type_t lck_type);
168#endif
169
170__BEGIN_DECLS
171
172extern void lck_grp_free(
173 lck_grp_t *grp);
174
175__END_DECLS
176
177#ifdef MACH_KERNEL_PRIVATE
178typedef struct _lck_attr_ {
179 unsigned int lck_attr_val;
180} lck_attr_t;
181
182extern 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
190typedef struct __lck_attr__ lck_attr_t;
191#endif
192
193#define LCK_ATTR_NULL (lck_attr_t *)0
194
195__BEGIN_DECLS
196
197extern lck_attr_t *lck_attr_alloc_init(
198 void);
199
200extern void lck_attr_setdefault(
201 lck_attr_t *attr);
202
203extern void lck_attr_setdebug(
204 lck_attr_t *attr);
205
c0fea474
A
206#ifdef XNU_KERNEL_PRIVATE
207extern void lck_attr_rw_shared_priority(
208 lck_attr_t *attr);
209#endif
210
91447636
A
211extern void lck_attr_free(
212 lck_attr_t *attr);
213
214#define decl_lck_spin_data(class,name) class lck_spin_t name;
215
216extern lck_spin_t *lck_spin_alloc_init(
217 lck_grp_t *grp,
218 lck_attr_t *attr);
219
220extern void lck_spin_init(
221 lck_spin_t *lck,
222 lck_grp_t *grp,
223 lck_attr_t *attr);
224
225extern void lck_spin_lock(
226 lck_spin_t *lck);
227
228extern void lck_spin_unlock(
229 lck_spin_t *lck);
230
231extern void lck_spin_destroy(
232 lck_spin_t *lck,
233 lck_grp_t *grp);
234
235extern void lck_spin_free(
236 lck_spin_t *lck,
237 lck_grp_t *grp);
238
239extern 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
245extern 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
254extern 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
262extern lck_mtx_t *lck_mtx_alloc_init(
263 lck_grp_t *grp,
264 lck_attr_t *attr);
265
266extern void lck_mtx_init(
267 lck_mtx_t *lck,
268 lck_grp_t *grp,
269 lck_attr_t *attr);
270
271extern void lck_mtx_lock(
272 lck_mtx_t *lck);
273
274extern void lck_mtx_unlock(
275 lck_mtx_t *lck);
276
277extern void lck_mtx_destroy(
278 lck_mtx_t *lck,
279 lck_grp_t *grp);
280
281extern void lck_mtx_free(
282 lck_mtx_t *lck,
283 lck_grp_t *grp);
284
285extern 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
291extern 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
300extern boolean_t lck_mtx_try_lock(
301 lck_mtx_t *lck);
302
303#endif /* KERNEL_PRIVATE */
304
305extern 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
315extern void lck_mtx_lock_wait(
316 lck_mtx_t *lck,
317 thread_t holder);
318
319extern int lck_mtx_lock_acquire(
320 lck_mtx_t *lck);
321
322extern void lck_mtx_unlock_wakeup(
323 lck_mtx_t *lck,
324 thread_t holder);
325
326extern 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
332typedef 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
339extern lck_rw_t *lck_rw_alloc_init(
340 lck_grp_t *grp,
341 lck_attr_t *attr);
342
343extern void lck_rw_init(
344 lck_rw_t *lck,
345 lck_grp_t *grp,
346 lck_attr_t *attr);
347
348extern void lck_rw_lock(
349 lck_rw_t *lck,
350 lck_rw_type_t lck_rw_type);
351
352extern void lck_rw_unlock(
353 lck_rw_t *lck,
354 lck_rw_type_t lck_rw_type);
355
356extern void lck_rw_lock_shared(
357 lck_rw_t *lck);
358
359extern void lck_rw_unlock_shared(
360 lck_rw_t *lck);
361
362extern void lck_rw_lock_exclusive(
363 lck_rw_t *lck);
364
365extern void lck_rw_unlock_exclusive(
366 lck_rw_t *lck);
367
368#ifdef KERNEL_PRIVATE
369
370extern lck_rw_type_t lck_rw_done(
371 lck_rw_t *lck);
372#endif
373
374extern void lck_rw_destroy(
375 lck_rw_t *lck,
376 lck_grp_t *grp);
377
378extern void lck_rw_free(
379 lck_rw_t *lck,
380 lck_grp_t *grp);
381
382extern 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
388extern 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
397extern boolean_t lck_rw_lock_shared_to_exclusive(
398 lck_rw_t *lck);
399
400extern void lck_rw_lock_exclusive_to_shared(
401 lck_rw_t *lck);
402
403extern boolean_t lck_rw_try_lock(
404 lck_rw_t *lck,
405 lck_rw_type_t lck_rw_type);
406
407extern boolean_t lck_rw_try_lock_shared(
408 lck_rw_t *lck);
409
410extern boolean_t lck_rw_try_lock_exclusive(
411 lck_rw_t *lck);
412#endif
413
414__END_DECLS
415
416#endif /* _KERN_LOCKS_H_ */