FreeBSD/Linux Kernel Cross Reference
sys/kern/sched_prim.h
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 Software.Distribution@CS.CMU.EDU
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 * HISTORY
28 * $Log: sched_prim.h,v $
29 * Revision 2.10 93/03/09 10:55:24 danner
30 * A small GNUism to signify thread_syscall_return does not return.
31 * [93/03/06 af]
32 *
33 * Revision 2.9 93/01/14 17:36:24 danner
34 * Added function prototypes.
35 * [92/11/11 dbg]
36 *
37 * Revision 2.8 92/01/03 20:14:49 dbg
38 * Removed THREAD_SHOULD_TERMINATE (again).
39 * [91/12/19 dbg]
40 *
41 * Revision 2.7 91/05/18 14:33:14 rpd
42 * Added recompute_priorities.
43 * [91/03/31 rpd]
44 *
45 * Revision 2.6 91/05/14 16:46:40 mrt
46 * Correcting copyright
47 *
48 * Revision 2.5 91/03/16 14:51:26 rpd
49 * Added declarations of new functions.
50 * [91/02/24 rpd]
51 *
52 * Revision 2.4 91/02/05 17:29:09 mrt
53 * Changed to new Mach copyright
54 * [91/02/01 16:17:24 mrt]
55 *
56 * Revision 2.3 90/06/02 14:56:03 rpd
57 * Updated to new scheduling technology.
58 * [90/03/26 22:17:10 rpd]
59 *
60 * Revision 2.2 90/01/11 11:44:04 dbg
61 * Export thread_bind.
62 * [89/12/06 dbg]
63 *
64 * Revision 2.1 89/08/03 15:53:39 rwd
65 * Created.
66 *
67 * 29-Jun-88 David Golub (dbg) at Carnegie-Mellon University
68 * Removed THREAD_SHOULD_TERMINATE.
69 *
70 * 16-May-88 Michael Young (mwyoung) at Carnegie-Mellon University
71 * Added thread_wakeup_with_result routine; thread_wakeup
72 * is a special case.
73 *
74 * 16-Apr-88 Michael Young (mwyoung) at Carnegie-Mellon University
75 * Added THREAD_RESTART wait result value.
76 *
77 * 29-Feb-88 David Black (dlb) at Carnegie-Mellon University
78 * thread_setrun is now a real routine.
79 *
80 * 13-Oct-87 David Golub (dbg) at Carnegie-Mellon University
81 * Moved thread_will_wait and thread_go to sched_prim_macros.h,
82 * to avoid including thread.h everywhere.
83 *
84 * 5-Oct-87 David Golub (dbg) at Carnegie-Mellon University
85 * Created. Moved thread_will_wait and thread_go here from
86 * mach_ipc.
87 */
88 /*
89 * File: sched_prim.h
90 * Author: David Golub
91 *
92 * Scheduling primitive definitions file
93 *
94 */
95
96 #ifndef _KERN_SCHED_PRIM_H_
97 #define _KERN_SCHED_PRIM_H_
98
99 #include <mach/boolean.h>
100 #include <mach/message.h> /* for mach_msg_timeout_t */
101 #include <kern/lock.h>
102 #include <kern/kern_types.h> /* for thread_t */
103
104 /*
105 * Possible results of assert_wait - returned in
106 * current_thread()->wait_result.
107 */
108 #define THREAD_AWAKENED 0 /* normal wakeup */
109 #define THREAD_TIMED_OUT 1 /* timeout expired */
110 #define THREAD_INTERRUPTED 2 /* interrupted by clear_wait */
111 #define THREAD_RESTART 3 /* restart operation entirely */
112
113 typedef void *event_t; /* wait event */
114
115 typedef void (*continuation_t)(void); /* continuation */
116
117 /*
118 * Exported interface to sched_prim.c.
119 */
120
121 extern void sched_init(void);
122
123 extern void assert_wait(
124 event_t event,
125 boolean_t interruptible);
126 extern void clear_wait(
127 thread_t thread,
128 int result,
129 boolean_t interrupt_only);
130 extern void thread_sleep(
131 event_t event,
132 simple_lock_t lock,
133 boolean_t interruptible);
134 extern void thread_wakeup(); /* for function pointers */
135 extern void thread_wakeup_prim(
136 event_t event,
137 boolean_t one_thread,
138 int result);
139 extern boolean_t thread_invoke(
140 thread_t old_thread,
141 continuation_t continuation,
142 thread_t new_thread);
143 extern void thread_block(
144 continuation_t continuation);
145 extern void thread_run(
146 continuation_t continuation,
147 thread_t new_thread);
148 extern void thread_set_timeout(
149 int t);
150 extern void thread_setrun(
151 thread_t thread,
152 boolean_t may_preempt);
153 extern void thread_dispatch(
154 thread_t thread);
155 extern void thread_continue(
156 thread_t old_thread);
157 extern void thread_go(
158 thread_t thread);
159 extern void thread_will_wait(
160 thread_t thread);
161 extern void thread_will_wait_with_timeout(
162 thread_t thread,
163 mach_msg_timeout_t msecs);
164 extern boolean_t thread_handoff(
165 thread_t old_thread,
166 continuation_t continuation,
167 thread_t new_thread);
168 extern void recompute_priorities();
169
170 /*
171 * Routines defined as macros
172 */
173
174 #define thread_wakeup(x) \
175 thread_wakeup_prim((x), FALSE, THREAD_AWAKENED)
176 #define thread_wakeup_with_result(x, z) \
177 thread_wakeup_prim((x), FALSE, (z))
178 #define thread_wakeup_one(x) \
179 thread_wakeup_prim((x), TRUE, THREAD_AWAKENED)
180
181 /*
182 * Machine-dependent code must define these functions.
183 */
184
185 extern void thread_bootstrap_return(void);
186 extern void thread_exception_return(void);
187 #ifdef __GNUC__
188 extern void __volatile__ thread_syscall_return(kern_return_t);
189 #else
190 extern void thread_syscall_return(kern_return_t);
191 #endif
192 extern thread_t switch_context(
193 thread_t old_thread,
194 continuation_t continuation,
195 thread_t new_thread);
196 extern void stack_handoff(
197 thread_t old_thread,
198 thread_t new_thread);
199
200 /*
201 * These functions are either defined in kern/thread.c
202 * via machine-dependent stack_attach and stack_detach functions,
203 * or are defined directly by machine-dependent code.
204 */
205
206 extern void stack_alloc(
207 thread_t thread,
208 void (*resume)(thread_t));
209 extern boolean_t stack_alloc_try(
210 thread_t thread,
211 void (*resume)(thread_t));
212 extern void stack_free(
213 thread_t thread);
214
215 /*
216 * Convert a timeout in milliseconds (mach_msg_timeout_t)
217 * to a timeout in ticks (for use by set_timeout).
218 * This conversion rounds UP so that small timeouts
219 * at least wait for one tick instead of not waiting at all.
220 */
221
222 #define convert_ipc_timeout_to_ticks(millis) \
223 (((millis) * hz + 999) / 1000)
224
225 #endif /* _KERN_SCHED_PRIM_H_ */
Cache object: d4f33f2ebd062abf8b5f0ae8de68a9f0
|