]> git.saurik.com Git - apple/xnu.git/blob - osfmk/kern/simple_lock.h
258d323dbf8a5bdefeaef814c1fb6684e42afca7
[apple/xnu.git] / osfmk / kern / simple_lock.h
1 /*
2 * Copyright (c) 2000-2005 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
5 *
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.
14 *
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
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.
25 *
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
27 */
28 /*
29 * Copyright (C) 1998 Apple Computer
30 * All Rights Reserved
31 */
32 /*
33 * @OSF_COPYRIGHT@
34 */
35 /*
36 * Mach Operating System
37 * Copyright (c) 1991,1990,1989,1988,1987 Carnegie Mellon University
38 * All Rights Reserved.
39 *
40 * Permission to use, copy, modify and distribute this software and its
41 * documentation is hereby granted, provided that both the copyright
42 * notice and this permission notice appear in all copies of the
43 * software, derivative works or modified versions, and any portions
44 * thereof, and that both notices appear in supporting documentation.
45 *
46 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
47 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
48 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
49 *
50 * Carnegie Mellon requests users of this software to return to
51 *
52 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
53 * School of Computer Science
54 * Carnegie Mellon University
55 * Pittsburgh PA 15213-3890
56 *
57 * any improvements or extensions that they make and grant Carnegie Mellon
58 * the rights to redistribute these changes.
59 */
60 /*
61 * File: kern/simple_lock.h (derived from kern/lock.h)
62 * Author: Avadis Tevanian, Jr., Michael Wayne Young
63 * Date: 1985
64 *
65 * Atomic primitives and Simple Locking primitives definitions
66 */
67
68 #ifdef KERNEL_PRIVATE
69
70 #ifndef _KERN_SIMPLE_LOCK_H_
71 #define _KERN_SIMPLE_LOCK_H_
72
73 #include <sys/cdefs.h>
74 #include <mach/boolean.h>
75 #include <kern/kern_types.h>
76 #include <kern/lock_group.h>
77 #include <machine/simple_lock.h>
78
79 #ifdef MACH_KERNEL_PRIVATE
80 #include <mach_ldebug.h>
81
82 extern void hw_lock_init(
83 hw_lock_t);
84
85 #if LOCK_STATS
86 extern void hw_lock_lock(
87 hw_lock_t,
88 lck_grp_t*);
89
90 extern void hw_lock_lock_nopreempt(
91 hw_lock_t,
92 lck_grp_t*);
93
94 extern unsigned int hw_lock_to(
95 hw_lock_t,
96 uint64_t,
97 lck_grp_t*);
98
99 extern unsigned int hw_lock_try(
100 hw_lock_t,
101 lck_grp_t*);
102
103 extern unsigned int hw_lock_try_nopreempt(
104 hw_lock_t,
105 lck_grp_t*);
106
107 #else
108
109 extern void hw_lock_lock(
110 hw_lock_t);
111
112 #define hw_lock_lock(lck, grp) hw_lock_lock(lck)
113
114 extern void hw_lock_lock_nopreempt(
115 hw_lock_t);
116 #define hw_lock_lock_nopreempt(lck, grp) hw_lock_lock_nopreempt(lck)
117
118 extern unsigned int hw_lock_to(
119 hw_lock_t,
120 uint64_t);
121 #define hw_lock_to(lck, timeout, grp) hw_lock_to(lck, timeout)
122
123
124 extern unsigned int hw_lock_try(
125 hw_lock_t);
126 #define hw_lock_try(lck, grp) hw_lock_try(lck)
127
128 extern unsigned int hw_lock_try_nopreempt(
129 hw_lock_t);
130 #define hw_lock_try_nopreempt(lck, grp) hw_lock_try_nopreempt(lck)
131
132
133 #endif /* LOCK_STATS */
134
135 extern void hw_lock_unlock(
136 hw_lock_t);
137
138 extern void hw_lock_unlock_nopreempt(
139 hw_lock_t);
140
141 extern unsigned int hw_lock_held(
142 hw_lock_t);
143
144 #endif /* MACH_KERNEL_PRIVATE */
145
146 __BEGIN_DECLS
147
148 extern uint32_t hw_atomic_add(
149 volatile uint32_t *dest,
150 uint32_t delt);
151
152 extern uint32_t hw_atomic_sub(
153 volatile uint32_t *dest,
154 uint32_t delt);
155
156 extern uint32_t hw_atomic_or(
157 volatile uint32_t *dest,
158 uint32_t mask);
159
160 extern uint32_t hw_atomic_and(
161 volatile uint32_t *dest,
162 uint32_t mask);
163
164 /*
165 * Variant of hw_atomic_or which doesn't return a value; potentially
166 * more efficient on some platforms.
167 */
168 extern void hw_atomic_or_noret(
169 volatile uint32_t *dest,
170 uint32_t mask);
171 /*
172 * Variant of hw_atomic_and which doesn't return a value; potentially
173 * more efficient on some platforms.
174 */
175
176 extern void hw_atomic_and_noret(
177 volatile uint32_t *dest,
178 uint32_t mask);
179
180 extern uint32_t hw_compare_and_store(
181 uint32_t oldval,
182 uint32_t newval,
183 volatile uint32_t *dest);
184
185 extern void hw_queue_atomic(
186 unsigned int *anchor,
187 unsigned int *elem,
188 unsigned int disp);
189
190 extern void hw_queue_atomic_list(
191 unsigned int *anchor,
192 unsigned int *first,
193 unsigned int *last,
194 unsigned int disp);
195
196 extern unsigned int *hw_dequeue_atomic(
197 unsigned int *anchor,
198 unsigned int disp);
199
200 extern void usimple_lock_init(
201 usimple_lock_t,
202 unsigned short);
203
204 #if LOCK_STATS
205 extern void usimple_lock(
206 usimple_lock_t,
207 lck_grp_t*);
208
209 extern unsigned int usimple_lock_try(
210 usimple_lock_t,
211 lck_grp_t*);
212
213 extern void usimple_lock_try_lock_loop(
214 usimple_lock_t,
215 lck_grp_t*);
216 #else
217 extern void usimple_lock(
218 usimple_lock_t);
219 #define usimple_lock(lck, grp) usimple_lock(lck)
220
221
222 extern unsigned int usimple_lock_try(
223 usimple_lock_t);
224
225 #define usimple_lock_try(lck, grp) usimple_lock_try(lck)
226
227 extern void usimple_lock_try_lock_loop(
228 usimple_lock_t);
229 #define usimple_lock_try_lock_loop(lck, grp) usimple_lock_try_lock_loop(lck)
230
231 #endif /* LOCK_STATS */
232
233 extern void usimple_unlock(
234 usimple_lock_t);
235
236
237 __END_DECLS
238
239 #define ETAP_NO_TRACE 0
240 #define ETAP_IO_AHA 0
241
242 /*
243 * If we got to here and we still don't have simple_lock_init
244 * defined, then we must either be outside the osfmk component,
245 * running on a true SMP, or need debug.
246 */
247 #if !defined(simple_lock_init)
248 #define simple_lock_init(l, t) usimple_lock_init(l,t)
249 #define simple_lock(l, grp) usimple_lock(l, grp)
250 #define simple_unlock(l) usimple_unlock(l)
251 #define simple_lock_try(l, grp) usimple_lock_try(l, grp)
252 #define simple_lock_try_lock_loop(l, grp) usimple_lock_try_lock_loop(l, grp)
253 #define simple_lock_addr(l) (&(l))
254 #endif /* !defined(simple_lock_init) */
255
256 #endif /*!_KERN_SIMPLE_LOCK_H_*/
257
258 #endif /* KERNEL_PRIVATE */