]> git.saurik.com Git - apple/xnu.git/blob - osfmk/kern/lock.h
xnu-792.1.5.tar.gz
[apple/xnu.git] / osfmk / kern / lock.h
1 /*
2 * Copyright (c) 2000-2005 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 * @OSF_COPYRIGHT@
24 */
25 /*
26 * Mach Operating System
27 * Copyright (c) 1991,1990,1989,1988,1987 Carnegie Mellon University
28 * All Rights Reserved.
29 *
30 * Permission to use, copy, modify and distribute this software and its
31 * documentation is hereby granted, provided that both the copyright
32 * notice and this permission notice appear in all copies of the
33 * software, derivative works or modified versions, and any portions
34 * thereof, and that both notices appear in supporting documentation.
35 *
36 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
37 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
38 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
39 *
40 * Carnegie Mellon requests users of this software to return to
41 *
42 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
43 * School of Computer Science
44 * Carnegie Mellon University
45 * Pittsburgh PA 15213-3890
46 *
47 * any improvements or extensions that they make and grant Carnegie Mellon
48 * the rights to redistribute these changes.
49 */
50 /*
51 * File: kern/lock.h
52 * Author: Avadis Tevanian, Jr., Michael Wayne Young
53 * Date: 1985
54 *
55 * Higher Level Locking primitives definitions
56 */
57
58 #ifdef KERNEL_PRIVATE
59
60 #ifndef _KERN_LOCK_H_
61 #define _KERN_LOCK_H_
62
63 #include <kern/simple_lock.h>
64 #include <machine/lock.h>
65 #include <sys/cdefs.h>
66
67 __BEGIN_DECLS
68
69 #ifndef MACH_KERNEL_PRIVATE
70
71 typedef struct __mutex__ mutex_t;
72
73 #else /* MACH_KERNEL_PRIVATE */
74
75 #define decl_mutex_data(class,name) class mutex_t name;
76 #define mutex_addr(m) (&(m))
77
78 extern void mutex_init(
79 mutex_t *mutex,
80 unsigned short tag);
81
82 #endif /* MACH_KERNEL_PRIVATE */
83
84 extern mutex_t *mutex_alloc(
85 unsigned short tag);
86
87 extern void mutex_free(
88 mutex_t *mutex);
89
90 extern void mutex_lock(
91 mutex_t *mutex);
92
93 extern void mutex_unlock(
94 mutex_t *mutex);
95
96 extern boolean_t mutex_try(
97 mutex_t *mutex);
98
99 extern void mutex_pause(void);
100
101 #define MA_OWNED 0x01
102 #define MA_NOTOWNED 0x02
103
104 void _mutex_assert (
105 mutex_t *mutex,
106 unsigned int what);
107
108 #define mutex_assert(a, b) _mutex_assert(a, b)
109
110 #ifndef MACH_KERNEL_PRIVATE
111
112 typedef struct __lock__ lock_t;
113
114 #else /* MACH_KERNEL_PRIVATE */
115
116 extern void lock_init(
117 lock_t *lock,
118 boolean_t can_sleep,
119 unsigned short tag0,
120 unsigned short tag1);
121
122 #endif /* MACH_KERNEL_PRIVATE */
123
124 extern lock_t *lock_alloc(
125 boolean_t can_sleep,
126 unsigned short tag0,
127 unsigned short tag1);
128
129 extern void lock_free(
130 lock_t *lock);
131
132 extern void lock_write(
133 lock_t *lock);
134
135 extern void lock_read(
136 lock_t *lock);
137
138 extern void lock_done(
139 lock_t *lock);
140
141 extern void lock_write_to_read(
142 lock_t *lock);
143
144 #define lock_read_done(l) lock_done(l)
145 #define lock_write_done(l) lock_done(l)
146
147 extern boolean_t lock_read_to_write(
148 lock_t *lock);
149
150
151 /* Sleep, unlocking and then relocking a usimple_lock in the process */
152 extern wait_result_t thread_sleep_usimple_lock(
153 event_t event,
154 usimple_lock_t lock,
155 wait_interrupt_t interruptible);
156
157 /* Sleep, unlocking and then relocking a mutex in the process */
158 extern wait_result_t thread_sleep_mutex(
159 event_t event,
160 mutex_t *mutex,
161 wait_interrupt_t interruptible);
162
163 /* Sleep with a deadline, unlocking and then relocking a mutex in the process */
164 extern wait_result_t thread_sleep_mutex_deadline(
165 event_t event,
166 mutex_t *mutex,
167 uint64_t deadline,
168 wait_interrupt_t interruptible);
169
170 /* Sleep, unlocking and then relocking a write lock in the process */
171 extern wait_result_t thread_sleep_lock_write(
172 event_t event,
173 lock_t *lock,
174 wait_interrupt_t interruptible);
175 __END_DECLS
176
177 #ifdef MACH_KERNEL_PRIVATE
178
179 extern wait_result_t thread_sleep_fast_usimple_lock(
180 event_t event,
181 simple_lock_t lock,
182 wait_interrupt_t interruptible);
183 #endif /* MACH_KERNEL_PRIVATE */
184
185 #endif /* _KERN_LOCK_H_ */
186
187 #endif /* KERNEL_PRIVATE */