2 * Copyright (c) 2000-2005 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_OSREFERENCE_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
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
16 * Please obtain a copy of the License at
17 * http://www.opensource.apple.com/apsl/ and read it before using this
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.
28 * @APPLE_LICENSE_OSREFERENCE_HEADER_END@
34 * Mach Operating System
35 * Copyright (c) 1991,1990,1989,1988,1987 Carnegie Mellon University
36 * All Rights Reserved.
38 * Permission to use, copy, modify and distribute this software and its
39 * documentation is hereby granted, provided that both the copyright
40 * notice and this permission notice appear in all copies of the
41 * software, derivative works or modified versions, and any portions
42 * thereof, and that both notices appear in supporting documentation.
44 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
45 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
46 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
48 * Carnegie Mellon requests users of this software to return to
50 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
51 * School of Computer Science
52 * Carnegie Mellon University
53 * Pittsburgh PA 15213-3890
55 * any improvements or extensions that they make and grant Carnegie Mellon
56 * the rights to redistribute these changes.
64 * Scheduling primitive definitions file
68 #ifndef _KERN_SCHED_PRIM_H_
69 #define _KERN_SCHED_PRIM_H_
71 #include <mach/boolean.h>
72 #include <mach/machine/vm_types.h>
73 #include <mach/kern_return.h>
74 #include <kern/clock.h>
75 #include <kern/kern_types.h>
76 #include <kern/thread.h>
77 #include <sys/cdefs.h>
79 #ifdef MACH_KERNEL_PRIVATE
82 extern void sched_init(void);
84 extern void sched_startup(void);
86 extern void sched_timebase_init(void);
88 /* Force a preemption point for a thread and wait for it to stop running */
89 extern boolean_t
thread_stop(
92 /* Release a previous stop request */
93 extern void thread_unstop(
96 /* Wait for a thread to stop running */
97 extern void thread_wait(
100 /* Select a thread to run */
101 extern thread_t
thread_select(
102 processor_t myprocessor
);
104 /* Unblock thread on wake up */
105 extern boolean_t
thread_unblock(
107 wait_result_t wresult
);
109 /* Unblock and dispatch thread */
110 extern kern_return_t
thread_go(
112 wait_result_t wresult
);
114 /* Context switch primitive */
115 extern boolean_t
thread_invoke(
120 /* Perform calculations for thread finishing execution */
121 extern void thread_done(
124 processor_t processor
);
126 /* Set up for thread beginning execution */
127 extern void thread_begin(
129 processor_t processor
);
131 /* Handle previous thread at context switch */
132 extern void thread_dispatch(
135 /* Switch directly to a particular thread */
136 extern int thread_run(
138 thread_continue_t continuation
,
140 thread_t new_thread
);
142 /* Resume thread with new stack */
143 extern void thread_continue(
144 thread_t old_thread
);
146 /* Invoke continuation */
147 extern void call_continuation(
148 thread_continue_t continuation
,
150 wait_result_t wresult
);
152 /* Set the current scheduled priority */
153 extern void set_sched_pri(
157 /* Set base priority of the specified thread */
158 extern void set_priority(
162 /* Reset scheduled priority of thread */
163 extern void compute_priority(
165 boolean_t override_depress
);
167 /* Adjust scheduled priority of thread during execution */
168 extern void compute_my_priority(
171 /* Periodic scheduler activity */
172 extern void sched_tick_thread(void);
174 /* Perform sched_tick housekeeping activities */
175 extern void update_priority(
178 /* Idle processor thread */
179 extern void idle_thread(void);
181 extern kern_return_t
idle_thread_create(
182 processor_t processor
);
184 /* Start thread running */
185 extern void thread_bootstrap_return(void);
187 /* Continuation return from syscall */
188 extern void thread_syscall_return(
192 extern wait_result_t
thread_block_reason(
193 thread_continue_t continuation
,
197 /* Reschedule thread for execution */
198 extern void thread_setrun(
202 #define SCHED_TAILQ 0
203 #define SCHED_HEADQ 1
204 #define SCHED_PREEMPT 2
206 /* Bind thread to a particular processor */
207 extern processor_t
thread_bind(
209 processor_t processor
);
211 extern void thread_timer_expire(
215 /* Set the maximum interrupt level for the thread */
216 __private_extern__ wait_interrupt_t
thread_interrupt_level(
217 wait_interrupt_t interruptible
);
219 __private_extern__ wait_result_t
thread_mark_wait_locked(
221 wait_interrupt_t interruptible
);
223 /* Wake up locked thread directly, passing result */
224 __private_extern__ kern_return_t
clear_wait_internal(
226 wait_result_t result
);
228 #endif /* MACH_KERNEL_PRIVATE */
232 #ifdef XNU_KERNEL_PRIVATE
234 extern boolean_t
assert_wait_possible(void);
237 ****************** Only exported until BSD stops using ********************
240 /* Wake up thread directly, passing result */
241 extern kern_return_t
clear_wait(
243 wait_result_t result
);
245 /* Return from exception (BSD-visible interface) */
246 extern void thread_exception_return(void);
248 #endif /* XNU_KERNEL_PRIVATE */
251 extern wait_result_t
thread_block(
252 thread_continue_t continuation
);
254 extern wait_result_t
thread_block_parameter(
255 thread_continue_t continuation
,
258 /* Declare thread will wait on a particular event */
259 extern wait_result_t
assert_wait(
261 wait_interrupt_t interruptible
);
263 /* Assert that the thread intends to wait with a timeout */
264 extern wait_result_t
assert_wait_timeout(
266 wait_interrupt_t interruptible
,
268 uint32_t scale_factor
);
270 extern wait_result_t
assert_wait_deadline(
272 wait_interrupt_t interruptible
,
275 /* Wake up thread (or threads) waiting on a particular event */
276 extern kern_return_t
thread_wakeup_prim(
278 boolean_t one_thread
,
279 wait_result_t result
);
281 #define thread_wakeup(x) \
282 thread_wakeup_prim((x), FALSE, THREAD_AWAKENED)
283 #define thread_wakeup_with_result(x, z) \
284 thread_wakeup_prim((x), FALSE, (z))
285 #define thread_wakeup_one(x) \
286 thread_wakeup_prim((x), TRUE, THREAD_AWAKENED)
288 extern boolean_t
preemption_enabled(void);
290 #ifdef KERNEL_PRIVATE
293 * Obsolete interfaces.
296 extern void thread_set_timer(
298 uint32_t scale_factor
);
300 extern void thread_set_timer_deadline(
303 extern void thread_cancel_timer(void);
305 #ifndef MACH_KERNEL_PRIVATE
307 #ifndef ABSOLUTETIME_SCALAR_TYPE
309 #define thread_set_timer_deadline(a) \
310 thread_set_timer_deadline(__OSAbsoluteTime(a))
312 #endif /* ABSOLUTETIME_SCALAR_TYPE */
314 #endif /* MACH_KERNEL_PRIVATE */
316 #endif /* KERNEL_PRIVATE */
320 #endif /* _KERN_SCHED_PRIM_H_ */