]>
Commit | Line | Data |
---|---|---|
1c79356b | 1 | /* |
2d21ac55 | 2 | * Copyright (c) 2000-2006 Apple Computer, Inc. All rights reserved. |
1c79356b | 3 | * |
2d21ac55 | 4 | * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ |
1c79356b | 5 | * |
2d21ac55 A |
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. | |
8f6c56a5 | 14 | * |
2d21ac55 A |
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 | |
8f6c56a5 A |
20 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, |
21 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
2d21ac55 A |
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. | |
8f6c56a5 | 25 | * |
2d21ac55 | 26 | * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ |
1c79356b A |
27 | */ |
28 | /* | |
29 | * @OSF_COPYRIGHT@ | |
30 | */ | |
31 | /* | |
32 | * Mach Operating System | |
33 | * Copyright (c) 1991,1990,1989,1988,1987 Carnegie Mellon University | |
34 | * All Rights Reserved. | |
35 | * | |
36 | * Permission to use, copy, modify and distribute this software and its | |
37 | * documentation is hereby granted, provided that both the copyright | |
38 | * notice and this permission notice appear in all copies of the | |
39 | * software, derivative works or modified versions, and any portions | |
40 | * thereof, and that both notices appear in supporting documentation. | |
41 | * | |
42 | * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" | |
43 | * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR | |
44 | * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. | |
45 | * | |
46 | * Carnegie Mellon requests users of this software to return to | |
47 | * | |
48 | * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU | |
49 | * School of Computer Science | |
50 | * Carnegie Mellon University | |
51 | * Pittsburgh PA 15213-3890 | |
52 | * | |
53 | * any improvements or extensions that they make and grant Carnegie Mellon | |
54 | * the rights to redistribute these changes. | |
55 | */ | |
56 | /* | |
57 | */ | |
58 | /* | |
59 | * File: sched_prim.h | |
60 | * Author: David Golub | |
61 | * | |
62 | * Scheduling primitive definitions file | |
63 | * | |
64 | */ | |
65 | ||
66 | #ifndef _KERN_SCHED_PRIM_H_ | |
67 | #define _KERN_SCHED_PRIM_H_ | |
68 | ||
69 | #include <mach/boolean.h> | |
70 | #include <mach/machine/vm_types.h> | |
71 | #include <mach/kern_return.h> | |
72 | #include <kern/clock.h> | |
73 | #include <kern/kern_types.h> | |
74 | #include <kern/thread.h> | |
91447636 | 75 | #include <sys/cdefs.h> |
9bccf70c A |
76 | |
77 | #ifdef MACH_KERNEL_PRIVATE | |
1c79356b | 78 | |
91447636 | 79 | /* Initialization */ |
2d21ac55 | 80 | extern void sched_init(void) __attribute__((section("__TEXT, initcode"))); |
1c79356b | 81 | |
91447636 | 82 | extern void sched_startup(void); |
1c79356b | 83 | |
91447636 | 84 | extern void sched_timebase_init(void); |
1c79356b | 85 | |
91447636 | 86 | /* Force a preemption point for a thread and wait for it to stop running */ |
1c79356b A |
87 | extern boolean_t thread_stop( |
88 | thread_t thread); | |
89 | ||
91447636 A |
90 | /* Release a previous stop request */ |
91 | extern void thread_unstop( | |
1c79356b A |
92 | thread_t thread); |
93 | ||
91447636 A |
94 | /* Wait for a thread to stop running */ |
95 | extern void thread_wait( | |
96 | thread_t thread); | |
1c79356b | 97 | |
91447636 A |
98 | /* Unblock thread on wake up */ |
99 | extern boolean_t thread_unblock( | |
100 | thread_t thread, | |
101 | wait_result_t wresult); | |
1c79356b | 102 | |
91447636 A |
103 | /* Unblock and dispatch thread */ |
104 | extern kern_return_t thread_go( | |
105 | thread_t thread, | |
106 | wait_result_t wresult); | |
1c79356b | 107 | |
2d21ac55 | 108 | /* Handle threads at context switch */ |
91447636 | 109 | extern void thread_dispatch( |
2d21ac55 A |
110 | thread_t old_thread, |
111 | thread_t new_thread); | |
1c79356b | 112 | |
91447636 A |
113 | /* Switch directly to a particular thread */ |
114 | extern int thread_run( | |
115 | thread_t self, | |
116 | thread_continue_t continuation, | |
117 | void *parameter, | |
118 | thread_t new_thread); | |
119 | ||
120 | /* Resume thread with new stack */ | |
121 | extern void thread_continue( | |
122 | thread_t old_thread); | |
123 | ||
1c79356b A |
124 | /* Invoke continuation */ |
125 | extern void call_continuation( | |
91447636 A |
126 | thread_continue_t continuation, |
127 | void *parameter, | |
128 | wait_result_t wresult); | |
9bccf70c A |
129 | |
130 | /* Set the current scheduled priority */ | |
131 | extern void set_sched_pri( | |
132 | thread_t thread, | |
133 | int priority); | |
1c79356b | 134 | |
9bccf70c A |
135 | /* Set base priority of the specified thread */ |
136 | extern void set_priority( | |
137 | thread_t thread, | |
138 | int priority); | |
139 | ||
140 | /* Reset scheduled priority of thread */ | |
1c79356b | 141 | extern void compute_priority( |
9bccf70c A |
142 | thread_t thread, |
143 | boolean_t override_depress); | |
1c79356b | 144 | |
9bccf70c | 145 | /* Adjust scheduled priority of thread during execution */ |
1c79356b | 146 | extern void compute_my_priority( |
9bccf70c | 147 | thread_t thread); |
1c79356b A |
148 | |
149 | /* Periodic scheduler activity */ | |
91447636 | 150 | extern void sched_tick_thread(void); |
1c79356b | 151 | |
91447636 | 152 | /* Perform sched_tick housekeeping activities */ |
1c79356b | 153 | extern void update_priority( |
9bccf70c | 154 | thread_t thread); |
1c79356b | 155 | |
91447636 | 156 | /* Idle processor thread */ |
1c79356b A |
157 | extern void idle_thread(void); |
158 | ||
91447636 A |
159 | extern kern_return_t idle_thread_create( |
160 | processor_t processor); | |
1c79356b A |
161 | |
162 | /* Start thread running */ | |
163 | extern void thread_bootstrap_return(void); | |
164 | ||
1c79356b A |
165 | /* Continuation return from syscall */ |
166 | extern void thread_syscall_return( | |
167 | kern_return_t ret); | |
168 | ||
91447636 | 169 | /* Context switch */ |
9bccf70c A |
170 | extern wait_result_t thread_block_reason( |
171 | thread_continue_t continuation, | |
91447636 | 172 | void *parameter, |
9bccf70c | 173 | ast_t reason); |
1c79356b | 174 | |
91447636 | 175 | /* Reschedule thread for execution */ |
1c79356b | 176 | extern void thread_setrun( |
9bccf70c | 177 | thread_t thread, |
55e303ae | 178 | integer_t options); |
1c79356b | 179 | |
2d21ac55 A |
180 | #define SCHED_TAILQ 1 |
181 | #define SCHED_HEADQ 2 | |
182 | #define SCHED_PREEMPT 4 | |
1c79356b | 183 | |
2d21ac55 | 184 | /* Bind the current thread to a particular processor */ |
55e303ae | 185 | extern processor_t thread_bind( |
55e303ae | 186 | processor_t processor); |
1c79356b | 187 | |
2d21ac55 A |
188 | extern void run_queue_init( |
189 | run_queue_t runq); | |
190 | ||
91447636 A |
191 | extern void thread_timer_expire( |
192 | void *thread, | |
193 | void *p1); | |
194 | ||
9bccf70c A |
195 | /* Set the maximum interrupt level for the thread */ |
196 | __private_extern__ wait_interrupt_t thread_interrupt_level( | |
197 | wait_interrupt_t interruptible); | |
198 | ||
199 | __private_extern__ wait_result_t thread_mark_wait_locked( | |
200 | thread_t thread, | |
201 | wait_interrupt_t interruptible); | |
202 | ||
9bccf70c A |
203 | /* Wake up locked thread directly, passing result */ |
204 | __private_extern__ kern_return_t clear_wait_internal( | |
205 | thread_t thread, | |
206 | wait_result_t result); | |
1c79356b A |
207 | |
208 | #endif /* MACH_KERNEL_PRIVATE */ | |
209 | ||
91447636 | 210 | __BEGIN_DECLS |
55e303ae | 211 | |
91447636 A |
212 | #ifdef XNU_KERNEL_PRIVATE |
213 | ||
214 | extern boolean_t assert_wait_possible(void); | |
1c79356b A |
215 | |
216 | /* | |
91447636 | 217 | ****************** Only exported until BSD stops using ******************** |
1c79356b | 218 | */ |
1c79356b A |
219 | |
220 | /* Wake up thread directly, passing result */ | |
9bccf70c A |
221 | extern kern_return_t clear_wait( |
222 | thread_t thread, | |
223 | wait_result_t result); | |
1c79356b | 224 | |
91447636 | 225 | /* Return from exception (BSD-visible interface) */ |
2d21ac55 | 226 | extern void thread_exception_return(void) __dead2; |
1c79356b | 227 | |
91447636 | 228 | #endif /* XNU_KERNEL_PRIVATE */ |
1c79356b | 229 | |
91447636 A |
230 | /* Context switch */ |
231 | extern wait_result_t thread_block( | |
232 | thread_continue_t continuation); | |
1c79356b | 233 | |
91447636 A |
234 | extern wait_result_t thread_block_parameter( |
235 | thread_continue_t continuation, | |
236 | void *parameter); | |
1c79356b | 237 | |
1c79356b | 238 | /* Declare thread will wait on a particular event */ |
91447636 A |
239 | extern wait_result_t assert_wait( |
240 | event_t event, | |
241 | wait_interrupt_t interruptible); | |
1c79356b | 242 | |
91447636 A |
243 | /* Assert that the thread intends to wait with a timeout */ |
244 | extern wait_result_t assert_wait_timeout( | |
245 | event_t event, | |
246 | wait_interrupt_t interruptible, | |
247 | uint32_t interval, | |
248 | uint32_t scale_factor); | |
1c79356b | 249 | |
91447636 A |
250 | extern wait_result_t assert_wait_deadline( |
251 | event_t event, | |
252 | wait_interrupt_t interruptible, | |
253 | uint64_t deadline); | |
1c79356b | 254 | |
91447636 A |
255 | /* Wake up thread (or threads) waiting on a particular event */ |
256 | extern kern_return_t thread_wakeup_prim( | |
257 | event_t event, | |
258 | boolean_t one_thread, | |
259 | wait_result_t result); | |
1c79356b A |
260 | |
261 | #define thread_wakeup(x) \ | |
262 | thread_wakeup_prim((x), FALSE, THREAD_AWAKENED) | |
263 | #define thread_wakeup_with_result(x, z) \ | |
264 | thread_wakeup_prim((x), FALSE, (z)) | |
265 | #define thread_wakeup_one(x) \ | |
266 | thread_wakeup_prim((x), TRUE, THREAD_AWAKENED) | |
267 | ||
91447636 A |
268 | extern boolean_t preemption_enabled(void); |
269 | ||
270 | #ifdef KERNEL_PRIVATE | |
271 | ||
272 | /* | |
273 | * Obsolete interfaces. | |
274 | */ | |
275 | ||
276 | extern void thread_set_timer( | |
277 | uint32_t interval, | |
278 | uint32_t scale_factor); | |
279 | ||
280 | extern void thread_set_timer_deadline( | |
281 | uint64_t deadline); | |
0b4e3aa0 | 282 | |
91447636 A |
283 | extern void thread_cancel_timer(void); |
284 | ||
285 | #ifndef MACH_KERNEL_PRIVATE | |
286 | ||
287 | #ifndef ABSOLUTETIME_SCALAR_TYPE | |
0b4e3aa0 A |
288 | |
289 | #define thread_set_timer_deadline(a) \ | |
290 | thread_set_timer_deadline(__OSAbsoluteTime(a)) | |
291 | ||
91447636 A |
292 | #endif /* ABSOLUTETIME_SCALAR_TYPE */ |
293 | ||
294 | #endif /* MACH_KERNEL_PRIVATE */ | |
295 | ||
296 | #endif /* KERNEL_PRIVATE */ | |
297 | ||
298 | __END_DECLS | |
1c79356b A |
299 | |
300 | #endif /* _KERN_SCHED_PRIM_H_ */ |