2 * Copyright (c) 2004 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_OSREFERENCE_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
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
16 * Please obtain a copy of the License at
17 * http://www.opensource.apple.com/apsl/ and read it before using this
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.
28 * @APPLE_LICENSE_OSREFERENCE_HEADER_END@
31 #ifndef _I386_LOCKS_H_
32 #define _I386_LOCKS_H_
34 #include <sys/appleapiopts.h>
35 #include <kern/kern_types.h>
37 #ifdef MACH_KERNEL_PRIVATE
39 #include <i386/hw_lock_types.h>
41 extern unsigned int LcksOpts
;
43 #define enaLkDeb 0x00000001 /* Request debug in default attribute */
44 #define enaLkStat 0x00000002 /* Request statistic in default attribute */
48 #ifdef MACH_KERNEL_PRIVATE
50 unsigned int lck_spin_data
[10]; /* XXX - usimple_lock_data_t */
53 #define LCK_SPIN_TAG_DESTROYED 0x00002007 /* lock marked as Destroyed */
58 unsigned int opaque
[10];
61 typedef struct __lck_spin_t__ lck_spin_t
;
65 #ifdef MACH_KERNEL_PRIVATE
66 typedef struct _lck_mtx_
{
69 unsigned int lck_mtxd_ilk
;
70 unsigned int lck_mtxd_locked
;
71 unsigned short lck_mtxd_waiters
;
72 unsigned short lck_mtxd_pri
;
75 unsigned int lck_mtxi_tag
;
76 struct _lck_mtx_ext_
*lck_mtxi_ptr
;
77 unsigned int lck_mtxi_pad8
;
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
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
90 #define LCK_MTX_TAG_INDIRECT 0x00001007 /* lock marked as Indirect */
91 #define LCK_MTX_TAG_DESTROYED 0x00002007 /* lock marked as Destroyed */
93 /* Adaptive spin before blocking */
94 extern unsigned int MutexSpin
;
95 extern void lck_mtx_lock_spin(lck_mtx_t
*lck
);
97 extern void lck_mtx_interlock_spin(lck_mtx_t
*lck
);
105 #define MUTEX_TAG 0x4d4d
108 unsigned int lck_mtx_stat_data
;
111 typedef struct _lck_mtx_ext_
{
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
;
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
125 #ifdef KERNEL_PRIVATE
127 unsigned int opaque
[3];
130 typedef struct __lck_mtx_t__ lck_mtx_t
;
134 #ifdef MACH_KERNEL_PRIVATE
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
;
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
158 #define LCK_RW_TAG_DESTROYED 0x00002007 /* lock marked as Destroyed */
161 #ifdef KERNEL_PRIVATE
163 unsigned int opaque
[3];
166 typedef struct __lck_rw_t__ lck_rw_t
;
170 #endif /* _I386_LOCKS_H_ */