1 | /* thread.h |
---|
2 | * |
---|
3 | * This include file contains all constants and structures associated |
---|
4 | * with the thread control block. |
---|
5 | * |
---|
6 | * COPYRIGHT (c) 1989, 1990, 1991, 1992, 1993, 1994. |
---|
7 | * On-Line Applications Research Corporation (OAR). |
---|
8 | * All rights assigned to U.S. Government, 1994. |
---|
9 | * |
---|
10 | * This material may be reproduced by or for the U.S. Government pursuant |
---|
11 | * to the copyright license under the clause at DFARS 252.227-7013. This |
---|
12 | * notice must appear in all copies of this file and its derivatives. |
---|
13 | * |
---|
14 | * $Id$ |
---|
15 | */ |
---|
16 | |
---|
17 | #ifndef __THREAD_h |
---|
18 | #define __THREAD_h |
---|
19 | |
---|
20 | #ifdef __cplusplus |
---|
21 | extern "C" { |
---|
22 | #endif |
---|
23 | |
---|
24 | #include <rtems/score/context.h> |
---|
25 | #include <rtems/score/cpu.h> |
---|
26 | #include <rtems/score/mppkt.h> |
---|
27 | #include <rtems/score/object.h> |
---|
28 | #include <rtems/score/priority.h> |
---|
29 | #include <rtems/score/stack.h> |
---|
30 | #include <rtems/score/states.h> |
---|
31 | #include <rtems/score/tod.h> |
---|
32 | #include <rtems/score/tqdata.h> |
---|
33 | #include <rtems/score/watchdog.h> |
---|
34 | |
---|
35 | /* |
---|
36 | * The following defines the "return type" of a thread. |
---|
37 | */ |
---|
38 | |
---|
39 | typedef void Thread; |
---|
40 | |
---|
41 | /* |
---|
42 | * The following defines the ways in which the entry point for a |
---|
43 | * thread can be invoked. Basically, it can be passed any |
---|
44 | * combination/permutation of a pointer and an unsigned32 value. |
---|
45 | * |
---|
46 | * NOTE: For now, we are ignoring the return type. |
---|
47 | */ |
---|
48 | |
---|
49 | typedef enum { |
---|
50 | THREAD_START_NUMERIC, |
---|
51 | THREAD_START_POINTER, |
---|
52 | THREAD_START_BOTH_POINTER_FIRST, |
---|
53 | THREAD_START_BOTH_NUMERIC_FIRST |
---|
54 | } Thread_Start_types; |
---|
55 | |
---|
56 | typedef Thread ( *Thread_Entry )( ); |
---|
57 | |
---|
58 | /* |
---|
59 | * The following structure contains the information which defines |
---|
60 | * the starting state of a thread. |
---|
61 | */ |
---|
62 | |
---|
63 | typedef struct { |
---|
64 | Thread_Entry entry_point; /* starting thread address */ |
---|
65 | Thread_Start_types prototype; /* how task is invoked */ |
---|
66 | void *pointer_argument; /* pointer argument */ |
---|
67 | unsigned32 numeric_argument; /* numeric argument */ |
---|
68 | /* initial execution modes */ |
---|
69 | boolean is_preemptible; |
---|
70 | boolean is_timeslice; |
---|
71 | unsigned32 isr_level; |
---|
72 | Priority_Control initial_priority; /* initial priority */ |
---|
73 | Stack_Control Initial_stack; /* stack information */ |
---|
74 | void *fp_context; /* initial FP context area address */ |
---|
75 | void *stack; /* initial FP context area address */ |
---|
76 | } Thread_Start_information; |
---|
77 | |
---|
78 | /* |
---|
79 | * The following structure contains the information necessary to manage |
---|
80 | * a thread which it is waiting for a resource. |
---|
81 | */ |
---|
82 | |
---|
83 | #define THREAD_STATUS_PROXY_BLOCKING 0x1111111 |
---|
84 | |
---|
85 | typedef struct { |
---|
86 | Objects_Id id; /* waiting on this object */ |
---|
87 | unsigned32 count; /* "generic" fields to be used */ |
---|
88 | void *return_argument; /* when blocking */ |
---|
89 | void *return_argument_1; |
---|
90 | unsigned32 option; |
---|
91 | |
---|
92 | /* |
---|
93 | * NOTE: The following assumes that all API return codes can be |
---|
94 | * treated as an unsigned32. |
---|
95 | */ |
---|
96 | unsigned32 return_code; /* status for thread awakened */ |
---|
97 | |
---|
98 | Chain_Control Block2n; /* 2 - n priority blocked chain */ |
---|
99 | Thread_queue_Control *queue; /* pointer to thread queue */ |
---|
100 | } Thread_Wait_information; |
---|
101 | |
---|
102 | /* |
---|
103 | * The following defines the control block used to manage |
---|
104 | * each thread proxy. |
---|
105 | * |
---|
106 | * NOTE: It is critical that proxies and threads have identical |
---|
107 | * memory images for the shared part. |
---|
108 | */ |
---|
109 | |
---|
110 | typedef struct { |
---|
111 | Objects_Control Object; |
---|
112 | States_Control current_state; |
---|
113 | Priority_Control current_priority; |
---|
114 | Priority_Control real_priority; |
---|
115 | unsigned32 resource_count; |
---|
116 | Thread_Wait_information Wait; |
---|
117 | Watchdog_Control Timer; |
---|
118 | MP_packet_Prefix *receive_packet; |
---|
119 | /****************** end of common block ********************/ |
---|
120 | Chain_Node Active; |
---|
121 | } Thread_Proxy_control; |
---|
122 | |
---|
123 | |
---|
124 | /* |
---|
125 | * The following record defines the control block used |
---|
126 | * to manage each thread. |
---|
127 | * |
---|
128 | * NOTE: It is critical that proxies and threads have identical |
---|
129 | * memory images for the shared part. |
---|
130 | */ |
---|
131 | |
---|
132 | typedef enum { |
---|
133 | THREAD_API_RTEMS, |
---|
134 | THREAD_API_POSIX |
---|
135 | } Thread_APIs; |
---|
136 | |
---|
137 | #define THREAD_API_FIRST THREAD_API_RTEMS |
---|
138 | #define THREAD_API_LAST THREAD_API_POSIX |
---|
139 | |
---|
140 | typedef struct { |
---|
141 | Objects_Control Object; |
---|
142 | States_Control current_state; |
---|
143 | Priority_Control current_priority; |
---|
144 | Priority_Control real_priority; |
---|
145 | unsigned32 resource_count; |
---|
146 | Thread_Wait_information Wait; |
---|
147 | Watchdog_Control Timer; |
---|
148 | MP_packet_Prefix *receive_packet; |
---|
149 | /****************** end of common block ********************/ |
---|
150 | boolean is_global; |
---|
151 | boolean do_post_task_switch_extension; |
---|
152 | Chain_Control *ready; |
---|
153 | Priority_Information Priority_map; |
---|
154 | Thread_Start_information Start; |
---|
155 | boolean is_preemptible; |
---|
156 | boolean is_timeslice; |
---|
157 | Context_Control Registers; |
---|
158 | void *fp_context; |
---|
159 | void *API_Extensions[ THREAD_API_LAST + 1 ]; |
---|
160 | void **extensions; |
---|
161 | } Thread_Control; |
---|
162 | |
---|
163 | /* |
---|
164 | * The following constants define the stack size requirements for |
---|
165 | * the idle thread. |
---|
166 | */ |
---|
167 | |
---|
168 | |
---|
169 | #define THREAD_IDLE_STACK_SIZE STACK_MINIMUM_SIZE |
---|
170 | |
---|
171 | /* |
---|
172 | * The following defines the information control block used to |
---|
173 | * manage this class of objects. |
---|
174 | */ |
---|
175 | |
---|
176 | SCORE_EXTERN Objects_Information _Thread_Internal_information; |
---|
177 | |
---|
178 | /* |
---|
179 | * The following define the thread control pointers used to access |
---|
180 | * and manipulate the idle thread. |
---|
181 | */ |
---|
182 | |
---|
183 | SCORE_EXTERN Thread_Control *_Thread_Idle; |
---|
184 | |
---|
185 | /* |
---|
186 | * The following context area contains the context of the "thread" |
---|
187 | * which invoked the start multitasking routine. This context is |
---|
188 | * restored as the last action of the stop multitasking routine. Thus |
---|
189 | * control of the processor can be returned to the environment |
---|
190 | * which initiated the system. |
---|
191 | */ |
---|
192 | |
---|
193 | SCORE_EXTERN Context_Control _Thread_BSP_context; |
---|
194 | |
---|
195 | /* |
---|
196 | * The following declares the dispatch critical section nesting |
---|
197 | * counter which is used to prevent context switches at inopportune |
---|
198 | * moments. |
---|
199 | */ |
---|
200 | |
---|
201 | SCORE_EXTERN unsigned32 _Thread_Dispatch_disable_level; |
---|
202 | |
---|
203 | /* |
---|
204 | * The following holds how many user extensions are in the system. This |
---|
205 | * is used to determine how many user extension data areas to allocate |
---|
206 | * per thread. |
---|
207 | */ |
---|
208 | |
---|
209 | SCORE_EXTERN unsigned32 _Thread_Maximum_extensions; |
---|
210 | |
---|
211 | /* |
---|
212 | * The following data items are used to manage timeslicing. |
---|
213 | */ |
---|
214 | |
---|
215 | SCORE_EXTERN unsigned32 _Thread_Ticks_remaining_in_timeslice; |
---|
216 | SCORE_EXTERN unsigned32 _Thread_Ticks_per_timeslice; |
---|
217 | |
---|
218 | /* |
---|
219 | * The following points to the array of FIFOs used to manage the |
---|
220 | * set of ready threads. |
---|
221 | */ |
---|
222 | |
---|
223 | SCORE_EXTERN Chain_Control *_Thread_Ready_chain; |
---|
224 | |
---|
225 | /* |
---|
226 | * The following points to the thread which is currently executing. |
---|
227 | * This thread is implicitly manipulated by numerous directives. |
---|
228 | */ |
---|
229 | |
---|
230 | SCORE_EXTERN Thread_Control *_Thread_Executing; |
---|
231 | |
---|
232 | /* |
---|
233 | * The following points to the highest priority ready thread |
---|
234 | * in the system. Unless the current thread is not preemptibl, |
---|
235 | * then this thread will be context switched to when the next |
---|
236 | * dispatch occurs. |
---|
237 | */ |
---|
238 | |
---|
239 | SCORE_EXTERN Thread_Control *_Thread_Heir; |
---|
240 | |
---|
241 | /* |
---|
242 | * The following points to the thread whose floating point |
---|
243 | * context is currently loaded. |
---|
244 | */ |
---|
245 | |
---|
246 | SCORE_EXTERN Thread_Control *_Thread_Allocated_fp; |
---|
247 | |
---|
248 | /* |
---|
249 | * _Thread_Handler_initialization |
---|
250 | * |
---|
251 | * DESCRIPTION: |
---|
252 | * |
---|
253 | * This routine performs the initialization necessary for this handler. |
---|
254 | */ |
---|
255 | |
---|
256 | void _Thread_Handler_initialization ( |
---|
257 | unsigned32 ticks_per_timeslice, |
---|
258 | unsigned32 maximum_extensions, |
---|
259 | unsigned32 maximum_proxies |
---|
260 | ); |
---|
261 | |
---|
262 | /* |
---|
263 | * _Thread_Create_idle |
---|
264 | * |
---|
265 | * DESCRIPTION: |
---|
266 | * |
---|
267 | * This routine creates the idle thread. |
---|
268 | * |
---|
269 | * WARNING!! No thread should be created before this one. |
---|
270 | */ |
---|
271 | |
---|
272 | void _Thread_Create_idle( void ); |
---|
273 | |
---|
274 | /* |
---|
275 | * _Thread_Start_multitasking |
---|
276 | * |
---|
277 | * DESCRIPTION: |
---|
278 | * |
---|
279 | * This routine initiates multitasking. It is invoked only as |
---|
280 | * part of initialization and its invocation is the last act of |
---|
281 | * the non-multitasking part of the system initialization. |
---|
282 | */ |
---|
283 | |
---|
284 | void _Thread_Start_multitasking( void ); |
---|
285 | |
---|
286 | /* |
---|
287 | * _Thread_Dispatch |
---|
288 | * |
---|
289 | * DESCRIPTION: |
---|
290 | * |
---|
291 | * This routine is responsible for transferring control of the |
---|
292 | * processor from the executing thread to the heir thread. As part |
---|
293 | * of this process, it is responsible for the following actions: |
---|
294 | * |
---|
295 | * + saving the context of the executing thread |
---|
296 | * + restoring the context of the heir thread |
---|
297 | * + dispatching any signals for the resulting executing thread |
---|
298 | */ |
---|
299 | |
---|
300 | void _Thread_Dispatch( void ); |
---|
301 | |
---|
302 | /* |
---|
303 | * _Thread_Initialize |
---|
304 | * |
---|
305 | * DESCRIPTION: |
---|
306 | * |
---|
307 | * XXX |
---|
308 | */ |
---|
309 | |
---|
310 | boolean _Thread_Initialize( |
---|
311 | Objects_Information *information, |
---|
312 | Thread_Control *the_thread, |
---|
313 | void *stack_area, /* NULL if to be allocated */ |
---|
314 | unsigned32 stack_size, /* insure it is >= min */ |
---|
315 | boolean is_fp, /* TRUE if thread uses FP */ |
---|
316 | Priority_Control priority, |
---|
317 | boolean is_preemptible, |
---|
318 | boolean is_timeslice, |
---|
319 | unsigned32 isr_level, |
---|
320 | Objects_Name name |
---|
321 | |
---|
322 | ); |
---|
323 | |
---|
324 | /* |
---|
325 | * _Thread_Start |
---|
326 | * |
---|
327 | * DESCRIPTION: |
---|
328 | * |
---|
329 | * XXX |
---|
330 | */ |
---|
331 | |
---|
332 | boolean _Thread_Start( |
---|
333 | Thread_Control *the_thread, |
---|
334 | Thread_Start_types the_prototype, |
---|
335 | void *entry_point, |
---|
336 | void *pointer_argument, |
---|
337 | unsigned32 numeric_argument |
---|
338 | ); |
---|
339 | |
---|
340 | /* |
---|
341 | * _Thread_Restart |
---|
342 | * |
---|
343 | * DESCRIPTION: |
---|
344 | * |
---|
345 | * XXX |
---|
346 | */ |
---|
347 | |
---|
348 | /* XXX multiple task arg profiles */ |
---|
349 | |
---|
350 | boolean _Thread_Restart( |
---|
351 | Thread_Control *the_thread, |
---|
352 | void *pointer_argument, |
---|
353 | unsigned32 numeric_argument |
---|
354 | ); |
---|
355 | |
---|
356 | /* |
---|
357 | * _Thread_Close |
---|
358 | * |
---|
359 | * DESCRIPTION: |
---|
360 | * |
---|
361 | * XXX |
---|
362 | */ |
---|
363 | |
---|
364 | void _Thread_Close( |
---|
365 | Objects_Information *information, |
---|
366 | Thread_Control *the_thread |
---|
367 | ); |
---|
368 | |
---|
369 | /* |
---|
370 | * _Thread_Ready |
---|
371 | * |
---|
372 | * DESCRIPTION: |
---|
373 | * |
---|
374 | * This routine removes any set states for the_thread. It performs |
---|
375 | * any necessary scheduling operations including the selection of |
---|
376 | * a new heir thread. |
---|
377 | */ |
---|
378 | |
---|
379 | void _Thread_Ready( |
---|
380 | Thread_Control *the_thread |
---|
381 | ); |
---|
382 | |
---|
383 | /* |
---|
384 | * _Thread_Clear_state |
---|
385 | * |
---|
386 | * DESCRIPTION: |
---|
387 | * |
---|
388 | * This routine clears the indicated STATES for the_thread. It performs |
---|
389 | * any necessary scheduling operations including the selection of |
---|
390 | * a new heir thread. |
---|
391 | */ |
---|
392 | |
---|
393 | void _Thread_Clear_state( |
---|
394 | Thread_Control *the_thread, |
---|
395 | States_Control state |
---|
396 | ); |
---|
397 | |
---|
398 | /* |
---|
399 | * _Thread_Set_state |
---|
400 | * |
---|
401 | * DESCRIPTION: |
---|
402 | * |
---|
403 | * This routine sets the indicated states for the_thread. It performs |
---|
404 | * any necessary scheduling operations including the selection of |
---|
405 | * a new heir thread. |
---|
406 | * |
---|
407 | */ |
---|
408 | |
---|
409 | void _Thread_Set_state( |
---|
410 | Thread_Control *the_thread, |
---|
411 | States_Control state |
---|
412 | ); |
---|
413 | |
---|
414 | /* |
---|
415 | * _Thread_Set_transient |
---|
416 | * |
---|
417 | * DESCRIPTION: |
---|
418 | * |
---|
419 | * This routine sets the TRANSIENT state for the_thread. It performs |
---|
420 | * any necessary scheduling operations including the selection of |
---|
421 | * a new heir thread. |
---|
422 | */ |
---|
423 | |
---|
424 | void _Thread_Set_transient( |
---|
425 | Thread_Control *the_thread |
---|
426 | ); |
---|
427 | |
---|
428 | /* |
---|
429 | * _Thread_Reset_timeslice |
---|
430 | * |
---|
431 | * DESCRIPTION: |
---|
432 | * |
---|
433 | * This routine is invoked upon expiration of the currently |
---|
434 | * executing thread's timeslice. If no other thread's are ready |
---|
435 | * at the priority of the currently executing thread, then the |
---|
436 | * executing thread's timeslice is reset. Otherwise, the |
---|
437 | * currently executing thread is placed at the rear of the |
---|
438 | * FIFO for this priority and a new heir is selected. |
---|
439 | */ |
---|
440 | |
---|
441 | void _Thread_Reset_timeslice( void ); |
---|
442 | |
---|
443 | /* |
---|
444 | * _Thread_Tickle_timeslice |
---|
445 | * |
---|
446 | * DESCRIPTION: |
---|
447 | * |
---|
448 | * This routine is invoked as part of processing each clock tick. |
---|
449 | * It is responsible for determining if the current thread allows |
---|
450 | * timeslicing and, if so, when its timeslice expires. |
---|
451 | */ |
---|
452 | |
---|
453 | void _Thread_Tickle_timeslice( void ); |
---|
454 | |
---|
455 | /* |
---|
456 | * _Thread_Yield_processor |
---|
457 | * |
---|
458 | * DESCRIPTION: |
---|
459 | * |
---|
460 | * This routine is invoked when a thread wishes to voluntarily |
---|
461 | * transfer control of the processor to another thread of equal |
---|
462 | * or greater priority. |
---|
463 | */ |
---|
464 | |
---|
465 | void _Thread_Yield_processor( void ); |
---|
466 | |
---|
467 | /* |
---|
468 | * _Thread_Load_environment |
---|
469 | * |
---|
470 | * DESCRIPTION: |
---|
471 | * |
---|
472 | * This routine initializes the context of the_thread to its |
---|
473 | * appropriate starting state. |
---|
474 | */ |
---|
475 | |
---|
476 | void _Thread_Load_environment( |
---|
477 | Thread_Control *the_thread |
---|
478 | ); |
---|
479 | |
---|
480 | /* |
---|
481 | * _Thread_Handler |
---|
482 | * |
---|
483 | * DESCRIPTION: |
---|
484 | * |
---|
485 | * This routine is the wrapper function for all threads. It is |
---|
486 | * the starting point for all threads. The user provided thread |
---|
487 | * entry point is invoked by this routine. Operations |
---|
488 | * which must be performed immediately before and after the user's |
---|
489 | * thread executes are found here. |
---|
490 | */ |
---|
491 | |
---|
492 | void _Thread_Handler( void ); |
---|
493 | |
---|
494 | /* |
---|
495 | * _Thread_Delay_ended |
---|
496 | * |
---|
497 | * DESCRIPTION: |
---|
498 | * |
---|
499 | * This routine is invoked when a thread must be unblocked at the |
---|
500 | * end of a time based delay (i.e. wake after or wake when). |
---|
501 | */ |
---|
502 | |
---|
503 | void _Thread_Delay_ended( |
---|
504 | Objects_Id id, |
---|
505 | void *ignored |
---|
506 | ); |
---|
507 | |
---|
508 | /* |
---|
509 | * _Thread_Change_priority |
---|
510 | * |
---|
511 | * DESCRIPTION: |
---|
512 | * |
---|
513 | * This routine changes the current priority of the_thread to |
---|
514 | * new_priority. It performs any necessary scheduling operations |
---|
515 | * including the selection of a new heir thread. |
---|
516 | */ |
---|
517 | |
---|
518 | void _Thread_Change_priority ( |
---|
519 | Thread_Control *the_thread, |
---|
520 | Priority_Control new_priority |
---|
521 | ); |
---|
522 | |
---|
523 | /* |
---|
524 | * _Thread_Set_priority |
---|
525 | * |
---|
526 | * DESCRIPTION: |
---|
527 | * |
---|
528 | * This routine updates the priority related fields in the_thread |
---|
529 | * control block to indicate the current priority is now new_priority. |
---|
530 | */ |
---|
531 | |
---|
532 | void _Thread_Set_priority( |
---|
533 | Thread_Control *the_thread, |
---|
534 | Priority_Control new_priority |
---|
535 | ); |
---|
536 | |
---|
537 | /* |
---|
538 | * _Thread_Evaluate_mode |
---|
539 | * |
---|
540 | * DESCRIPTION: |
---|
541 | * |
---|
542 | * This routine XXX |
---|
543 | */ |
---|
544 | |
---|
545 | boolean _Thread_Evaluate_mode( void ); |
---|
546 | |
---|
547 | /* |
---|
548 | * _Thread_Get |
---|
549 | * |
---|
550 | * NOTE: If we are not using static inlines, this must be a real |
---|
551 | * subroutine call. |
---|
552 | */ |
---|
553 | |
---|
554 | #ifndef USE_INLINES |
---|
555 | Thread_Control *_Thread_Get ( |
---|
556 | Objects_Id id, |
---|
557 | Objects_Locations *location |
---|
558 | ); |
---|
559 | #endif |
---|
560 | |
---|
561 | /* |
---|
562 | * _Thread_Idle_body |
---|
563 | * |
---|
564 | * DESCRIPTION: |
---|
565 | * |
---|
566 | * This routine is the body of the system idle thread. |
---|
567 | */ |
---|
568 | |
---|
569 | #if (CPU_PROVIDES_IDLE_THREAD_BODY == FALSE) |
---|
570 | Thread _Thread_Idle_body( |
---|
571 | unsigned32 ignored |
---|
572 | ); |
---|
573 | #endif |
---|
574 | |
---|
575 | #ifndef __RTEMS_APPLICATION__ |
---|
576 | #include <rtems/score/thread.inl> |
---|
577 | #endif |
---|
578 | #include <rtems/score/threadmp.h> |
---|
579 | |
---|
580 | #ifdef __cplusplus |
---|
581 | } |
---|
582 | #endif |
---|
583 | |
---|
584 | #endif |
---|
585 | /* end of include file */ |
---|