]> git.saurik.com Git - apple/xnu.git/blame - osfmk/kern/lock.h
xnu-792.25.20.tar.gz
[apple/xnu.git] / osfmk / kern / lock.h
CommitLineData
1c79356b 1/*
91447636 2 * Copyright (c) 2000-2005 Apple Computer, Inc. All rights reserved.
1c79356b 3 *
6601e61a 4 * @APPLE_LICENSE_HEADER_START@
1c79356b 5 *
6601e61a
A
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.
8f6c56a5 11 *
6601e61a
A
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
8f6c56a5
A
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
6601e61a
A
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.
8f6c56a5 19 *
6601e61a 20 * @APPLE_LICENSE_HEADER_END@
1c79356b 21 */
1c79356b
A
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
91447636
A
58#ifdef KERNEL_PRIVATE
59
1c79356b
A
60#ifndef _KERN_LOCK_H_
61#define _KERN_LOCK_H_
62
1c79356b
A
63#include <kern/simple_lock.h>
64#include <machine/lock.h>
91447636 65#include <sys/cdefs.h>
1c79356b 66
91447636 67__BEGIN_DECLS
9bccf70c 68
91447636 69#ifndef MACH_KERNEL_PRIVATE
9bccf70c 70
91447636 71typedef struct __mutex__ mutex_t;
9bccf70c 72
91447636 73#else /* MACH_KERNEL_PRIVATE */
1c79356b
A
74
75#define decl_mutex_data(class,name) class mutex_t name;
76#define mutex_addr(m) (&(m))
77
91447636
A
78extern void mutex_init(
79 mutex_t *mutex,
80 unsigned short tag);
1c79356b 81
9bccf70c 82#endif /* MACH_KERNEL_PRIVATE */
1c79356b 83
91447636
A
84extern mutex_t *mutex_alloc(
85 unsigned short tag);
9bccf70c 86
91447636
A
87extern void mutex_free(
88 mutex_t *mutex);
55e303ae 89
91447636
A
90extern void mutex_lock(
91 mutex_t *mutex);
55e303ae 92
91447636
A
93extern void mutex_unlock(
94 mutex_t *mutex);
55e303ae
A
95
96extern boolean_t mutex_try(
97 mutex_t *mutex);
1c79356b 98
91447636 99extern void mutex_pause(void);
9bccf70c 100
91447636
A
101#define MA_OWNED 0x01
102#define MA_NOTOWNED 0x02
103
104void _mutex_assert (
105 mutex_t *mutex,
106 unsigned int what);
1c79356b 107
91447636 108#define mutex_assert(a, b) _mutex_assert(a, b)
9bccf70c 109
91447636 110#ifndef MACH_KERNEL_PRIVATE
1c79356b 111
91447636 112typedef struct __lock__ lock_t;
1c79356b 113
91447636 114#else /* MACH_KERNEL_PRIVATE */
1c79356b 115
91447636
A
116extern void lock_init(
117 lock_t *lock,
118 boolean_t can_sleep,
119 unsigned short tag0,
120 unsigned short tag1);
1c79356b 121
9bccf70c
A
122#endif /* MACH_KERNEL_PRIVATE */
123
91447636
A
124extern lock_t *lock_alloc(
125 boolean_t can_sleep,
126 unsigned short tag0,
127 unsigned short tag1);
9bccf70c 128
91447636
A
129extern void lock_free(
130 lock_t *lock);
9bccf70c 131
91447636
A
132extern void lock_write(
133 lock_t *lock);
1c79356b 134
91447636
A
135extern void lock_read(
136 lock_t *lock);
1c79356b 137
91447636
A
138extern void lock_done(
139 lock_t *lock);
1c79356b 140
91447636
A
141extern void lock_write_to_read(
142 lock_t *lock);
1c79356b
A
143
144#define lock_read_done(l) lock_done(l)
145#define lock_write_done(l) lock_done(l)
146
91447636
A
147extern boolean_t lock_read_to_write(
148 lock_t *lock);
149
150
151/* Sleep, unlocking and then relocking a usimple_lock in the process */
152extern 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 */
158extern 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 */
164extern 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 */
171extern 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
179extern 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 */
1c79356b
A
184
185#endif /* _KERN_LOCK_H_ */
91447636
A
186
187#endif /* KERNEL_PRIVATE */