source: rtems/cpukit/score/include/rtems/score/thread.h @ f6d0821

4.104.114.84.95
Last change on this file since f6d0821 was f6d0821, checked in by Joel Sherrill <joel.sherrill@…>, on 11/16/99 at 16:07:52

Added prototype for _Thread_Reset() and numerous comments.

  • Property mode set to 100644
File size: 18.8 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_API_ITRON
171}  Thread_APIs;
172
173#define THREAD_API_FIRST THREAD_API_RTEMS
174#define THREAD_API_LAST  THREAD_API_ITRON
175
176struct Thread_Control_struct {
177  Objects_Control                       Object;
178  States_Control                        current_state;
179  Priority_Control                      current_priority;
180  Priority_Control                      real_priority;
181  unsigned32                            resource_count;
182  Thread_Wait_information               Wait;
183  Watchdog_Control                      Timer;
184#if defined(RTEMS_MULTIPROCESSING)
185  MP_packet_Prefix                     *receive_packet;
186#endif
187     /****************** end of common block ********************/
188  unsigned32                            suspend_count;
189  boolean                               is_global;
190  boolean                               do_post_task_switch_extension;
191
192  boolean                               is_preemptible;
193  void                                 *rtems_ada_self;
194  unsigned32                            cpu_time_budget;
195  Thread_CPU_budget_algorithms          budget_algorithm;
196  Thread_CPU_budget_algorithm_callout   budget_callout;
197
198  unsigned32                            ticks_executed;
199  Chain_Control                        *ready;
200  Priority_Information                  Priority_map;
201  Thread_Start_information              Start;
202  Context_Control                       Registers;
203  void                                 *fp_context;
204  void                                 *API_Extensions[ THREAD_API_LAST + 1 ];
205  void                                **extensions;
206};
207
208/*
209 *  Self for the GNU Ada Run-Time
210 */
211
212SCORE_EXTERN void *rtems_ada_self;
213 
214/*
215 *  The following defines the information control block used to
216 *  manage this class of objects.
217 */
218 
219SCORE_EXTERN Objects_Information _Thread_Internal_information;
220 
221/*
222 *  The following define the thread control pointers used to access
223 *  and manipulate the idle thread.
224 */
225 
226SCORE_EXTERN Thread_Control *_Thread_Idle;
227
228/*
229 *  The following context area contains the context of the "thread"
230 *  which invoked the start multitasking routine.  This context is
231 *  restored as the last action of the stop multitasking routine.  Thus
232 *  control of the processor can be returned to the environment
233 *  which initiated the system.
234 */
235 
236SCORE_EXTERN Context_Control _Thread_BSP_context;
237 
238/*
239 *  The following declares the dispatch critical section nesting
240 *  counter which is used to prevent context switches at inopportune
241 *  moments.
242 */
243
244SCORE_EXTERN volatile unsigned32 _Thread_Dispatch_disable_level;
245
246/*
247 *  If this is non-zero, then the post-task switch extension
248 *  is run regardless of the state of the per thread flag.
249 */
250
251SCORE_EXTERN unsigned32 _Thread_Do_post_task_switch_extension;
252
253/*
254 *  The following holds how many user extensions are in the system.  This
255 *  is used to determine how many user extension data areas to allocate
256 *  per thread.
257 */
258
259SCORE_EXTERN unsigned32 _Thread_Maximum_extensions;
260
261/*
262 *  The following is used to manage the length of a timeslice quantum.
263 */
264
265SCORE_EXTERN unsigned32 _Thread_Ticks_per_timeslice;
266
267/*
268 *  The following points to the array of FIFOs used to manage the
269 *  set of ready threads.
270 */
271
272SCORE_EXTERN Chain_Control *_Thread_Ready_chain;
273
274/*
275 *  The following points to the thread which is currently executing.
276 *  This thread is implicitly manipulated by numerous directives.
277 */
278
279SCORE_EXTERN Thread_Control *_Thread_Executing;
280
281/*
282 *  The following points to the highest priority ready thread
283 *  in the system.  Unless the current thread is not preemptibl,
284 *  then this thread will be context switched to when the next
285 *  dispatch occurs.
286 */
287
288SCORE_EXTERN Thread_Control *_Thread_Heir;
289
290/*
291 *  The following points to the thread whose floating point
292 *  context is currently loaded.
293 */
294
295SCORE_EXTERN Thread_Control *_Thread_Allocated_fp;
296
297/*
298 *  _Thread_Handler_initialization
299 *
300 *  DESCRIPTION:
301 *
302 *  This routine performs the initialization necessary for this handler.
303 */
304
305void _Thread_Handler_initialization (
306  unsigned32   ticks_per_timeslice,
307  unsigned32   maximum_extensions,
308  unsigned32   maximum_proxies
309);
310
311/*
312 *  _Thread_Create_idle
313 *
314 *  DESCRIPTION:
315 *
316 *  This routine creates the idle thread.
317 *
318 *  WARNING!! No thread should be created before this one.
319 */
320 
321void _Thread_Create_idle( void );
322
323/*
324 *  _Thread_Start_multitasking
325 *
326 *  DESCRIPTION:
327 *
328 *  This routine initiates multitasking.  It is invoked only as
329 *  part of initialization and its invocation is the last act of
330 *  the non-multitasking part of the system initialization.
331 */
332
333void _Thread_Start_multitasking( void );
334
335/*
336 *  _Thread_Dispatch
337 *
338 *  DESCRIPTION:
339 *
340 *  This routine is responsible for transferring control of the
341 *  processor from the executing thread to the heir thread.  As part
342 *  of this process, it is responsible for the following actions:
343 *
344 *     + saving the context of the executing thread
345 *     + restoring the context of the heir thread
346 *     + dispatching any signals for the resulting executing thread
347 */
348
349void _Thread_Dispatch( void );
350
351/*
352 *  _Thread_Stack_Allocate
353 * 
354 *  DESCRIPTION:
355 *
356 *  Allocate the requested stack space for the thread.
357 *  return the actual size allocated after any adjustment
358 *  or return zero if the allocation failed.
359 *  Set the Start.stack field to the address of the stack
360 *
361 *  NOTES: NONE
362 *
363 */
364
365unsigned32 _Thread_Stack_Allocate(
366  Thread_Control *the_thread,
367  unsigned32 stack_size
368);
369
370/*
371 *  _Thread_Stack_Free
372 *
373 *  DESCRIPTION:
374 *
375 *  Deallocate the Thread's stack.
376 *  NOTES: NONE
377 *
378 */
379
380void _Thread_Stack_Free(
381  Thread_Control *the_thread
382);
383
384/*
385 *  _Thread_Initialize
386 *
387 *  DESCRIPTION:
388 *
389 *  This routine initializes the specified the thread.  It allocates
390 *  all memory associated with this thread.  It completes by adding
391 *  the thread to the local object table so operations on this
392 *  thread id are allowed.
393 *
394 *  NOTES:
395 *
396 *  If stack_area is NULL, it is allocated from the workspace.
397 *
398 *  If the stack is allocated from the workspace, then it is guaranteed to be
399 *  of at least minimum size.
400 */
401
402boolean _Thread_Initialize(
403  Objects_Information                  *information,
404  Thread_Control                       *the_thread,
405  void                                 *stack_area,
406  unsigned32                            stack_size,
407  boolean                               is_fp,
408  Priority_Control                      priority,
409  boolean                               is_preemptible,
410  Thread_CPU_budget_algorithms          budget_algorithm,
411  Thread_CPU_budget_algorithm_callout   budget_callout,
412  unsigned32                            isr_level,
413  Objects_Name                          name
414);
415
416/*
417 *  _Thread_Start
418 *
419 *  DESCRIPTION:
420 *
421 *  This routine initializes the executable information for a thread
422 *  and makes it ready to execute.  After this routine executes, the
423 *  thread competes with all other threads for CPU time.
424 */
425 
426boolean _Thread_Start(
427  Thread_Control           *the_thread,
428  Thread_Start_types        the_prototype,
429  void                     *entry_point,
430  void                     *pointer_argument,
431  unsigned32                numeric_argument
432);
433
434/*
435 *  _Thread_Restart
436 *
437 *  DESCRIPTION:
438 *
439 *  This support routine restarts the specified task in a way that the
440 *  next time this thread executes, it will begin execution at its
441 *  original starting point.
442 */
443 
444/* XXX multiple task arg profiles */
445 
446boolean _Thread_Restart(
447  Thread_Control           *the_thread,
448  void                     *pointer_argument,
449  unsigned32                numeric_argument
450);
451
452/*
453 *  _Thread_Reset
454 *
455 *  DESCRIPTION:
456 *
457 *  This routine resets a thread to its initial state but does
458 *  not restart it.
459 */
460 
461void _Thread_Reset(
462  Thread_Control      *the_thread,
463  void                *pointer_argument,
464  unsigned32           numeric_argument
465);
466
467/*
468 *  _Thread_Close
469 *
470 *  DESCRIPTION:
471 *
472 *  This routine frees all memory associated with the specified
473 *  thread and removes it from the local object table so no further
474 *  operations on this thread are allowed.
475 */
476 
477void _Thread_Close(
478  Objects_Information  *information,
479  Thread_Control       *the_thread
480);
481
482/*
483 *  _Thread_Ready
484 *
485 *  DESCRIPTION:
486 *
487 *  This routine removes any set states for the_thread.  It performs
488 *  any necessary scheduling operations including the selection of
489 *  a new heir thread.
490 */
491
492void _Thread_Ready(
493  Thread_Control *the_thread
494);
495
496/*
497 *  _Thread_Clear_state
498 *
499 *  DESCRIPTION:
500 *
501 *  This routine clears the indicated STATES for the_thread.  It performs
502 *  any necessary scheduling operations including the selection of
503 *  a new heir thread.
504 */
505
506void _Thread_Clear_state(
507  Thread_Control *the_thread,
508  States_Control  state
509);
510
511/*
512 *  _Thread_Set_state
513 *
514 *  DESCRIPTION:
515 *
516 *  This routine sets the indicated states for the_thread.  It performs
517 *  any necessary scheduling operations including the selection of
518 *  a new heir thread.
519 *
520 */
521
522void _Thread_Set_state(
523  Thread_Control *the_thread,
524  States_Control  state
525);
526
527/*
528 *  _Thread_Set_transient
529 *
530 *  DESCRIPTION:
531 *
532 *  This routine sets the TRANSIENT state for the_thread.  It performs
533 *  any necessary scheduling operations including the selection of
534 *  a new heir thread.
535 */
536
537void _Thread_Set_transient(
538  Thread_Control *the_thread
539);
540
541/*
542 *  _Thread_Reset_timeslice
543 *
544 *  DESCRIPTION:
545 *
546 *  This routine is invoked upon expiration of the currently
547 *  executing thread's timeslice.  If no other thread's are ready
548 *  at the priority of the currently executing thread, then the
549 *  executing thread's timeslice is reset.  Otherwise, the
550 *  currently executing thread is placed at the rear of the
551 *  FIFO for this priority and a new heir is selected.
552 */
553
554void _Thread_Reset_timeslice( void );
555
556/*
557 *  _Thread_Tickle_timeslice
558 *
559 *  DESCRIPTION:
560 *
561 *  This routine is invoked as part of processing each clock tick.
562 *  It is responsible for determining if the current thread allows
563 *  timeslicing and, if so, when its timeslice expires.
564 */
565
566void _Thread_Tickle_timeslice( void );
567
568/*
569 *  _Thread_Yield_processor
570 *
571 *  DESCRIPTION:
572 *
573 *  This routine is invoked when a thread wishes to voluntarily
574 *  transfer control of the processor to another thread of equal
575 *  or greater priority.
576 */
577
578void _Thread_Yield_processor( void );
579
580/* 
581 *  _Thread_Rotate_Ready_Queue
582 * 
583 *  DESCRIPTION:
584 * 
585 *  This routine is invoked to rotate the ready queue for the
586 *  given priority.  It can be used to yeild the processor
587 *  by rotating the executing threads ready queue.
588 */
589
590void _Thread_Rotate_Ready_Queue(
591  Priority_Control  priority
592);
593
594/*
595 *  _Thread_Load_environment
596 *
597 *  DESCRIPTION:
598 *
599 *  This routine initializes the context of the_thread to its
600 *  appropriate starting state.
601 */
602
603void _Thread_Load_environment(
604  Thread_Control *the_thread
605);
606
607/*
608 *  _Thread_Handler
609 *
610 *  DESCRIPTION:
611 *
612 *  This routine is the wrapper function for all threads.  It is
613 *  the starting point for all threads.  The user provided thread
614 *  entry point is invoked by this routine.  Operations
615 *  which must be performed immediately before and after the user's
616 *  thread executes are found here.
617 */
618
619void _Thread_Handler( void );
620
621/*
622 *  _Thread_Delay_ended
623 *
624 *  DESCRIPTION:
625 *
626 *  This routine is invoked when a thread must be unblocked at the
627 *  end of a time based delay (i.e. wake after or wake when).
628 */
629
630void _Thread_Delay_ended(
631  Objects_Id  id,
632  void       *ignored
633);
634
635/*
636 *  _Thread_Change_priority
637 *
638 *  DESCRIPTION:
639 *
640 *  This routine changes the current priority of the_thread to
641 *  new_priority.  It performs any necessary scheduling operations
642 *  including the selection of a new heir thread.
643 */
644
645void _Thread_Change_priority (
646  Thread_Control   *the_thread,
647  Priority_Control  new_priority,
648  boolean           prepend_it
649);
650
651/*
652 *  _Thread_Set_priority
653 *
654 *  DESCRIPTION:
655 *
656 *  This routine updates the priority related fields in the_thread
657 *  control block to indicate the current priority is now new_priority.
658 */
659
660void _Thread_Set_priority(
661  Thread_Control   *the_thread,
662  Priority_Control  new_priority
663);
664
665/*
666 *  _Thread_Suspend
667 *
668 *  DESCRIPTION:
669 *
670 *  This routine updates the related suspend fields in the_thread
671 *  control block to indicate the current nested level.
672 */
673
674void _Thread_Suspend(
675  Thread_Control   *the_thread
676);
677
678/*
679 *  _Thread_Resume
680 *
681 *  DESCRIPTION:
682 *
683 *  This routine updates the related suspend fields in the_thread
684 *  control block to indicate the current nested level.  A force
685 *  parameter of TRUE will force a resume and clear the suspend count.
686 */
687
688void _Thread_Resume(
689  Thread_Control   *the_thread,
690  boolean           force
691);
692
693/*
694 *  _Thread_Evaluate_mode
695 *
696 *  DESCRIPTION:
697 *
698 *  This routine evaluates the current scheduling information for the
699 *  system and determines if a context switch is required.  This
700 *  is usually called after changing an execution mode such as preemptability
701 *  for a thread.
702 */
703
704boolean _Thread_Evaluate_mode( void );
705
706/*
707 *  _Thread_Get
708 *
709 *  NOTE:  If we are not using static inlines, this must be a real
710 *         subroutine call.
711 */
712 
713#ifndef USE_INLINES
714Thread_Control *_Thread_Get (
715  Objects_Id           id,
716  Objects_Locations   *location
717);
718#endif
719
720/*
721 *  _Thread_Idle_body
722 *
723 *  DESCRIPTION:
724 *
725 *  This routine is the body of the system idle thread.
726 */
727 
728#if (CPU_PROVIDES_IDLE_THREAD_BODY == FALSE)
729Thread _Thread_Idle_body(
730  unsigned32 ignored
731);
732#endif
733
734#ifndef __RTEMS_APPLICATION__
735#include <rtems/score/thread.inl>
736#endif
737#if defined(RTEMS_MULTIPROCESSING)
738#include <rtems/score/threadmp.h>
739#endif
740
741#ifdef __cplusplus
742}
743#endif
744
745#endif
746/* end of include file */
Note: See TracBrowser for help on using the repository browser.