]> git.saurik.com Git - apple/xnu.git/blame - osfmk/kern/lock_group.h
xnu-4903.270.47.tar.gz
[apple/xnu.git] / osfmk / kern / lock_group.h
CommitLineData
0a7de745
A
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 *)0
35
36
37typedef unsigned int lck_type_t;
38
39#define LCK_TYPE_SPIN 1
40#define LCK_TYPE_MTX 2
41#define LCK_TYPE_RW 3
42
43#if XNU_KERNEL_PRIVATE
44
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
60typedef 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
72typedef 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
87typedef struct _lck_grp_ {
88 queue_chain_t lck_grp_link;
89 uint32_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
99typedef struct _lck_grp_ lck_grp_t;
100#endif /* XNU_KERNEL_PRIVATE */
101
102#ifdef MACH_KERNEL_PRIVATE
103typedef struct _lck_grp_attr_ {
104 uint32_t grp_attr_val;
105} lck_grp_attr_t;
106
107extern lck_grp_attr_t LockDefaultGroupAttr;
108
109#define LCK_GRP_ATTR_STAT 0x1
110#define LCK_GRP_ATTR_TIME_STAT 0x2
111
112#else
113typedef struct __lck_grp_attr__ lck_grp_attr_t;
114#endif /* MACH_KERNEL_PRIVATE */
115
116#define LCK_GRP_ATTR_NULL (lck_grp_attr_t *)0
117
118__BEGIN_DECLS
119
120extern lck_grp_attr_t *lck_grp_attr_alloc_init(
121 void);
122
123extern void lck_grp_attr_setdefault(
124 lck_grp_attr_t *attr);
125
126extern void lck_grp_attr_setstat(
127 lck_grp_attr_t *attr);
128
129extern void lck_grp_attr_free(
130 lck_grp_attr_t *attr);
131
132extern lck_grp_t *lck_grp_alloc_init(
133 const char* grp_name,
134 lck_grp_attr_t *attr);
135
136extern void lck_grp_free(
137 lck_grp_t *grp);
138
139__END_DECLS
140
141#ifdef MACH_KERNEL_PRIVATE
142extern void lck_grp_init(
143 lck_grp_t *grp,
144 const char* grp_name,
145 lck_grp_attr_t *attr);
146
147extern void lck_grp_reference(
148 lck_grp_t *grp);
149
150extern void lck_grp_deallocate(
151 lck_grp_t *grp);
152
153extern void lck_grp_lckcnt_incr(
154 lck_grp_t *grp,
155 lck_type_t lck_type);
156
157extern void lck_grp_lckcnt_decr(
158 lck_grp_t *grp,
159 lck_type_t lck_type);
160
161#endif /* MACH_KERNEL_PRIVATE */
162
163#endif /* _KERN_LOCK_GROUP_H */