]> git.saurik.com Git - apple/xnu.git/blob - osfmk/kern/simple_lock.h
37fe67747e26bcf4e7ee1a917d185071836b3729
[apple/xnu.git] / osfmk / kern / simple_lock.h
1 /*
2 * Copyright (c) 2000-2005 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_OSREFERENCE_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
10 * License may not be used to create, or enable the creation or
11 * redistribution of, unlawful or unlicensed copies of an Apple operating
12 * system, or to circumvent, violate, or enable the circumvention or
13 * violation of, any terms of an Apple operating system software license
14 * agreement.
15 *
16 * Please obtain a copy of the License at
17 * http://www.opensource.apple.com/apsl/ and read it before using this
18 * file.
19 *
20 * The Original Code and all software distributed under the License are
21 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
22 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
23 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
24 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
25 * Please see the License for the specific language governing rights and
26 * limitations under the License.
27 *
28 * @APPLE_LICENSE_OSREFERENCE_HEADER_END@
29 */
30 /*
31 * Copyright (C) 1998 Apple Computer
32 * All Rights Reserved
33 */
34 /*
35 * @OSF_COPYRIGHT@
36 */
37 /*
38 * Mach Operating System
39 * Copyright (c) 1991,1990,1989,1988,1987 Carnegie Mellon University
40 * All Rights Reserved.
41 *
42 * Permission to use, copy, modify and distribute this software and its
43 * documentation is hereby granted, provided that both the copyright
44 * notice and this permission notice appear in all copies of the
45 * software, derivative works or modified versions, and any portions
46 * thereof, and that both notices appear in supporting documentation.
47 *
48 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
49 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
50 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
51 *
52 * Carnegie Mellon requests users of this software to return to
53 *
54 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
55 * School of Computer Science
56 * Carnegie Mellon University
57 * Pittsburgh PA 15213-3890
58 *
59 * any improvements or extensions that they make and grant Carnegie Mellon
60 * the rights to redistribute these changes.
61 */
62 /*
63 * File: kern/simple_lock.h (derived from kern/lock.h)
64 * Author: Avadis Tevanian, Jr., Michael Wayne Young
65 * Date: 1985
66 *
67 * Atomic primitives and Simple Locking primitives definitions
68 */
69
70 #ifdef KERNEL_PRIVATE
71
72 #ifndef _KERN_SIMPLE_LOCK_H_
73 #define _KERN_SIMPLE_LOCK_H_
74
75 #include <sys/cdefs.h>
76 #include <mach/boolean.h>
77 #include <kern/kern_types.h>
78 #include <machine/simple_lock.h>
79
80 #ifdef MACH_KERNEL_PRIVATE
81 #include <mach_ldebug.h>
82
83 extern void hw_lock_init(
84 hw_lock_t);
85
86 extern void hw_lock_lock(
87 hw_lock_t);
88
89 extern void hw_lock_unlock(
90 hw_lock_t);
91
92 extern unsigned int hw_lock_to(
93 hw_lock_t,
94 unsigned int);
95
96 extern unsigned int hw_lock_try(
97 hw_lock_t);
98
99 extern unsigned int hw_lock_held(
100 hw_lock_t);
101
102 #endif /* MACH_KERNEL_PRIVATE */
103
104 __BEGIN_DECLS
105
106 extern uint32_t hw_atomic_add(
107 uint32_t *dest,
108 uint32_t delt);
109
110 extern uint32_t hw_atomic_sub(
111 uint32_t *dest,
112 uint32_t delt);
113
114 extern uint32_t hw_atomic_or(
115 uint32_t *dest,
116 uint32_t mask);
117
118 extern uint32_t hw_atomic_and(
119 uint32_t *dest,
120 uint32_t mask);
121
122 extern uint32_t hw_compare_and_store(
123 uint32_t oldval,
124 uint32_t newval,
125 uint32_t *dest);
126
127 extern void hw_queue_atomic(
128 unsigned int *anchor,
129 unsigned int *elem,
130 unsigned int disp);
131
132 extern void hw_queue_atomic_list(
133 unsigned int *anchor,
134 unsigned int *first,
135 unsigned int *last,
136 unsigned int disp);
137
138 extern unsigned int *hw_dequeue_atomic(
139 unsigned int *anchor,
140 unsigned int disp);
141
142 extern void usimple_lock_init(
143 usimple_lock_t,
144 unsigned short);
145
146 extern void usimple_lock(
147 usimple_lock_t);
148
149 extern void usimple_unlock(
150 usimple_lock_t);
151
152 extern unsigned int usimple_lock_try(
153 usimple_lock_t);
154
155 __END_DECLS
156
157 #define ETAP_NO_TRACE 0
158 #define ETAP_IO_AHA 0
159
160 /*
161 * If we got to here and we still don't have simple_lock_init
162 * defined, then we must either be outside the osfmk component,
163 * running on a true SMP, or need debug.
164 */
165 #if !defined(simple_lock_init)
166 #define simple_lock_init(l,t) usimple_lock_init(l,t)
167 #define simple_lock(l) usimple_lock(l)
168 #define simple_unlock(l) usimple_unlock(l)
169 #define simple_lock_try(l) usimple_lock_try(l)
170 #define simple_lock_addr(l) (&(l))
171 #define thread_sleep_simple_lock(l, e, i) \
172 thread_sleep_usimple_lock((l), (e), (i))
173 #endif /* !defined(simple_lock_init) */
174
175 #endif /*!_KERN_SIMPLE_LOCK_H_*/
176
177 #endif /* KERNEL_PRIVATE */