]> git.saurik.com Git - apple/xnu.git/blob - osfmk/kern/lock_group.h
xnu-6153.81.5.tar.gz
[apple/xnu.git] / osfmk / kern / lock_group.h
1 /*
2 * Copyright (c) 2018 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 #ifndef _KERN_LOCK_GROUP_H
29 #define _KERN_LOCK_GROUP_H
30
31 #include <kern/queue.h>
32 #include <mach/mach_types.h>
33
34 #define LCK_GRP_NULL (lck_grp_t *)NULL
35
36 typedef unsigned int lck_type_t;
37
38 #define LCK_TYPE_SPIN 1
39 #define LCK_TYPE_MTX 2
40 #define LCK_TYPE_RW 3
41
42 #if XNU_KERNEL_PRIVATE
43
44 #include <os/refcnt.h>
45 /*
46 * Arguments wrapped in LCK_GRP_ARG() will be elided
47 * when LOCK_STATS is not set.
48 *
49 * Arguments wrapped with LCK_GRP_PROBEARG() will be
50 * NULL when LOCK_STATS is not set
51 */
52 #if LOCK_STATS
53 #define LCK_GRP_ARG(expr) ,expr
54 #define LCK_GRP_PROBEARG(grp) grp
55 #else
56 #define LCK_GRP_ARG(expr)
57 #define LCK_GRP_PROBEARG(grp) LCK_GRP_NULL
58 #endif /* LOCK_STATS */
59
60 typedef struct _lck_grp_stat_ {
61 uint64_t lgs_count;
62 uint32_t lgs_enablings;
63 #if CONFIG_DTRACE
64 /*
65 * Protected by dtrace_lock
66 */
67 uint32_t lgs_probeid;
68 uint64_t lgs_limit;
69 #endif /* CONFIG_DTRACE */
70 } lck_grp_stat_t;
71
72 typedef struct _lck_grp_stats_ {
73 #if LOCK_STATS
74 lck_grp_stat_t lgss_spin_held;
75 lck_grp_stat_t lgss_spin_miss;
76 lck_grp_stat_t lgss_spin_spin;
77 #endif /* LOCK_STATS */
78
79 lck_grp_stat_t lgss_mtx_held;
80 lck_grp_stat_t lgss_mtx_direct_wait;
81 lck_grp_stat_t lgss_mtx_miss;
82 lck_grp_stat_t lgss_mtx_wait;
83 } lck_grp_stats_t;
84
85 #define LCK_GRP_MAX_NAME 64
86
87 typedef struct _lck_grp_ {
88 queue_chain_t lck_grp_link;
89 os_refcnt_t lck_grp_refcnt;
90 uint32_t lck_grp_spincnt;
91 uint32_t lck_grp_mtxcnt;
92 uint32_t lck_grp_rwcnt;
93 uint32_t lck_grp_attr;
94 char lck_grp_name[LCK_GRP_MAX_NAME];
95 lck_grp_stats_t lck_grp_stats;
96 } lck_grp_t;
97
98 #else
99 typedef struct _lck_grp_ lck_grp_t;
100 #endif /* XNU_KERNEL_PRIVATE */
101
102
103 #ifdef MACH_KERNEL_PRIVATE
104 typedef struct _lck_grp_attr_ {
105 uint32_t grp_attr_val;
106 } lck_grp_attr_t;
107
108 extern lck_grp_attr_t LockDefaultGroupAttr;
109
110 #define LCK_GRP_ATTR_STAT 0x1
111 #define LCK_GRP_ATTR_TIME_STAT 0x2
112
113 #else
114 typedef struct __lck_grp_attr__ lck_grp_attr_t;
115 #endif /* MACH_KERNEL_PRIVATE */
116
117 #define LCK_GRP_ATTR_NULL (lck_grp_attr_t *)NULL
118
119 __BEGIN_DECLS
120
121 extern lck_grp_attr_t *lck_grp_attr_alloc_init(
122 void);
123
124 extern void lck_grp_attr_setdefault(
125 lck_grp_attr_t *attr);
126
127 extern void lck_grp_attr_setstat(
128 lck_grp_attr_t *attr);
129
130 extern void lck_grp_attr_free(
131 lck_grp_attr_t *attr);
132
133 extern lck_grp_t *lck_grp_alloc_init(
134 const char* grp_name,
135 lck_grp_attr_t *attr);
136
137 extern void lck_grp_free(
138 lck_grp_t *grp);
139
140 __END_DECLS
141
142 #ifdef MACH_KERNEL_PRIVATE
143 extern void lck_grp_init(
144 lck_grp_t *grp,
145 const char* grp_name,
146 lck_grp_attr_t *attr);
147
148 extern void lck_grp_reference(
149 lck_grp_t *grp);
150
151 extern void lck_grp_deallocate(
152 lck_grp_t *grp);
153
154 extern void lck_grp_lckcnt_incr(
155 lck_grp_t *grp,
156 lck_type_t lck_type);
157
158 extern void lck_grp_lckcnt_decr(
159 lck_grp_t *grp,
160 lck_type_t lck_type);
161 #endif /* MACH_KERNEL_PRIVATE */
162
163 #endif /* _KERN_LOCK_GROUP_H */