2 * Copyright (c) 2000-2005 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
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.
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
20 * @APPLE_LICENSE_HEADER_END@
26 * Mach Operating System
27 * Copyright (c) 1991,1990,1989,1988,1987 Carnegie Mellon University
28 * All Rights Reserved.
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.
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.
40 * Carnegie Mellon requests users of this software to return to
42 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
43 * School of Computer Science
44 * Carnegie Mellon University
45 * Pittsburgh PA 15213-3890
47 * any improvements or extensions that they make and grant Carnegie Mellon
48 * the rights to redistribute these changes.
52 * Author: Avadis Tevanian, Jr., Michael Wayne Young
55 * Higher Level Locking primitives definitions
63 #include <kern/simple_lock.h>
64 #include <machine/lock.h>
65 #include <sys/cdefs.h>
69 #ifndef MACH_KERNEL_PRIVATE
71 typedef struct __mutex__ mutex_t
;
73 #else /* MACH_KERNEL_PRIVATE */
75 #define decl_mutex_data(class,name) class mutex_t name;
76 #define mutex_addr(m) (&(m))
78 extern void mutex_init(
82 #endif /* MACH_KERNEL_PRIVATE */
84 extern mutex_t
*mutex_alloc(
87 extern void mutex_free(
90 extern void mutex_lock(
93 extern void mutex_unlock(
96 extern boolean_t
mutex_try(
99 extern void mutex_pause(void);
101 #define MA_OWNED 0x01
102 #define MA_NOTOWNED 0x02
108 #define mutex_assert(a, b) _mutex_assert(a, b)
110 #ifndef MACH_KERNEL_PRIVATE
112 typedef struct __lock__ lock_t
;
114 #else /* MACH_KERNEL_PRIVATE */
116 extern void lock_init(
120 unsigned short tag1
);
122 #endif /* MACH_KERNEL_PRIVATE */
124 extern lock_t
*lock_alloc(
127 unsigned short tag1
);
129 extern void lock_free(
132 extern void lock_write(
135 extern void lock_read(
138 extern void lock_done(
141 extern void lock_write_to_read(
144 #define lock_read_done(l) lock_done(l)
145 #define lock_write_done(l) lock_done(l)
147 extern boolean_t
lock_read_to_write(
151 /* Sleep, unlocking and then relocking a usimple_lock in the process */
152 extern wait_result_t
thread_sleep_usimple_lock(
155 wait_interrupt_t interruptible
);
157 /* Sleep, unlocking and then relocking a mutex in the process */
158 extern wait_result_t
thread_sleep_mutex(
161 wait_interrupt_t interruptible
);
163 /* Sleep with a deadline, unlocking and then relocking a mutex in the process */
164 extern wait_result_t
thread_sleep_mutex_deadline(
168 wait_interrupt_t interruptible
);
170 /* Sleep, unlocking and then relocking a write lock in the process */
171 extern wait_result_t
thread_sleep_lock_write(
174 wait_interrupt_t interruptible
);
177 #ifdef MACH_KERNEL_PRIVATE
179 extern wait_result_t
thread_sleep_fast_usimple_lock(
182 wait_interrupt_t interruptible
);
183 #endif /* MACH_KERNEL_PRIVATE */
185 #endif /* _KERN_LOCK_H_ */
187 #endif /* KERNEL_PRIVATE */