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

4.104.114.84.95
Last change on this file since eb02f47 was eb02f47, checked in by Joel Sherrill <joel.sherrill@…>, on Nov 10, 1999 at 1:48:27 PM

Committed modifications from ITRON Task and Task Dependendent Synchronization
Working Group. Included are tests.

  • Property mode set to 100644
File size: 17.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 *  XXX
390 *
391 *  NOTES:
392 *
393 *  If stack_area is NULL, it is allocated from the workspace.
394 *
395 *  If the stack is allocated from the workspace, then it is guaranteed to be
396 *  of at least minimum size.
397 */
398
399boolean _Thread_Initialize(
400  Objects_Information                  *information,
401  Thread_Control                       *the_thread,
402  void                                 *stack_area,
403  unsigned32                            stack_size,
404  boolean                               is_fp,
405  Priority_Control                      priority,
406  boolean                               is_preemptible,
407  Thread_CPU_budget_algorithms          budget_algorithm,
408  Thread_CPU_budget_algorithm_callout   budget_callout,
409  unsigned32                            isr_level,
410  Objects_Name                          name
411);
412
413/*
414 *  _Thread_Start
415 *
416 *  DESCRIPTION:
417 *
418 *  XXX
419 */
420 
421boolean _Thread_Start(
422  Thread_Control           *the_thread,
423  Thread_Start_types        the_prototype,
424  void                     *entry_point,
425  void                     *pointer_argument,
426  unsigned32                numeric_argument
427);
428
429/*
430 *  _Thread_Restart
431 *
432 *  DESCRIPTION:
433 *
434 *  XXX
435 */
436 
437/* XXX multiple task arg profiles */
438 
439boolean _Thread_Restart(
440  Thread_Control           *the_thread,
441  void                     *pointer_argument,
442  unsigned32                numeric_argument
443);
444
445/*
446 *  _Thread_Close
447 *
448 *  DESCRIPTION:
449 *
450 *  XXX
451 */
452 
453void _Thread_Close(
454  Objects_Information  *information,
455  Thread_Control       *the_thread
456);
457
458/*
459 *  _Thread_Ready
460 *
461 *  DESCRIPTION:
462 *
463 *  This routine removes any set states for the_thread.  It performs
464 *  any necessary scheduling operations including the selection of
465 *  a new heir thread.
466 */
467
468void _Thread_Ready(
469  Thread_Control *the_thread
470);
471
472/*
473 *  _Thread_Clear_state
474 *
475 *  DESCRIPTION:
476 *
477 *  This routine clears the indicated STATES for the_thread.  It performs
478 *  any necessary scheduling operations including the selection of
479 *  a new heir thread.
480 */
481
482void _Thread_Clear_state(
483  Thread_Control *the_thread,
484  States_Control  state
485);
486
487/*
488 *  _Thread_Set_state
489 *
490 *  DESCRIPTION:
491 *
492 *  This routine sets the indicated states for the_thread.  It performs
493 *  any necessary scheduling operations including the selection of
494 *  a new heir thread.
495 *
496 */
497
498void _Thread_Set_state(
499  Thread_Control *the_thread,
500  States_Control  state
501);
502
503/*
504 *  _Thread_Set_transient
505 *
506 *  DESCRIPTION:
507 *
508 *  This routine sets the TRANSIENT state for the_thread.  It performs
509 *  any necessary scheduling operations including the selection of
510 *  a new heir thread.
511 */
512
513void _Thread_Set_transient(
514  Thread_Control *the_thread
515);
516
517/*
518 *  _Thread_Reset_timeslice
519 *
520 *  DESCRIPTION:
521 *
522 *  This routine is invoked upon expiration of the currently
523 *  executing thread's timeslice.  If no other thread's are ready
524 *  at the priority of the currently executing thread, then the
525 *  executing thread's timeslice is reset.  Otherwise, the
526 *  currently executing thread is placed at the rear of the
527 *  FIFO for this priority and a new heir is selected.
528 */
529
530void _Thread_Reset_timeslice( void );
531
532/*
533 *  _Thread_Tickle_timeslice
534 *
535 *  DESCRIPTION:
536 *
537 *  This routine is invoked as part of processing each clock tick.
538 *  It is responsible for determining if the current thread allows
539 *  timeslicing and, if so, when its timeslice expires.
540 */
541
542void _Thread_Tickle_timeslice( void );
543
544/*
545 *  _Thread_Yield_processor
546 *
547 *  DESCRIPTION:
548 *
549 *  This routine is invoked when a thread wishes to voluntarily
550 *  transfer control of the processor to another thread of equal
551 *  or greater priority.
552 */
553
554void _Thread_Yield_processor( void );
555
556/* 
557 *  _Thread_Rotate_Ready_Queue
558 * 
559 *  DESCRIPTION:
560 * 
561 *  This routine is invoked to rotate the ready queue for the
562 *  given priority.  It can be used to yeild the processor
563 *  by rotating the executing threads ready queue.
564 */
565
566void _Thread_Rotate_Ready_Queue(
567  Priority_Control  priority
568);
569
570/*
571 *  _Thread_Load_environment
572 *
573 *  DESCRIPTION:
574 *
575 *  This routine initializes the context of the_thread to its
576 *  appropriate starting state.
577 */
578
579void _Thread_Load_environment(
580  Thread_Control *the_thread
581);
582
583/*
584 *  _Thread_Handler
585 *
586 *  DESCRIPTION:
587 *
588 *  This routine is the wrapper function for all threads.  It is
589 *  the starting point for all threads.  The user provided thread
590 *  entry point is invoked by this routine.  Operations
591 *  which must be performed immediately before and after the user's
592 *  thread executes are found here.
593 */
594
595void _Thread_Handler( void );
596
597/*
598 *  _Thread_Delay_ended
599 *
600 *  DESCRIPTION:
601 *
602 *  This routine is invoked when a thread must be unblocked at the
603 *  end of a time based delay (i.e. wake after or wake when).
604 */
605
606void _Thread_Delay_ended(
607  Objects_Id  id,
608  void       *ignored
609);
610
611/*
612 *  _Thread_Change_priority
613 *
614 *  DESCRIPTION:
615 *
616 *  This routine changes the current priority of the_thread to
617 *  new_priority.  It performs any necessary scheduling operations
618 *  including the selection of a new heir thread.
619 */
620
621void _Thread_Change_priority (
622  Thread_Control   *the_thread,
623  Priority_Control  new_priority,
624  boolean           prepend_it
625);
626
627/*
628 *  _Thread_Set_priority
629 *
630 *  DESCRIPTION:
631 *
632 *  This routine updates the priority related fields in the_thread
633 *  control block to indicate the current priority is now new_priority.
634 */
635
636void _Thread_Set_priority(
637  Thread_Control   *the_thread,
638  Priority_Control  new_priority
639);
640
641/*
642 *  _Thread_Suspend
643 *
644 *  DESCRIPTION:
645 *
646 *  This routine updates the related suspend fields in the_thread
647 *  control block to indicate the current nested level.
648 */
649
650void _Thread_Suspend(
651  Thread_Control   *the_thread
652);
653
654/*
655 *  _Thread_Resume
656 *
657 *  DESCRIPTION:
658 *
659 *  This routine updates the related suspend fields in the_thread
660 *  control block to indicate the current nested level.  A force
661 *  parameter of TRUE will force a resume and clear the suspend count.
662 */
663
664void _Thread_Resume(
665  Thread_Control   *the_thread,
666  boolean           force
667);
668
669/*
670 *  _Thread_Evaluate_mode
671 *
672 *  DESCRIPTION:
673 *
674 *  This routine evaluates the current scheduling information for the
675 *  system and determines if a context switch is required.  This
676 *  is usually called after changing an execution mode such as preemptability
677 *  for a thread.
678 */
679
680boolean _Thread_Evaluate_mode( void );
681
682/*
683 *  _Thread_Get
684 *
685 *  NOTE:  If we are not using static inlines, this must be a real
686 *         subroutine call.
687 */
688 
689#ifndef USE_INLINES
690Thread_Control *_Thread_Get (
691  Objects_Id           id,
692  Objects_Locations   *location
693);
694#endif
695
696/*
697 *  _Thread_Idle_body
698 *
699 *  DESCRIPTION:
700 *
701 *  This routine is the body of the system idle thread.
702 */
703 
704#if (CPU_PROVIDES_IDLE_THREAD_BODY == FALSE)
705Thread _Thread_Idle_body(
706  unsigned32 ignored
707);
708#endif
709
710#ifndef __RTEMS_APPLICATION__
711#include <rtems/score/thread.inl>
712#endif
713#if defined(RTEMS_MULTIPROCESSING)
714#include <rtems/score/threadmp.h>
715#endif
716
717#ifdef __cplusplus
718}
719#endif
720
721#endif
722/* end of include file */
Note: See TracBrowser for help on using the repository browser.