/*
- * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
+ * Copyright (c) 2000-2006 Apple Computer, Inc. All rights reserved.
*
- * @APPLE_LICENSE_HEADER_START@
+ * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
*
- * The contents of this file constitute Original Code as defined in and
- * are subject to the Apple Public Source License Version 1.1 (the
- * "License"). You may not use this file except in compliance with the
- * License. Please obtain a copy of the License at
- * http://www.apple.com/publicsource and read it before using this file.
+ * This file contains Original Code and/or Modifications of Original Code
+ * as defined in and that are subject to the Apple Public Source License
+ * Version 2.0 (the 'License'). You may not use this file except in
+ * compliance with the License. The rights granted to you under the License
+ * may not be used to create, or enable the creation or redistribution of,
+ * unlawful or unlicensed copies of an Apple operating system, or to
+ * circumvent, violate, or enable the circumvention or violation of, any
+ * terms of an Apple operating system software license agreement.
*
- * This Original Code and all software distributed under the License are
- * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * Please obtain a copy of the License at
+ * http://www.opensource.apple.com/apsl/ and read it before using this file.
+ *
+ * The Original Code and all software distributed under the License are
+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
- * License for the specific language governing rights and limitations
- * under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
+ * Please see the License for the specific language governing rights and
+ * limitations under the License.
*
- * @APPLE_LICENSE_HEADER_END@
+ * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
*/
/*
* @OSF_COPYRIGHT@
#include <kern/clock.h>
#include <kern/kern_types.h>
#include <kern/thread.h>
-#include <kern/lock.h>
-#include <kern/time_out.h> /*** ??? temp - remove me soon ***/
-#include <kern/cpu_data.h>
-#include <kern/wait_queue.h>
-
-#ifdef MACH_KERNEL_PRIVATE
-
-#include <mach_ldebug.h>
-/*
- * Exported interface to sched_prim.c.
- * A few of these functions are actually defined in
- * ipc_sched.c, for historical reasons.
- */
+#include <sys/cdefs.h>
-/* Initialize scheduler module */
-extern void sched_init(void);
+#ifdef MACH_KERNEL_PRIVATE
-/*
- * Set up thread timeout element(s) when thread is created.
- */
-extern void thread_timer_setup(
- thread_t thread);
+/* Initialization */
+extern void sched_init(void) __attribute__((section("__TEXT, initcode")));
-extern void thread_timer_terminate(void);
+extern void sched_startup(void);
-#define thread_bind_locked(thread, processor) \
- (thread)->bound_processor = (processor)
+extern void sched_timebase_init(void);
-/*
- * Prevent a thread from restarting after it blocks interruptibly
- */
+/* Force a preemption point for a thread and wait for it to stop running */
extern boolean_t thread_stop(
thread_t thread);
-/*
- * wait for a thread to stop
- */
-extern boolean_t thread_wait(
+/* Release a previous stop request */
+extern void thread_unstop(
thread_t thread);
-/* Select a thread to run on a particular processor */
-extern thread_t thread_select(
- processor_t myprocessor);
+/* Wait for a thread to stop running */
+extern void thread_wait(
+ thread_t thread);
-extern void thread_go_locked(
- thread_t thread,
- int result);
+/* Unblock thread on wake up */
+extern boolean_t thread_unblock(
+ thread_t thread,
+ wait_result_t wresult);
-/* Stop old thread and run new thread */
-extern boolean_t thread_invoke(
- thread_t old_thread,
- thread_t new_thread,
- int reason,
- void (*continuation)(void));
+/* Unblock and dispatch thread */
+extern kern_return_t thread_go(
+ thread_t thread,
+ wait_result_t wresult);
-/* Called when current thread is given new stack */
-extern void thread_continue(
- thread_t old_thread);
+/* Handle threads at context switch */
+extern void thread_dispatch(
+ thread_t old_thread,
+ thread_t new_thread);
/* Switch directly to a particular thread */
-extern int thread_run(
- thread_t old_thread,
- void (*continuation)(void),
- thread_t new_thread);
+extern int thread_run(
+ thread_t self,
+ thread_continue_t continuation,
+ void *parameter,
+ thread_t new_thread);
-/* Dispatch a thread not on a run queue */
-extern void thread_dispatch(
- thread_t thread);
+/* Resume thread with new stack */
+extern void thread_continue(
+ thread_t old_thread);
/* Invoke continuation */
extern void call_continuation(
- void (*continuation)(void));
+ thread_continue_t continuation,
+ void *parameter,
+ wait_result_t wresult);
+
+/* Set the current scheduled priority */
+extern void set_sched_pri(
+ thread_t thread,
+ int priority);
-/* Compute effective priority of the specified thread */
+/* Set base priority of the specified thread */
+extern void set_priority(
+ thread_t thread,
+ int priority);
+
+/* Reset scheduled priority of thread */
extern void compute_priority(
- thread_t thread,
- int resched);
+ thread_t thread,
+ boolean_t override_depress);
-/* Version of compute_priority for current thread or
- * thread being manipuldated by scheduler.
- */
+/* Adjust scheduled priority of thread during execution */
extern void compute_my_priority(
- thread_t thread);
+ thread_t thread);
/* Periodic scheduler activity */
extern void sched_tick_thread(void);
-/* Update priority of thread that has been sleeping or suspended.
- * Used to "catch up" with the system.
- */
+/* Perform sched_tick housekeeping activities */
extern void update_priority(
- thread_t thread);
+ thread_t thread);
-/* Idle thread loop */
+/* Idle processor thread */
extern void idle_thread(void);
-/*
- * thread_sleep_interlock:
- *
- * Cause the current thread to wait until the specified event
- * occurs. The specified HW interlock is unlocked before releasing
- * the cpu. (This is a convenient way to sleep without manually
- * calling assert_wait).
- */
-
-#define thread_sleep_interlock(event, lock, interruptible) \
-MACRO_BEGIN \
- assert_wait(event, interruptible); \
- interlock_unlock(lock); \
- thread_block((void (*)(void)) 0); \
-MACRO_END
-
-/*
- * Machine-dependent code must define these functions.
- */
+extern kern_return_t idle_thread_create(
+ processor_t processor);
/* Start thread running */
extern void thread_bootstrap_return(void);
-/* Return from exception */
-extern void thread_exception_return(void);
-
/* Continuation return from syscall */
extern void thread_syscall_return(
kern_return_t ret);
-extern thread_t switch_context(
- thread_t old_thread,
- void (*continuation)(void),
- thread_t new_thread);
+/* Context switch */
+extern wait_result_t thread_block_reason(
+ thread_continue_t continuation,
+ void *parameter,
+ ast_t reason);
-/* Attach stack to thread */
-extern void machine_kernel_stack_init(
- thread_t thread,
- void (*start_pos)(thread_t));
-
-extern void load_context(
- thread_t thread);
-
-extern thread_act_t switch_act(
- thread_act_t act);
-
-extern void machine_switch_act(
- thread_t thread,
- thread_act_t old,
- thread_act_t new,
- int cpu);
+/* Reschedule thread for execution */
+extern void thread_setrun(
+ thread_t thread,
+ integer_t options);
-/*
- * These functions are either defined in kern/thread.c
- * or are defined directly by machine-dependent code.
- */
+#define SCHED_TAILQ 1
+#define SCHED_HEADQ 2
+#define SCHED_PREEMPT 4
-/* Allocate an activation stack */
-extern vm_offset_t stack_alloc(thread_t thread, void (*start_pos)(thread_t));
+/* Bind the current thread to a particular processor */
+extern processor_t thread_bind(
+ processor_t processor);
-/* Free an activation stack */
-extern void stack_free(thread_t thread);
+extern void run_queue_init(
+ run_queue_t runq);
-/* Collect excess kernel stacks */
-extern void stack_collect(void);
+extern void thread_timer_expire(
+ void *thread,
+ void *p1);
-extern void set_pri(
- thread_t thread,
- int pri,
- boolean_t resched);
+/* Set the maximum interrupt level for the thread */
+__private_extern__ wait_interrupt_t thread_interrupt_level(
+ wait_interrupt_t interruptible);
-/* Block current thread, indicating reason (Block or Quantum expiration) */
-extern int thread_block_reason(
- void (*continuation)(void),
- int reason);
+__private_extern__ wait_result_t thread_mark_wait_locked(
+ thread_t thread,
+ wait_interrupt_t interruptible);
-/* Make thread runnable */
-extern void thread_setrun(
- thread_t thread,
- boolean_t may_preempt,
- boolean_t tail);
-/*
- * Flags for thread_setrun()
- */
+/* Wake up locked thread directly, passing result */
+__private_extern__ kern_return_t clear_wait_internal(
+ thread_t thread,
+ wait_result_t result);
-#define HEAD_Q 0 /* FALSE */
-#define TAIL_Q 1 /* TRUE */
+#endif /* MACH_KERNEL_PRIVATE */
-/* Bind thread to a particular processor */
-extern void thread_bind(
- thread_t thread,
- processor_t processor);
+__BEGIN_DECLS
-extern void thread_mark_wait_locked(
- thread_t thread,
- int interruptible);
+#ifdef XNU_KERNEL_PRIVATE
-#endif /* MACH_KERNEL_PRIVATE */
+extern boolean_t assert_wait_possible(void);
/*
****************** Only exported until BSD stops using ********************
*/
-/*
- * Cancel a stop and continue the thread if necessary.
- */
-extern void thread_unstop(
- thread_t thread);
-
/* Wake up thread directly, passing result */
-extern void clear_wait(
- thread_t thread,
- int result);
-
-/* Bind thread to a particular processor */
-extern void thread_bind(
- thread_t thread,
- processor_t processor);
-
+extern kern_return_t clear_wait(
+ thread_t thread,
+ wait_result_t result);
-/*
- * ********************* PUBLIC APIs ************************************
- */
+/* Return from exception (BSD-visible interface) */
+extern void thread_exception_return(void) __dead2;
-/* Set timer for current thread */
-extern void thread_set_timer(
- natural_t interval,
- natural_t scale_factor);
-
-extern void thread_set_timer_deadline(
- AbsoluteTime deadline);
+#endif /* XNU_KERNEL_PRIVATE */
-extern void thread_cancel_timer(void);
+/* Context switch */
+extern wait_result_t thread_block(
+ thread_continue_t continuation);
-/*
- * thread_stop a thread then wait for it to stop (both of the above)
- */
-extern boolean_t thread_stop_wait(
- thread_t thread);
+extern wait_result_t thread_block_parameter(
+ thread_continue_t continuation,
+ void *parameter);
/* Declare thread will wait on a particular event */
-extern void assert_wait(
- event_t event,
- int interruptflag);
-
-/* Assert that the thread intends to wait for a timeout */
-extern void assert_wait_timeout(
- natural_t msecs,
- int interruptflags);
+extern wait_result_t assert_wait(
+ event_t event,
+ wait_interrupt_t interruptible);
+
+/* Assert that the thread intends to wait with a timeout */
+extern wait_result_t assert_wait_timeout(
+ event_t event,
+ wait_interrupt_t interruptible,
+ uint32_t interval,
+ uint32_t scale_factor);
+
+extern wait_result_t assert_wait_deadline(
+ event_t event,
+ wait_interrupt_t interruptible,
+ uint64_t deadline);
/* Wake up thread (or threads) waiting on a particular event */
-extern void thread_wakeup_prim(
- event_t event,
- boolean_t one_thread,
- int result);
-
-/* Block current thread (Block reason) */
-extern int thread_block(
- void (*continuation)(void));
-
-
-/*
- * Routines defined as macros
- */
+extern kern_return_t thread_wakeup_prim(
+ event_t event,
+ boolean_t one_thread,
+ wait_result_t result);
#define thread_wakeup(x) \
thread_wakeup_prim((x), FALSE, THREAD_AWAKENED)
#define thread_wakeup_one(x) \
thread_wakeup_prim((x), TRUE, THREAD_AWAKENED)
-/*
- * thread_sleep_mutex:
- *
- * Cause the current thread to wait until the specified event
- * occurs. The specified mutex is unlocked before releasing
- * the cpu. (This is a convenient way to sleep without manually
- * calling assert_wait).
- */
+extern boolean_t preemption_enabled(void);
-#define thread_sleep_mutex(event, lock, interruptible) \
-MACRO_BEGIN \
- assert_wait(event, interruptible); \
- mutex_unlock(lock); \
- thread_block((void (*)(void)) 0); \
-MACRO_END
+#ifdef KERNEL_PRIVATE
/*
- * thread_sleep_simple_lock:
- *
- * Cause the current thread to wait until the specified event
- * occurs. The specified simple_lock is unlocked before releasing
- * the cpu. (This is a convenient way to sleep without manually
- * calling assert_wait).
+ * Obsolete interfaces.
*/
-#define thread_sleep_simple_lock(event, lock, interruptible) \
-MACRO_BEGIN \
- assert_wait(event, interruptible); \
- simple_unlock(lock); \
- thread_block((void (*)(void)) 0); \
-MACRO_END
+extern void thread_set_timer(
+ uint32_t interval,
+ uint32_t scale_factor);
+
+extern void thread_set_timer_deadline(
+ uint64_t deadline);
+
+extern void thread_cancel_timer(void);
+
+#ifndef MACH_KERNEL_PRIVATE
+
+#ifndef ABSOLUTETIME_SCALAR_TYPE
+
+#define thread_set_timer_deadline(a) \
+ thread_set_timer_deadline(__OSAbsoluteTime(a))
+
+#endif /* ABSOLUTETIME_SCALAR_TYPE */
+
+#endif /* MACH_KERNEL_PRIVATE */
+
+#endif /* KERNEL_PRIVATE */
+__END_DECLS
#endif /* _KERN_SCHED_PRIM_H_ */