]> git.saurik.com Git - apple/xnu.git/blame - osfmk/kern/locks.h
xnu-792.6.76.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
184#define LCK_ATTR_NONE 0
185#define LCK_ATTR_DEBUG 0x1
186
187#else
188typedef struct __lck_attr__ lck_attr_t;
189#endif
190
191#define LCK_ATTR_NULL (lck_attr_t *)0
192
193__BEGIN_DECLS
194
195extern lck_attr_t *lck_attr_alloc_init(
196 void);
197
198extern void lck_attr_setdefault(
199 lck_attr_t *attr);
200
201extern void lck_attr_setdebug(
202 lck_attr_t *attr);
203
204extern void lck_attr_free(
205 lck_attr_t *attr);
206
207#define decl_lck_spin_data(class,name) class lck_spin_t name;
208
209extern lck_spin_t *lck_spin_alloc_init(
210 lck_grp_t *grp,
211 lck_attr_t *attr);
212
213extern void lck_spin_init(
214 lck_spin_t *lck,
215 lck_grp_t *grp,
216 lck_attr_t *attr);
217
218extern void lck_spin_lock(
219 lck_spin_t *lck);
220
221extern void lck_spin_unlock(
222 lck_spin_t *lck);
223
224extern void lck_spin_destroy(
225 lck_spin_t *lck,
226 lck_grp_t *grp);
227
228extern void lck_spin_free(
229 lck_spin_t *lck,
230 lck_grp_t *grp);
231
232extern 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
238extern 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
247extern 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
255extern lck_mtx_t *lck_mtx_alloc_init(
256 lck_grp_t *grp,
257 lck_attr_t *attr);
258
259extern void lck_mtx_init(
260 lck_mtx_t *lck,
261 lck_grp_t *grp,
262 lck_attr_t *attr);
263
264extern void lck_mtx_lock(
265 lck_mtx_t *lck);
266
267extern void lck_mtx_unlock(
268 lck_mtx_t *lck);
269
270extern void lck_mtx_destroy(
271 lck_mtx_t *lck,
272 lck_grp_t *grp);
273
274extern void lck_mtx_free(
275 lck_mtx_t *lck,
276 lck_grp_t *grp);
277
278extern 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
284extern 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
293extern boolean_t lck_mtx_try_lock(
294 lck_mtx_t *lck);
295
296#endif /* KERNEL_PRIVATE */
297
298extern 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
308extern void lck_mtx_lock_wait(
309 lck_mtx_t *lck,
310 thread_t holder);
311
312extern int lck_mtx_lock_acquire(
313 lck_mtx_t *lck);
314
315extern void lck_mtx_unlock_wakeup(
316 lck_mtx_t *lck,
317 thread_t holder);
318
319extern 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
325typedef 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
332extern lck_rw_t *lck_rw_alloc_init(
333 lck_grp_t *grp,
334 lck_attr_t *attr);
335
336extern void lck_rw_init(
337 lck_rw_t *lck,
338 lck_grp_t *grp,
339 lck_attr_t *attr);
340
341extern void lck_rw_lock(
342 lck_rw_t *lck,
343 lck_rw_type_t lck_rw_type);
344
345extern void lck_rw_unlock(
346 lck_rw_t *lck,
347 lck_rw_type_t lck_rw_type);
348
349extern void lck_rw_lock_shared(
350 lck_rw_t *lck);
351
352extern void lck_rw_unlock_shared(
353 lck_rw_t *lck);
354
355extern void lck_rw_lock_exclusive(
356 lck_rw_t *lck);
357
358extern void lck_rw_unlock_exclusive(
359 lck_rw_t *lck);
360
361#ifdef KERNEL_PRIVATE
362
363extern lck_rw_type_t lck_rw_done(
364 lck_rw_t *lck);
365#endif
366
367extern void lck_rw_destroy(
368 lck_rw_t *lck,
369 lck_grp_t *grp);
370
371extern void lck_rw_free(
372 lck_rw_t *lck,
373 lck_grp_t *grp);
374
375extern 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
381extern 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
390extern boolean_t lck_rw_lock_shared_to_exclusive(
391 lck_rw_t *lck);
392
393extern void lck_rw_lock_exclusive_to_shared(
394 lck_rw_t *lck);
395
396extern boolean_t lck_rw_try_lock(
397 lck_rw_t *lck,
398 lck_rw_type_t lck_rw_type);
399
400extern boolean_t lck_rw_try_lock_shared(
401 lck_rw_t *lck);
402
403extern boolean_t lck_rw_try_lock_exclusive(
404 lck_rw_t *lck);
405#endif
406
407__END_DECLS
408
409#endif /* _KERN_LOCKS_H_ */