source: rtems/cpukit/score/include/rtems/score/thread.h @ 08311cc3

4.104.114.84.95
Last change on this file since 08311cc3 was 08311cc3, checked in by Joel Sherrill <joel.sherrill@…>, on 11/17/99 at 17:51:34

Updated copyright notice.

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