2 * Copyright (c) 2018 Apple Computer, Inc. All rights reserved.
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
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.
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
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.
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
28 #ifndef _KERN_LOCK_GROUP_H
29 #define _KERN_LOCK_GROUP_H
31 #include <kern/queue.h>
32 #include <mach/mach_types.h>
34 #define LCK_GRP_NULL (lck_grp_t *)0
37 typedef unsigned int lck_type_t
;
39 #define LCK_TYPE_SPIN 1
40 #define LCK_TYPE_MTX 2
43 #if XNU_KERNEL_PRIVATE
46 * Arguments wrapped in LCK_GRP_ARG() will be elided
47 * when LOCK_STATS is not set.
49 * Arguments wrapped with LCK_GRP_PROBEARG() will be
50 * NULL when LOCK_STATS is not set
53 #define LCK_GRP_ARG(expr) ,expr
54 #define LCK_GRP_PROBEARG(grp) grp
56 #define LCK_GRP_ARG(expr)
57 #define LCK_GRP_PROBEARG(grp) LCK_GRP_NULL
58 #endif /* LOCK_STATS */
60 typedef struct _lck_grp_stat_
{
62 uint32_t lgs_enablings
;
65 * Protected by dtrace_lock
69 #endif /* CONFIG_DTRACE */
72 typedef struct _lck_grp_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 */
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
;
85 #define LCK_GRP_MAX_NAME 64
87 typedef 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
;
99 typedef struct _lck_grp_ lck_grp_t
;
100 #endif /* XNU_KERNEL_PRIVATE */
102 #ifdef MACH_KERNEL_PRIVATE
103 typedef struct _lck_grp_attr_
{
104 uint32_t grp_attr_val
;
107 extern lck_grp_attr_t LockDefaultGroupAttr
;
109 #define LCK_GRP_ATTR_STAT 0x1
110 #define LCK_GRP_ATTR_TIME_STAT 0x2
113 typedef struct __lck_grp_attr__ lck_grp_attr_t
;
114 #endif /* MACH_KERNEL_PRIVATE */
116 #define LCK_GRP_ATTR_NULL (lck_grp_attr_t *)0
120 extern lck_grp_attr_t
*lck_grp_attr_alloc_init(
123 extern void lck_grp_attr_setdefault(
124 lck_grp_attr_t
*attr
);
126 extern void lck_grp_attr_setstat(
127 lck_grp_attr_t
*attr
);
129 extern void lck_grp_attr_free(
130 lck_grp_attr_t
*attr
);
132 extern lck_grp_t
*lck_grp_alloc_init(
133 const char* grp_name
,
134 lck_grp_attr_t
*attr
);
136 extern void lck_grp_free(
141 #ifdef MACH_KERNEL_PRIVATE
142 extern void lck_grp_init(
144 const char* grp_name
,
145 lck_grp_attr_t
*attr
);
147 extern void lck_grp_reference(
150 extern void lck_grp_deallocate(
153 extern void lck_grp_lckcnt_incr(
155 lck_type_t lck_type
);
157 extern void lck_grp_lckcnt_decr(
159 lck_type_t lck_type
);
161 #endif /* MACH_KERNEL_PRIVATE */
163 #endif /* _KERN_LOCK_GROUP_H */