]> git.saurik.com Git - apple/xnu.git/blob - osfmk/i386/locks.h
xnu-792.tar.gz
[apple/xnu.git] / osfmk / i386 / locks.h
1 /*
2 * Copyright (c) 2004 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
11 *
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
18 * under the License.
19 *
20 * @APPLE_LICENSE_HEADER_END@
21 */
22
23 #ifndef _I386_LOCKS_H_
24 #define _I386_LOCKS_H_
25
26 #include <sys/appleapiopts.h>
27 #include <kern/kern_types.h>
28
29 #ifdef MACH_KERNEL_PRIVATE
30
31 #include <i386/hw_lock_types.h>
32
33 extern unsigned int LcksOpts;
34
35 #define enaLkDeb 0x00000001 /* Request debug in default attribute */
36 #define enaLkStat 0x00000002 /* Request statistic in default attribute */
37
38 #endif
39
40 #ifdef MACH_KERNEL_PRIVATE
41 typedef struct {
42 unsigned int lck_spin_data[10]; /* XXX - usimple_lock_data_t */
43 } lck_spin_t;
44
45 #define LCK_SPIN_TAG_DESTROYED 0x00002007 /* lock marked as Destroyed */
46
47 #else
48 #ifdef KERNEL_PRIVATE
49 typedef struct {
50 unsigned int opaque[10];
51 } lck_spin_t;
52 #else
53 typedef struct __lck_spin_t__ lck_spin_t;
54 #endif
55 #endif
56
57 #ifdef MACH_KERNEL_PRIVATE
58 typedef struct _lck_mtx_ {
59 union {
60 struct {
61 unsigned int lck_mtxd_ilk;
62 unsigned int lck_mtxd_locked;
63 unsigned short lck_mtxd_waiters;
64 unsigned short lck_mtxd_pri;
65 } lck_mtxd;
66 struct {
67 unsigned int lck_mtxi_tag;
68 struct _lck_mtx_ext_ *lck_mtxi_ptr;
69 unsigned int lck_mtxi_pad8;
70 } lck_mtxi;
71 } lck_mtx_sw;
72 } lck_mtx_t;
73
74 #define lck_mtx_ilk lck_mtx_sw.lck_mtxd.lck_mtxd_ilk
75 #define lck_mtx_locked lck_mtx_sw.lck_mtxd.lck_mtxd_locked
76 #define lck_mtx_waiters lck_mtx_sw.lck_mtxd.lck_mtxd_waiters
77 #define lck_mtx_pri lck_mtx_sw.lck_mtxd.lck_mtxd_pri
78
79 #define lck_mtx_tag lck_mtx_sw.lck_mtxi.lck_mtxi_tag
80 #define lck_mtx_ptr lck_mtx_sw.lck_mtxi.lck_mtxi_ptr
81
82 #define LCK_MTX_TAG_INDIRECT 0x00001007 /* lock marked as Indirect */
83 #define LCK_MTX_TAG_DESTROYED 0x00002007 /* lock marked as Destroyed */
84
85 typedef struct {
86 unsigned int type;
87 vm_offset_t pc;
88 vm_offset_t thread;
89 } lck_mtx_deb_t;
90
91 #define MUTEX_TAG 0x4d4d
92
93 typedef struct {
94 unsigned int lck_mtx_stat_data;
95 } lck_mtx_stat_t;
96
97 typedef struct _lck_mtx_ext_ {
98 lck_mtx_t lck_mtx;
99 struct _lck_grp_ *lck_mtx_grp;
100 unsigned int lck_mtx_attr;
101 lck_mtx_deb_t lck_mtx_deb;
102 lck_mtx_stat_t lck_mtx_stat;
103 } lck_mtx_ext_t;
104
105 #define LCK_MTX_ATTR_DEBUG 0x1
106 #define LCK_MTX_ATTR_DEBUGb 31
107 #define LCK_MTX_ATTR_STAT 0x2
108 #define LCK_MTX_ATTR_STATb 30
109
110 #else
111 #ifdef KERNEL_PRIVATE
112 typedef struct {
113 unsigned int opaque[3];
114 } lck_mtx_t;
115 #else
116 typedef struct __lck_mtx_t__ lck_mtx_t;
117 #endif
118 #endif
119
120 #ifdef MACH_KERNEL_PRIVATE
121 typedef struct {
122 hw_lock_data_t interlock;
123 volatile unsigned int
124 read_count:16, /* No. of accepted readers */
125 want_upgrade:1, /* Read-to-write upgrade waiting */
126 want_write:1, /* Writer is waiting, or locked for write */
127 waiting:1, /* Someone is sleeping on lock */
128 can_sleep:1; /* Can attempts to lock go to sleep? */
129 unsigned int lck_rw_tag;
130 } lck_rw_t;
131
132 #define LCK_RW_TAG_DESTROYED 0x00002007 /* lock marked as Destroyed */
133
134 #else
135 #ifdef KERNEL_PRIVATE
136 typedef struct {
137 unsigned int opaque[3];
138 } lck_rw_t;
139 #else
140 typedef struct __lck_rw_t__ lck_rw_t;
141 #endif
142 #endif
143
144 #endif /* _I386_LOCKS_H_ */