2 * Copyright (c) 2000-2005 Apple Computer, Inc. All rights reserved.
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
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.
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
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.
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
32 * Mach Operating System
33 * Copyright (c) 1991,1990,1989,1988,1987 Carnegie Mellon University
34 * All Rights Reserved.
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.
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.
46 * Carnegie Mellon requests users of this software to return to
48 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
49 * School of Computer Science
50 * Carnegie Mellon University
51 * Pittsburgh PA 15213-3890
53 * any improvements or extensions that they make and grant Carnegie Mellon
54 * the rights to redistribute these changes.
62 * Scheduling primitive definitions file
66 #ifndef _KERN_SCHED_PRIM_H_
67 #define _KERN_SCHED_PRIM_H_
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>
75 #include <sys/cdefs.h>
77 #ifdef MACH_KERNEL_PRIVATE
80 extern void sched_init(void);
82 extern void sched_startup(void);
84 extern void sched_timebase_init(void);
86 /* Force a preemption point for a thread and wait for it to stop running */
87 extern boolean_t
thread_stop(
90 /* Release a previous stop request */
91 extern void thread_unstop(
94 /* Wait for a thread to stop running */
95 extern void thread_wait(
98 /* Select a thread to run */
99 extern thread_t
thread_select(
100 processor_t myprocessor
);
102 /* Unblock thread on wake up */
103 extern boolean_t
thread_unblock(
105 wait_result_t wresult
);
107 /* Unblock and dispatch thread */
108 extern kern_return_t
thread_go(
110 wait_result_t wresult
);
112 /* Context switch primitive */
113 extern boolean_t
thread_invoke(
118 /* Perform calculations for thread finishing execution */
119 extern void thread_done(
122 processor_t processor
);
124 /* Set up for thread beginning execution */
125 extern void thread_begin(
127 processor_t processor
);
129 /* Handle previous thread at context switch */
130 extern void thread_dispatch(
133 /* Switch directly to a particular thread */
134 extern int thread_run(
136 thread_continue_t continuation
,
138 thread_t new_thread
);
140 /* Resume thread with new stack */
141 extern void thread_continue(
142 thread_t old_thread
);
144 /* Invoke continuation */
145 extern void call_continuation(
146 thread_continue_t continuation
,
148 wait_result_t wresult
);
150 /* Set the current scheduled priority */
151 extern void set_sched_pri(
155 /* Set base priority of the specified thread */
156 extern void set_priority(
160 /* Reset scheduled priority of thread */
161 extern void compute_priority(
163 boolean_t override_depress
);
165 /* Adjust scheduled priority of thread during execution */
166 extern void compute_my_priority(
169 /* Periodic scheduler activity */
170 extern void sched_tick_thread(void);
172 /* Perform sched_tick housekeeping activities */
173 extern void update_priority(
176 /* Idle processor thread */
177 extern void idle_thread(void);
179 extern kern_return_t
idle_thread_create(
180 processor_t processor
);
182 /* Start thread running */
183 extern void thread_bootstrap_return(void);
185 /* Continuation return from syscall */
186 extern void thread_syscall_return(
190 extern wait_result_t
thread_block_reason(
191 thread_continue_t continuation
,
195 /* Reschedule thread for execution */
196 extern void thread_setrun(
200 #define SCHED_TAILQ 0
201 #define SCHED_HEADQ 1
202 #define SCHED_PREEMPT 2
204 /* Bind thread to a particular processor */
205 extern processor_t
thread_bind(
207 processor_t processor
);
209 extern void thread_timer_expire(
213 /* Set the maximum interrupt level for the thread */
214 __private_extern__ wait_interrupt_t
thread_interrupt_level(
215 wait_interrupt_t interruptible
);
217 __private_extern__ wait_result_t
thread_mark_wait_locked(
219 wait_interrupt_t interruptible
);
221 /* Wake up locked thread directly, passing result */
222 __private_extern__ kern_return_t
clear_wait_internal(
224 wait_result_t result
);
226 #endif /* MACH_KERNEL_PRIVATE */
230 #ifdef XNU_KERNEL_PRIVATE
232 extern boolean_t
assert_wait_possible(void);
235 ****************** Only exported until BSD stops using ********************
238 /* Wake up thread directly, passing result */
239 extern kern_return_t
clear_wait(
241 wait_result_t result
);
243 /* Return from exception (BSD-visible interface) */
244 extern void thread_exception_return(void);
246 #endif /* XNU_KERNEL_PRIVATE */
249 extern wait_result_t
thread_block(
250 thread_continue_t continuation
);
252 extern wait_result_t
thread_block_parameter(
253 thread_continue_t continuation
,
256 /* Declare thread will wait on a particular event */
257 extern wait_result_t
assert_wait(
259 wait_interrupt_t interruptible
);
261 /* Assert that the thread intends to wait with a timeout */
262 extern wait_result_t
assert_wait_timeout(
264 wait_interrupt_t interruptible
,
266 uint32_t scale_factor
);
268 extern wait_result_t
assert_wait_deadline(
270 wait_interrupt_t interruptible
,
273 /* Wake up thread (or threads) waiting on a particular event */
274 extern kern_return_t
thread_wakeup_prim(
276 boolean_t one_thread
,
277 wait_result_t result
);
279 #define thread_wakeup(x) \
280 thread_wakeup_prim((x), FALSE, THREAD_AWAKENED)
281 #define thread_wakeup_with_result(x, z) \
282 thread_wakeup_prim((x), FALSE, (z))
283 #define thread_wakeup_one(x) \
284 thread_wakeup_prim((x), TRUE, THREAD_AWAKENED)
286 extern boolean_t
preemption_enabled(void);
288 #ifdef KERNEL_PRIVATE
291 * Obsolete interfaces.
294 extern void thread_set_timer(
296 uint32_t scale_factor
);
298 extern void thread_set_timer_deadline(
301 extern void thread_cancel_timer(void);
303 #ifndef MACH_KERNEL_PRIVATE
305 #ifndef ABSOLUTETIME_SCALAR_TYPE
307 #define thread_set_timer_deadline(a) \
308 thread_set_timer_deadline(__OSAbsoluteTime(a))
310 #endif /* ABSOLUTETIME_SCALAR_TYPE */
312 #endif /* MACH_KERNEL_PRIVATE */
314 #endif /* KERNEL_PRIVATE */
318 #endif /* _KERN_SCHED_PRIM_H_ */