]> git.saurik.com Git - apple/xnu.git/blob - osfmk/i386/locks.h
xnu-792.13.8.tar.gz
[apple/xnu.git] / osfmk / i386 / locks.h
1 /*
2 * Copyright (c) 2004 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_OSREFERENCE_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
10 * License may not be used to create, or enable the creation or
11 * redistribution of, unlawful or unlicensed copies of an Apple operating
12 * system, or to circumvent, violate, or enable the circumvention or
13 * violation of, any terms of an Apple operating system software license
14 * agreement.
15 *
16 * Please obtain a copy of the License at
17 * http://www.opensource.apple.com/apsl/ and read it before using this
18 * file.
19 *
20 * The Original Code and all software distributed under the License are
21 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
22 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
23 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
24 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
25 * Please see the License for the specific language governing rights and
26 * limitations under the License.
27 *
28 * @APPLE_LICENSE_OSREFERENCE_HEADER_END@
29 */
30
31 #ifndef _I386_LOCKS_H_
32 #define _I386_LOCKS_H_
33
34 #include <sys/appleapiopts.h>
35 #include <kern/kern_types.h>
36
37 #ifdef MACH_KERNEL_PRIVATE
38
39 #include <i386/hw_lock_types.h>
40
41 extern unsigned int LcksOpts;
42
43 #define enaLkDeb 0x00000001 /* Request debug in default attribute */
44 #define enaLkStat 0x00000002 /* Request statistic in default attribute */
45
46 #endif
47
48 #ifdef MACH_KERNEL_PRIVATE
49 typedef struct {
50 unsigned int lck_spin_data[10]; /* XXX - usimple_lock_data_t */
51 } lck_spin_t;
52
53 #define LCK_SPIN_TAG_DESTROYED 0x00002007 /* lock marked as Destroyed */
54
55 #else
56 #ifdef KERNEL_PRIVATE
57 typedef struct {
58 unsigned int opaque[10];
59 } lck_spin_t;
60 #else
61 typedef struct __lck_spin_t__ lck_spin_t;
62 #endif
63 #endif
64
65 #ifdef MACH_KERNEL_PRIVATE
66 typedef struct _lck_mtx_ {
67 union {
68 struct {
69 unsigned int lck_mtxd_ilk;
70 unsigned int lck_mtxd_locked;
71 unsigned short lck_mtxd_waiters;
72 unsigned short lck_mtxd_pri;
73 } lck_mtxd;
74 struct {
75 unsigned int lck_mtxi_tag;
76 struct _lck_mtx_ext_ *lck_mtxi_ptr;
77 unsigned int lck_mtxi_pad8;
78 } lck_mtxi;
79 } lck_mtx_sw;
80 } lck_mtx_t;
81
82 #define lck_mtx_ilk lck_mtx_sw.lck_mtxd.lck_mtxd_ilk
83 #define lck_mtx_locked lck_mtx_sw.lck_mtxd.lck_mtxd_locked
84 #define lck_mtx_waiters lck_mtx_sw.lck_mtxd.lck_mtxd_waiters
85 #define lck_mtx_pri lck_mtx_sw.lck_mtxd.lck_mtxd_pri
86
87 #define lck_mtx_tag lck_mtx_sw.lck_mtxi.lck_mtxi_tag
88 #define lck_mtx_ptr lck_mtx_sw.lck_mtxi.lck_mtxi_ptr
89
90 #define LCK_MTX_TAG_INDIRECT 0x00001007 /* lock marked as Indirect */
91 #define LCK_MTX_TAG_DESTROYED 0x00002007 /* lock marked as Destroyed */
92
93 /* Adaptive spin before blocking */
94 extern unsigned int MutexSpin;
95 extern void lck_mtx_lock_spin(lck_mtx_t *lck);
96
97 extern void lck_mtx_interlock_spin(lck_mtx_t *lck);
98
99 typedef struct {
100 unsigned int type;
101 vm_offset_t pc;
102 vm_offset_t thread;
103 } lck_mtx_deb_t;
104
105 #define MUTEX_TAG 0x4d4d
106
107 typedef struct {
108 unsigned int lck_mtx_stat_data;
109 } lck_mtx_stat_t;
110
111 typedef struct _lck_mtx_ext_ {
112 lck_mtx_t lck_mtx;
113 struct _lck_grp_ *lck_mtx_grp;
114 unsigned int lck_mtx_attr;
115 lck_mtx_deb_t lck_mtx_deb;
116 lck_mtx_stat_t lck_mtx_stat;
117 } lck_mtx_ext_t;
118
119 #define LCK_MTX_ATTR_DEBUG 0x1
120 #define LCK_MTX_ATTR_DEBUGb 0
121 #define LCK_MTX_ATTR_STAT 0x2
122 #define LCK_MTX_ATTR_STATb 1
123
124 #else
125 #ifdef KERNEL_PRIVATE
126 typedef struct {
127 unsigned int opaque[3];
128 } lck_mtx_t;
129 #else
130 typedef struct __lck_mtx_t__ lck_mtx_t;
131 #endif
132 #endif
133
134 #ifdef MACH_KERNEL_PRIVATE
135 typedef struct {
136 hw_lock_data_t interlock;
137 volatile unsigned int
138 read_count:16, /* No. of accepted readers */
139 want_upgrade:1, /* Read-to-write upgrade waiting */
140 want_write:1, /* Writer waiting or locked for write */
141 waiting:1, /* Someone is sleeping on lock */
142 can_sleep:1, /* Can attempts to lock go to sleep? */
143 read_priority:1;/* New read takes piority over write */
144 unsigned int lck_rw_tag;
145 } lck_rw_t;
146
147 #define LCK_RW_ATTR_DEBUG 0x1
148 #define LCK_RW_ATTR_DEBUGb 0
149 #define LCK_RW_ATTR_STAT 0x2
150 #define LCK_RW_ATTR_STATb 1
151 #define LCK_RW_ATTR_READ_PRI 0x3
152 #define LCK_RW_ATTR_READ_PRIb 2
153 #define LCK_RW_ATTR_DIS_THREAD 0x40000000
154 #define LCK_RW_ATTR_DIS_THREADb 30
155 #define LCK_RW_ATTR_DIS_MYLOCK 0x10000000
156 #define LCK_RW_ATTR_DIS_MYLOCKb 28
157
158 #define LCK_RW_TAG_DESTROYED 0x00002007 /* lock marked as Destroyed */
159
160 #else
161 #ifdef KERNEL_PRIVATE
162 typedef struct {
163 unsigned int opaque[3];
164 } lck_rw_t;
165 #else
166 typedef struct __lck_rw_t__ lck_rw_t;
167 #endif
168 #endif
169
170 #endif /* _I386_LOCKS_H_ */