|
|
1.1 root 1: /*
2: * Mach Operating System
3: * Copyright (c) 1992,1991,1990,1989,1988,1987 Carnegie Mellon University
4: * All Rights Reserved.
5: *
6: * Permission to use, copy, modify and distribute this software and its
7: * documentation is hereby granted, provided that both the copyright
8: * notice and this permission notice appear in all copies of the
9: * software, derivative works or modified versions, and any portions
10: * thereof, and that both notices appear in supporting documentation.
11: *
12: * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
13: * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
14: * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
15: *
16: * Carnegie Mellon requests users of this software to return to
17: *
18: * Software Distribution Coordinator or [email protected]
19: * School of Computer Science
20: * Carnegie Mellon University
21: * Pittsburgh PA 15213-3890
22: *
23: * any improvements or extensions that they make and grant Carnegie Mellon
24: * the rights to redistribute these changes.
25: */
26: /*
27: * File: sched_prim.h
28: * Author: David Golub
29: *
30: * Scheduling primitive definitions file
31: *
32: */
33:
34: #ifndef _KERN_SCHED_PRIM_H_
35: #define _KERN_SCHED_PRIM_H_
36:
37: #include <mach/boolean.h>
38: #include <mach/message.h> /* for mach_msg_timeout_t */
39: #include <kern/lock.h>
40: #include <kern/kern_types.h> /* for thread_t */
41:
42: /*
43: * Possible results of assert_wait - returned in
44: * current_thread()->wait_result.
45: */
46: #define THREAD_AWAKENED 0 /* normal wakeup */
47: #define THREAD_TIMED_OUT 1 /* timeout expired */
48: #define THREAD_INTERRUPTED 2 /* interrupted by clear_wait */
49: #define THREAD_RESTART 3 /* restart operation entirely */
50:
51: typedef void *event_t; /* wait event */
52:
53: typedef void (*continuation_t)(void); /* continuation */
54:
1.1.1.4 ! root 55: #define thread_no_continuation ((continuation_t) 0) /* no continuation */
! 56:
1.1 root 57: /*
58: * Exported interface to sched_prim.c.
59: */
60:
61: extern void sched_init(void);
62:
63: extern void assert_wait(
64: event_t event,
65: boolean_t interruptible);
66: extern void clear_wait(
67: thread_t thread,
68: int result,
69: boolean_t interrupt_only);
70: extern void thread_sleep(
71: event_t event,
72: simple_lock_t lock,
73: boolean_t interruptible);
1.1.1.3 root 74: extern void thread_wakeup(void); /* for function pointers */
1.1 root 75: extern void thread_wakeup_prim(
76: event_t event,
77: boolean_t one_thread,
78: int result);
79: extern boolean_t thread_invoke(
80: thread_t old_thread,
81: continuation_t continuation,
82: thread_t new_thread);
83: extern void thread_block(
84: continuation_t continuation);
85: extern void thread_run(
86: continuation_t continuation,
87: thread_t new_thread);
88: extern void thread_set_timeout(
89: int t);
90: extern void thread_setrun(
91: thread_t thread,
92: boolean_t may_preempt);
93: extern void thread_dispatch(
94: thread_t thread);
95: extern void thread_continue(
96: thread_t old_thread);
97: extern void thread_go(
98: thread_t thread);
99: extern void thread_will_wait(
100: thread_t thread);
101: extern void thread_will_wait_with_timeout(
102: thread_t thread,
103: mach_msg_timeout_t msecs);
104: extern boolean_t thread_handoff(
105: thread_t old_thread,
106: continuation_t continuation,
107: thread_t new_thread);
1.1.1.3 root 108: extern void recompute_priorities(void *param);
1.1.1.2 root 109: extern void update_priority(
110: thread_t thread);
111: extern void compute_my_priority(
112: thread_t thread);
113: extern void thread_bind(
114: thread_t thread,
115: processor_t processor);
116: extern void compute_priority(
117: thread_t thread,
118: boolean_t resched);
119: extern void thread_timeout_setup(
1.1.1.3 root 120: thread_t thread);
1.1 root 121:
122: /*
123: * Routines defined as macros
124: */
125:
126: #define thread_wakeup(x) \
127: thread_wakeup_prim((x), FALSE, THREAD_AWAKENED)
128: #define thread_wakeup_with_result(x, z) \
129: thread_wakeup_prim((x), FALSE, (z))
130: #define thread_wakeup_one(x) \
131: thread_wakeup_prim((x), TRUE, THREAD_AWAKENED)
132:
133: /*
134: * Machine-dependent code must define these functions.
135: */
136:
1.1.1.3 root 137: extern void thread_bootstrap_return(void) __attribute__((noreturn));
138: extern void thread_exception_return(void) __attribute__((noreturn));
1.1.1.2 root 139: extern void __attribute__((__noreturn__)) thread_syscall_return(kern_return_t);
1.1.1.3 root 140:
1.1 root 141: extern thread_t switch_context(
142: thread_t old_thread,
143: continuation_t continuation,
144: thread_t new_thread);
145: extern void stack_handoff(
146: thread_t old_thread,
147: thread_t new_thread);
148:
149: /*
150: * These functions are either defined in kern/thread.c
151: * via machine-dependent stack_attach and stack_detach functions,
152: * or are defined directly by machine-dependent code.
153: */
154:
1.1.1.4 ! root 155: extern kern_return_t stack_alloc(
1.1 root 156: thread_t thread,
157: void (*resume)(thread_t));
158: extern boolean_t stack_alloc_try(
159: thread_t thread,
160: void (*resume)(thread_t));
161: extern void stack_free(
162: thread_t thread);
163:
164: /*
165: * Convert a timeout in milliseconds (mach_msg_timeout_t)
166: * to a timeout in ticks (for use by set_timeout).
167: * This conversion rounds UP so that small timeouts
168: * at least wait for one tick instead of not waiting at all.
169: */
170:
171: #define convert_ipc_timeout_to_ticks(millis) \
172: (((millis) * hz + 999) / 1000)
173:
1.1.1.3 root 174: void set_pri(thread_t th, int pri, boolean_t resched);
175: void do_thread_scan(void);
176: thread_t choose_pset_thread(processor_t myprocessor, processor_set_t pset);
177:
178: #if DEBUG
1.1.1.4 ! root 179: #include <kern/sched.h> /* for run_queue_t */
! 180:
! 181: void checkrq(run_queue_t rq, const char *msg);
1.1.1.3 root 182: void thread_check(thread_t th, run_queue_t rq);
183: #endif /* DEBUG */
184:
185: extern void idle_thread(void) __attribute__((noreturn));
186: extern void sched_thread(void);
187:
1.1 root 188: #endif /* _KERN_SCHED_PRIM_H_ */
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.