]> git.saurik.com Git - apple/xnu.git/blame - osfmk/i386/locks.h
xnu-1228.5.18.tar.gz
[apple/xnu.git] / osfmk / i386 / locks.h
CommitLineData
91447636 1/*
2d21ac55 2 * Copyright (c) 2004-2007 Apple Inc. All rights reserved.
91447636 3 *
2d21ac55 4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
91447636 5 *
2d21ac55
A
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.
8f6c56a5 14 *
2d21ac55
A
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
8f6c56a5
A
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
2d21ac55
A
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.
8f6c56a5 25 *
2d21ac55 26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
91447636
A
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
39extern 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
47typedef 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
55typedef struct {
56 unsigned int opaque[10];
57} lck_spin_t;
58#else
59typedef struct __lck_spin_t__ lck_spin_t;
60#endif
61#endif
62
63#ifdef MACH_KERNEL_PRIVATE
64typedef 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;
2d21ac55 74 struct _lck_mtx_ext_ *lck_mtxi_ptr;
91447636
A
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
2d21ac55
A
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 */
0c530ab8
A
93/* Adaptive spin before blocking */
94extern unsigned int MutexSpin;
2d21ac55
A
95extern void lck_mtx_lock_spinwait(lck_mtx_t *lck);
96
97extern void lck_mtx_interlock_panic(lck_mtx_t *lck);
0c530ab8 98
2d21ac55
A
99extern void hw_lock_byte_init(uint8_t *lock_byte);
100extern void hw_lock_byte_lock(uint8_t *lock_byte);
101extern void hw_lock_byte_unlock(uint8_t *lock_byte);
0c530ab8 102
91447636
A
103typedef struct {
104 unsigned int type;
105 vm_offset_t pc;
106 vm_offset_t thread;
107} lck_mtx_deb_t;
108
109#define MUTEX_TAG 0x4d4d
110
111typedef struct {
112 unsigned int lck_mtx_stat_data;
113} lck_mtx_stat_t;
114
115typedef struct _lck_mtx_ext_ {
116 lck_mtx_t lck_mtx;
117 struct _lck_grp_ *lck_mtx_grp;
118 unsigned int lck_mtx_attr;
119 lck_mtx_deb_t lck_mtx_deb;
2d21ac55 120 uint64_t lck_mtx_stat;
91447636
A
121} lck_mtx_ext_t;
122
123#define LCK_MTX_ATTR_DEBUG 0x1
0c530ab8 124#define LCK_MTX_ATTR_DEBUGb 0
91447636 125#define LCK_MTX_ATTR_STAT 0x2
0c530ab8 126#define LCK_MTX_ATTR_STATb 1
91447636
A
127
128#else
129#ifdef KERNEL_PRIVATE
130typedef struct {
131 unsigned int opaque[3];
132} lck_mtx_t;
133#else
134typedef struct __lck_mtx_t__ lck_mtx_t;
135#endif
136#endif
137
138#ifdef MACH_KERNEL_PRIVATE
2d21ac55 139#pragma pack(1) /* Make sure the structure stays as we defined it */
91447636 140typedef struct {
2d21ac55
A
141 volatile uint16_t lck_rw_shared_count; /* No. of accepted readers */
142 uint8_t lck_rw_interlock; /* Interlock byte */
143 volatile uint8_t
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 */
151
152 unsigned int lck_rw_tag; /* This can be obsoleted when stats
153 * are in
154 */
155 unsigned int lck_rw_pad8;
91447636 156} lck_rw_t;
2d21ac55 157#pragma pack()
91447636 158
0c530ab8
A
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
169
91447636
A
170#define LCK_RW_TAG_DESTROYED 0x00002007 /* lock marked as Destroyed */
171
172#else
173#ifdef KERNEL_PRIVATE
174typedef struct {
175 unsigned int opaque[3];
176} lck_rw_t;
177#else
178typedef struct __lck_rw_t__ lck_rw_t;
179#endif
180#endif
181
182#endif /* _I386_LOCKS_H_ */