source: rtems/c/src/exec/score/include/rtems/score/thread.h @ 260b0c2

4.104.114.84.95
Last change on this file since 260b0c2 was 260b0c2, checked in by Joel Sherrill <joel.sherrill@…>, on 08/30/99 at 18:05:48

Patch from Charles-Antoine Gauthier <charles.gauthier@…> to add
support for return codes from POSIX threads that do an implicit exit
by returning from the bottom of the main function.

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