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 *)NULL
36 typedef unsigned int lck_type_t
;
38 #define LCK_TYPE_SPIN 1
39 #define LCK_TYPE_MTX 2
42 #if XNU_KERNEL_PRIVATE
44 #include <os/refcnt.h>
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 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
;
99 typedef struct _lck_grp_ lck_grp_t
;
100 #endif /* XNU_KERNEL_PRIVATE */
103 #ifdef MACH_KERNEL_PRIVATE
104 typedef struct _lck_grp_attr_
{
105 uint32_t grp_attr_val
;
108 extern lck_grp_attr_t LockDefaultGroupAttr
;
110 #define LCK_GRP_ATTR_STAT 0x1
111 #define LCK_GRP_ATTR_TIME_STAT 0x2
114 typedef struct __lck_grp_attr__ lck_grp_attr_t
;
115 #endif /* MACH_KERNEL_PRIVATE */
117 #define LCK_GRP_ATTR_NULL (lck_grp_attr_t *)NULL
121 extern lck_grp_attr_t
*lck_grp_attr_alloc_init(
124 extern void lck_grp_attr_setdefault(
125 lck_grp_attr_t
*attr
);
127 extern void lck_grp_attr_setstat(
128 lck_grp_attr_t
*attr
);
130 extern void lck_grp_attr_free(
131 lck_grp_attr_t
*attr
);
133 extern lck_grp_t
*lck_grp_alloc_init(
134 const char* grp_name
,
135 lck_grp_attr_t
*attr
);
137 extern void lck_grp_free(
142 #ifdef MACH_KERNEL_PRIVATE
143 extern void lck_grp_init(
145 const char* grp_name
,
146 lck_grp_attr_t
*attr
);
148 extern void lck_grp_reference(
151 extern void lck_grp_deallocate(
154 extern void lck_grp_lckcnt_incr(
156 lck_type_t lck_type
);
158 extern void lck_grp_lckcnt_decr(
160 lck_type_t lck_type
);
161 #endif /* MACH_KERNEL_PRIVATE */
163 #endif /* _KERN_LOCK_GROUP_H */