2 * Copyright (c) 2004-2007 Apple 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@
29 #ifndef _I386_LOCKS_H_
30 #define _I386_LOCKS_H_
32 #include <sys/appleapiopts.h>
33 #include <kern/kern_types.h>
35 #ifdef MACH_KERNEL_PRIVATE
37 #include <i386/hw_lock_types.h>
39 extern unsigned int LcksOpts
;
41 #define enaLkDeb 0x00000001 /* Request debug in default attribute */
42 #define enaLkStat 0x00000002 /* Request statistic in default attribute */
46 #ifdef MACH_KERNEL_PRIVATE
48 unsigned int lck_spin_data
[10]; /* XXX - usimple_lock_data_t */
51 #define LCK_SPIN_TAG_DESTROYED 0x00002007 /* lock marked as Destroyed */
56 unsigned int opaque
[10];
59 typedef struct __lck_spin_t__ lck_spin_t
;
63 #ifdef MACH_KERNEL_PRIVATE
64 typedef struct _lck_mtx_
{
67 unsigned int lck_mtxd_ilk
;
68 unsigned int lck_mtxd_locked
;
69 unsigned short lck_mtxd_waiters
;
70 unsigned short lck_mtxd_pri
;
73 unsigned int lck_mtxi_tag
;
74 struct _lck_mtx_ext_
*lck_mtxi_ptr
;
75 unsigned int lck_mtxi_pad8
;
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
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
88 #define LCK_MTX_TAG_INDIRECT 0x00001007 /* lock marked as Indirect */
89 #define LCK_MTX_TAG_DESTROYED 0x00002007 /* lock marked as Destroyed */
91 #define MUTEX_LOCKED_AS_SPIN 0x00004001 /* used to indicate that the mutex */
92 /* was acquired as a spin lock - stored in lck_mtxd_locked */
93 /* Adaptive spin before blocking */
94 extern unsigned int MutexSpin
;
95 extern void lck_mtx_lock_spinwait(lck_mtx_t
*lck
);
97 extern void lck_mtx_interlock_panic(lck_mtx_t
*lck
);
99 extern void hw_lock_byte_init(uint8_t *lock_byte
);
100 extern void hw_lock_byte_lock(uint8_t *lock_byte
);
101 extern void hw_lock_byte_unlock(uint8_t *lock_byte
);
109 #define MUTEX_TAG 0x4d4d
112 unsigned int lck_mtx_stat_data
;
115 typedef struct _lck_mtx_ext_
{
117 struct _lck_grp_
*lck_mtx_grp
;
118 unsigned int lck_mtx_attr
;
119 lck_mtx_deb_t lck_mtx_deb
;
120 uint64_t lck_mtx_stat
;
123 #define LCK_MTX_ATTR_DEBUG 0x1
124 #define LCK_MTX_ATTR_DEBUGb 0
125 #define LCK_MTX_ATTR_STAT 0x2
126 #define LCK_MTX_ATTR_STATb 1
129 #ifdef KERNEL_PRIVATE
131 unsigned int opaque
[3];
134 typedef struct __lck_mtx_t__ lck_mtx_t
;
138 #ifdef MACH_KERNEL_PRIVATE
139 #pragma pack(1) /* Make sure the structure stays as we defined it */
141 volatile uint16_t lck_rw_shared_count
; /* No. of accepted readers */
142 uint8_t lck_rw_interlock
; /* Interlock byte */
144 lck_rw_priv_excl
:1, /* Writers prioritized if set */
145 lck_rw_want_upgrade
:1, /* Read-to-write upgrade waiting */
146 lck_rw_want_write
:1, /* Writer waiting or locked for write */
147 lck_r_waiting
:1, /* Reader is sleeping on lock */
148 lck_w_waiting
:1, /* Writer is sleeping on lock */
149 lck_rw_can_sleep
:1, /* Can attempts to lock go to sleep? */
150 lck_rw_pad6
:2; /* padding */
152 unsigned int lck_rw_tag
; /* This can be obsoleted when stats
155 unsigned int lck_rw_pad8
;
159 #define LCK_RW_ATTR_DEBUG 0x1
160 #define LCK_RW_ATTR_DEBUGb 0
161 #define LCK_RW_ATTR_STAT 0x2
162 #define LCK_RW_ATTR_STATb 1
163 #define LCK_RW_ATTR_READ_PRI 0x3
164 #define LCK_RW_ATTR_READ_PRIb 2
165 #define LCK_RW_ATTR_DIS_THREAD 0x40000000
166 #define LCK_RW_ATTR_DIS_THREADb 30
167 #define LCK_RW_ATTR_DIS_MYLOCK 0x10000000
168 #define LCK_RW_ATTR_DIS_MYLOCKb 28
170 #define LCK_RW_TAG_DESTROYED 0x00002007 /* lock marked as Destroyed */
173 #ifdef KERNEL_PRIVATE
175 unsigned int opaque
[3];
178 typedef struct __lck_rw_t__ lck_rw_t
;
182 #endif /* _I386_LOCKS_H_ */