]> git.saurik.com Git - apple/xnu.git/blob - osfmk/i386/locks.h
xnu-792.18.15.tar.gz
[apple/xnu.git] / osfmk / i386 / locks.h
1 /*
2 * Copyright (c) 2004 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
29 #ifndef _I386_LOCKS_H_
30 #define _I386_LOCKS_H_
31
32 #include <sys/appleapiopts.h>
33 #include <kern/kern_types.h>
34
35 #ifdef MACH_KERNEL_PRIVATE
36
37 #include <i386/hw_lock_types.h>
38
39 extern unsigned int LcksOpts;
40
41 #define enaLkDeb 0x00000001 /* Request debug in default attribute */
42 #define enaLkStat 0x00000002 /* Request statistic in default attribute */
43
44 #endif
45
46 #ifdef MACH_KERNEL_PRIVATE
47 typedef struct {
48 unsigned int lck_spin_data[10]; /* XXX - usimple_lock_data_t */
49 } lck_spin_t;
50
51 #define LCK_SPIN_TAG_DESTROYED 0x00002007 /* lock marked as Destroyed */
52
53 #else
54 #ifdef KERNEL_PRIVATE
55 typedef struct {
56 unsigned int opaque[10];
57 } lck_spin_t;
58 #else
59 typedef struct __lck_spin_t__ lck_spin_t;
60 #endif
61 #endif
62
63 #ifdef MACH_KERNEL_PRIVATE
64 typedef struct _lck_mtx_ {
65 union {
66 struct {
67 unsigned int lck_mtxd_ilk;
68 unsigned int lck_mtxd_locked;
69 unsigned short lck_mtxd_waiters;
70 unsigned short lck_mtxd_pri;
71 } lck_mtxd;
72 struct {
73 unsigned int lck_mtxi_tag;
74 struct _lck_mtx_ext_ *lck_mtxi_ptr;
75 unsigned int lck_mtxi_pad8;
76 } lck_mtxi;
77 } lck_mtx_sw;
78 } lck_mtx_t;
79
80 #define lck_mtx_ilk lck_mtx_sw.lck_mtxd.lck_mtxd_ilk
81 #define lck_mtx_locked lck_mtx_sw.lck_mtxd.lck_mtxd_locked
82 #define lck_mtx_waiters lck_mtx_sw.lck_mtxd.lck_mtxd_waiters
83 #define lck_mtx_pri lck_mtx_sw.lck_mtxd.lck_mtxd_pri
84
85 #define lck_mtx_tag lck_mtx_sw.lck_mtxi.lck_mtxi_tag
86 #define lck_mtx_ptr lck_mtx_sw.lck_mtxi.lck_mtxi_ptr
87
88 #define LCK_MTX_TAG_INDIRECT 0x00001007 /* lock marked as Indirect */
89 #define LCK_MTX_TAG_DESTROYED 0x00002007 /* lock marked as Destroyed */
90
91 /* Adaptive spin before blocking */
92 extern unsigned int MutexSpin;
93 extern void lck_mtx_lock_spin(lck_mtx_t *lck);
94
95 extern void lck_mtx_interlock_spin(lck_mtx_t *lck);
96
97 typedef struct {
98 unsigned int type;
99 vm_offset_t pc;
100 vm_offset_t thread;
101 } lck_mtx_deb_t;
102
103 #define MUTEX_TAG 0x4d4d
104
105 typedef struct {
106 unsigned int lck_mtx_stat_data;
107 } lck_mtx_stat_t;
108
109 typedef struct _lck_mtx_ext_ {
110 lck_mtx_t lck_mtx;
111 struct _lck_grp_ *lck_mtx_grp;
112 unsigned int lck_mtx_attr;
113 lck_mtx_deb_t lck_mtx_deb;
114 lck_mtx_stat_t lck_mtx_stat;
115 } lck_mtx_ext_t;
116
117 #define LCK_MTX_ATTR_DEBUG 0x1
118 #define LCK_MTX_ATTR_DEBUGb 0
119 #define LCK_MTX_ATTR_STAT 0x2
120 #define LCK_MTX_ATTR_STATb 1
121
122 #else
123 #ifdef KERNEL_PRIVATE
124 typedef struct {
125 unsigned int opaque[3];
126 } lck_mtx_t;
127 #else
128 typedef struct __lck_mtx_t__ lck_mtx_t;
129 #endif
130 #endif
131
132 #ifdef MACH_KERNEL_PRIVATE
133 typedef struct {
134 hw_lock_data_t interlock;
135 volatile unsigned int
136 read_count:16, /* No. of accepted readers */
137 want_upgrade:1, /* Read-to-write upgrade waiting */
138 want_write:1, /* Writer waiting or locked for write */
139 waiting:1, /* Someone is sleeping on lock */
140 can_sleep:1, /* Can attempts to lock go to sleep? */
141 read_priority:1;/* New read takes piority over write */
142 unsigned int lck_rw_tag;
143 } lck_rw_t;
144
145 #define LCK_RW_ATTR_DEBUG 0x1
146 #define LCK_RW_ATTR_DEBUGb 0
147 #define LCK_RW_ATTR_STAT 0x2
148 #define LCK_RW_ATTR_STATb 1
149 #define LCK_RW_ATTR_READ_PRI 0x3
150 #define LCK_RW_ATTR_READ_PRIb 2
151 #define LCK_RW_ATTR_DIS_THREAD 0x40000000
152 #define LCK_RW_ATTR_DIS_THREADb 30
153 #define LCK_RW_ATTR_DIS_MYLOCK 0x10000000
154 #define LCK_RW_ATTR_DIS_MYLOCKb 28
155
156 #define LCK_RW_TAG_DESTROYED 0x00002007 /* lock marked as Destroyed */
157
158 #else
159 #ifdef KERNEL_PRIVATE
160 typedef struct {
161 unsigned int opaque[3];
162 } lck_rw_t;
163 #else
164 typedef struct __lck_rw_t__ lck_rw_t;
165 #endif
166 #endif
167
168 #endif /* _I386_LOCKS_H_ */