source: rtems/cpukit/score/include/rtems/score/thread.h @ 94b3ec59

4.104.114.84.95
Last change on this file since 94b3ec59 was 94b3ec59, checked in by Joel Sherrill <joel.sherrill@…>, on 02/13/96 at 22:14:48

changed post task extension from user set to api set and added flag
in each thread which must be set when the post switch extension is to be run.

  • 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, 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
21extern "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
39typedef 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
49typedef 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
56typedef Thread ( *Thread_Entry )( );
57
58/*
59 *  The following structure contains the information which defines
60 *  the starting state of a thread.
61 */
62
63typedef 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
85typedef 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
110typedef 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
132typedef 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
140typedef 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 context area contains the context of the "thread"
165 *  which invoked the start multitasking routine.  This context is
166 *  restored as the last action of the stop multitasking routine.  Thus
167 *  control of the processor can be returned to the environment
168 *  which initiated the system.
169 */
170 
171EXTERN Context_Control _Thread_BSP_context;
172 
173/*
174 *  The following declares the dispatch critical section nesting
175 *  counter which is used to prevent context switches at inopportune
176 *  moments.
177 */
178
179EXTERN unsigned32 _Thread_Dispatch_disable_level;
180
181/*
182 *  The following holds how many user extensions are in the system.  This
183 *  is used to determine how many user extension data areas to allocate
184 *  per thread.
185 */
186
187EXTERN unsigned32 _Thread_Maximum_extensions;
188
189/*
190 *  The following data items are used to manage timeslicing.
191 */
192
193EXTERN unsigned32 _Thread_Ticks_remaining_in_timeslice;
194EXTERN unsigned32 _Thread_Ticks_per_timeslice;
195
196/*
197 *  The following points to the array of FIFOs used to manage the
198 *  set of ready threads.
199 */
200
201EXTERN Chain_Control *_Thread_Ready_chain;
202
203/*
204 *  The following points to the thread which is currently executing.
205 *  This thread is implicitly manipulated by numerous directives.
206 */
207
208EXTERN Thread_Control *_Thread_Executing;
209
210/*
211 *  The following points to the highest priority ready thread
212 *  in the system.  Unless the current thread is not preemptibl,
213 *  then this thread will be context switched to when the next
214 *  dispatch occurs.
215 */
216
217EXTERN Thread_Control *_Thread_Heir;
218
219/*
220 *  The following points to the thread whose floating point
221 *  context is currently loaded.
222 */
223
224EXTERN Thread_Control *_Thread_Allocated_fp;
225
226/*
227 *  _Thread_Handler_initialization
228 *
229 *  DESCRIPTION:
230 *
231 *  This routine performs the initialization necessary for this handler.
232 */
233
234void _Thread_Handler_initialization (
235  unsigned32   ticks_per_timeslice,
236  unsigned32   maximum_extensions,
237  unsigned32   maximum_proxies
238);
239
240/*
241 *  _Thread_Start_multitasking
242 *
243 *  DESCRIPTION:
244 *
245 *  This routine initiates multitasking.  It is invoked only as
246 *  part of initialization and its invocation is the last act of
247 *  the non-multitasking part of the system initialization.
248 */
249
250void _Thread_Start_multitasking (
251  Thread_Control *system_thread,
252  Thread_Control *idle_thread
253);
254
255/*
256 *  _Thread_Stop_multitasking
257 *
258 *  DESCRIPTION:
259 *
260 *  This routine halts multitasking and returns control to
261 *  the "thread" (i.e. the BSP) which initially invoked the
262 *  routine which initialized the system.
263 */
264
265STATIC INLINE void _Thread_Stop_multitasking( void );
266
267/*
268 *  _Thread_Dispatch_initialization
269 *
270 *  DESCRIPTION:
271 *
272 *  This routine initializes the thread dispatching subsystem.
273 */
274
275STATIC INLINE void _Thread_Dispatch_initialization( void );
276
277/*
278 *  _Thread_Dispatch
279 *
280 *  DESCRIPTION:
281 *
282 *  This routine is responsible for transferring control of the
283 *  processor from the executing thread to the heir thread.  As part
284 *  of this process, it is responsible for the following actions:
285 *
286 *     + saving the context of the executing thread
287 *     + restoring the context of the heir thread
288 *     + dispatching any signals for the resulting executing thread
289 */
290
291void _Thread_Dispatch( void );
292
293/*
294 *  _Thread_Initialize
295 *
296 *  DESCRIPTION:
297 *
298 *  XXX
299 */
300
301boolean _Thread_Initialize(
302  Objects_Information *information,
303  Thread_Control      *the_thread,
304  void                *stack_area,    /* NULL if to be allocated */
305  unsigned32           stack_size,    /* insure it is >= min */
306  boolean              is_fp,         /* TRUE if thread uses FP */
307  Priority_Control     priority,
308  boolean              is_preemptible,
309  boolean              is_timeslice,
310  unsigned32           isr_level,
311  Objects_Name         name
312 
313);
314
315/*
316 *  _Thread_Start
317 *
318 *  DESCRIPTION:
319 *
320 *  XXX
321 */
322 
323boolean _Thread_Start(
324  Thread_Control           *the_thread,
325  Thread_Start_types        the_prototype,
326  void                     *entry_point,
327  void                     *pointer_argument,
328  unsigned32                numeric_argument
329);
330
331/*
332 *  _Thread_Restart
333 *
334 *  DESCRIPTION:
335 *
336 *  XXX
337 */
338 
339/* XXX multiple task arg profiles */
340 
341boolean _Thread_Restart(
342  Thread_Control           *the_thread,
343  void                     *pointer_argument,
344  unsigned32                numeric_argument
345);
346
347/*
348 *  _Thread_Close
349 *
350 *  DESCRIPTION:
351 *
352 *  XXX
353 */
354 
355void _Thread_Close(
356  Objects_Information  *information,
357  Thread_Control       *the_thread
358);
359
360/*
361 *  _Thread_Ready
362 *
363 *  DESCRIPTION:
364 *
365 *  This routine removes any set states for the_thread.  It performs
366 *  any necessary scheduling operations including the selection of
367 *  a new heir thread.
368 */
369
370void _Thread_Ready(
371  Thread_Control *the_thread
372);
373
374/*
375 *  _Thread_Clear_state
376 *
377 *  DESCRIPTION:
378 *
379 *  This routine clears the indicated STATES for the_thread.  It performs
380 *  any necessary scheduling operations including the selection of
381 *  a new heir thread.
382 */
383
384void _Thread_Clear_state(
385  Thread_Control *the_thread,
386  States_Control  state
387);
388
389/*
390 *  _Thread_Set_state
391 *
392 *  DESCRIPTION:
393 *
394 *  This routine sets the indicated states for the_thread.  It performs
395 *  any necessary scheduling operations including the selection of
396 *  a new heir thread.
397 *
398 */
399
400void _Thread_Set_state(
401  Thread_Control *the_thread,
402  States_Control  state
403);
404
405/*
406 *  _Thread_Set_transient
407 *
408 *  DESCRIPTION:
409 *
410 *  This routine sets the TRANSIENT state for the_thread.  It performs
411 *  any necessary scheduling operations including the selection of
412 *  a new heir thread.
413 */
414
415void _Thread_Set_transient(
416  Thread_Control *the_thread
417);
418
419/*
420 *  _Thread_Reset_timeslice
421 *
422 *  DESCRIPTION:
423 *
424 *  This routine is invoked upon expiration of the currently
425 *  executing thread's timeslice.  If no other thread's are ready
426 *  at the priority of the currently executing thread, then the
427 *  executing thread's timeslice is reset.  Otherwise, the
428 *  currently executing thread is placed at the rear of the
429 *  FIFO for this priority and a new heir is selected.
430 */
431
432void _Thread_Reset_timeslice( void );
433
434/*
435 *  _Thread_Tickle_timeslice
436 *
437 *  DESCRIPTION:
438 *
439 *  This routine is invoked as part of processing each clock tick.
440 *  It is responsible for determining if the current thread allows
441 *  timeslicing and, if so, when its timeslice expires.
442 */
443
444void _Thread_Tickle_timeslice( void );
445
446/*
447 *  _Thread_Yield_processor
448 *
449 *  DESCRIPTION:
450 *
451 *  This routine is invoked when a thread wishes to voluntarily
452 *  transfer control of the processor to another thread of equal
453 *  or greater priority.
454 */
455
456void _Thread_Yield_processor( void );
457
458/*
459 *  _Thread_Is_executing
460 *
461 *  DESCRIPTION:
462 *
463 *  This function returns TRUE if the_thread is the currently executing
464 *  thread, and FALSE otherwise.
465 */
466
467STATIC INLINE boolean _Thread_Is_executing (
468  Thread_Control *the_thread
469);
470
471/*
472 *  _Thread_Is_heir
473 *
474 *  DESCRIPTION:
475 *
476 *  This function returns TRUE if the_thread is the heir
477 *  thread, and FALSE otherwise.
478 */
479
480STATIC INLINE boolean _Thread_Is_executing (
481  Thread_Control *the_thread
482);
483
484/*
485 *  _Thread_Is_executing_also_the_heir
486 *
487 *  DESCRIPTION:
488 *
489 *  This function returns TRUE if the currently executing thread
490 *  is also the heir thread, and FALSE otherwise.
491 */
492
493STATIC INLINE boolean _Thread_Is_executing_also_the_heir( void );
494
495/*
496 *  _Thread_Load_environment
497 *
498 *  DESCRIPTION:
499 *
500 *  This routine initializes the context of the_thread to its
501 *  appropriate starting state.
502 */
503
504void _Thread_Load_environment(
505  Thread_Control *the_thread
506);
507
508/*
509 *  _Thread_Handler
510 *
511 *  DESCRIPTION:
512 *
513 *  This routine is the wrapper function for all threads.  It is
514 *  the starting point for all threads.  The user provided thread
515 *  entry point is invoked by this routine.  Operations
516 *  which must be performed immediately before and after the user's
517 *  thread executes are found here.
518 */
519
520void _Thread_Handler( void );
521
522/*
523 *  _Thread_Delay_ended
524 *
525 *  DESCRIPTION:
526 *
527 *  This routine is invoked when a thread must be unblocked at the
528 *  end of a time based delay (i.e. wake after or wake when).
529 */
530
531void _Thread_Delay_ended(
532  Objects_Id  id,
533  void       *ignored
534);
535
536/*
537 *  _Thread_Change_priority
538 *
539 *  DESCRIPTION:
540 *
541 *  This routine changes the current priority of the_thread to
542 *  new_priority.  It performs any necessary scheduling operations
543 *  including the selection of a new heir thread.
544 */
545
546void _Thread_Change_priority (
547  Thread_Control   *the_thread,
548  Priority_Control  new_priority
549);
550
551/*
552 *  _Thread_Set_priority
553 *
554 *  DESCRIPTION:
555 *
556 *  This routine updates the priority related fields in the_thread
557 *  control block to indicate the current priority is now new_priority.
558 */
559
560void _Thread_Set_priority(
561  Thread_Control   *the_thread,
562  Priority_Control  new_priority
563);
564
565/*
566 *  _Thread_Evaluate_mode
567 *
568 *  DESCRIPTION:
569 *
570 *  This routine XXX
571 */
572
573boolean _Thread_Evaluate_mode( void );
574
575/*
576 *  _Thread_Resume
577 *
578 *  DESCRIPTION:
579 *
580 *  This routine clears the SUSPENDED state for the_thread.  It performs
581 *  any necessary scheduling operations including the selection of
582 *  a new heir thread.
583 */
584
585STATIC INLINE void _Thread_Resume (
586  Thread_Control *the_thread
587);
588
589/*
590 *  _Thread_Unblock
591 *
592 *  DESCRIPTION:
593 *
594 *  This routine clears any blocking state for the_thread.  It performs
595 *  any necessary scheduling operations including the selection of
596 *  a new heir thread.
597 */
598
599STATIC INLINE void _Thread_Unblock (
600  Thread_Control *the_thread
601);
602
603/*
604 *  _Thread_Restart_self
605 *
606 *  DESCRIPTION:
607 *
608 *  This routine resets the current context of the calling thread
609 *  to that of its initial state.
610 */
611
612STATIC INLINE void _Thread_Restart_self( void );
613
614/*
615 *  _Thread_Calculate_heir
616 *
617 *  DESCRIPTION:
618 *
619 *  This function returns a pointer to the highest priority
620 *  ready thread.
621 */
622
623STATIC INLINE void _Thread_Calculate_heir( void );
624
625/*
626 *  _Thread_Is_allocated_fp
627 *
628 *  DESCRIPTION:
629 *
630 *  This function returns TRUE if the floating point context of
631 *  the_thread is currently loaded in the floating point unit, and
632 *  FALSE otherwise.
633 */
634
635STATIC INLINE boolean _Thread_Is_allocated_fp (
636  Thread_Control *the_thread
637);
638
639/*
640 *  _Thread_Deallocate_fp
641 *
642 *  DESCRIPTION:
643 *
644 *  This routine is invoked when the currently loaded floating
645 *  point context is now longer associated with an active thread.
646 */
647
648STATIC INLINE void _Thread_Deallocate_fp( void );
649
650/*
651 *  _Thread_Disable_dispatch
652 *
653 *  DESCRIPTION:
654 *
655 *  This routine prevents dispatching.
656 */
657
658STATIC INLINE void _Thread_Disable_dispatch( void );
659
660/*
661 *  _Thread_Enable_dispatch
662 *
663 *  DESCRIPTION:
664 *
665 *  This routine allows dispatching to occur again.  If this is
666 *  the outer most dispatching critical section, then a dispatching
667 *  operation will be performed and, if necessary, control of the
668 *  processor will be transferred to the heir thread.
669 */
670
671#if ( CPU_INLINE_ENABLE_DISPATCH == TRUE )
672
673STATIC INLINE void _Thread_Enable_dispatch();
674
675#endif
676
677#if ( CPU_INLINE_ENABLE_DISPATCH == FALSE )
678
679void _Thread_Enable_dispatch( void );
680
681#endif
682
683/*
684 *  _Thread_Unnest_dispatch
685 *
686 *  DESCRIPTION:
687 *
688 *  This routine allows dispatching to occur again.  However,
689 *  no dispatching operation is performed even if this is the outer
690 *  most dispatching critical section.
691 */
692
693STATIC INLINE void _Thread_Unnest_dispatch( void );
694
695/*
696 *  _Thread_Is_dispatching_enabled
697 *
698 *  DESCRIPTION:
699 *
700 *  This function returns TRUE if dispatching is disabled, and FALSE
701 *  otherwise.
702 */
703
704STATIC INLINE boolean _Thread_Is_dispatching_enabled( void );
705
706/*
707 *  _Thread_Is_context_switch_necessary
708 *
709 *  DESCRIPTION:
710 *
711 *  This function returns TRUE if dispatching is disabled, and FALSE
712 *  otherwise.
713 */
714
715STATIC INLINE boolean _Thread_Is_context_switch_necessary( void );
716
717/*
718 *  _Thread_Is_null
719 *
720 *  DESCRIPTION:
721 *
722 *  This function returns TRUE if the_thread is NULL and FALSE otherwise.
723 */
724
725STATIC INLINE boolean _Thread_Is_null (
726  Thread_Control *the_thread
727);
728
729/*
730 *  _Thread_Get
731 *
732 *  DESCRIPTION:
733 *
734 *  This function maps thread IDs to thread control
735 *  blocks.  If ID corresponds to a local thread, then it
736 *  returns the_thread control pointer which maps to ID
737 *  and location is set to OBJECTS_LOCAL.  If the thread ID is
738 *  global and resides on a remote node, then location is set
739 *  to OBJECTS_REMOTE, and the_thread is undefined.
740 *  Otherwise, location is set to OBJECTS_ERROR and
741 *  the_thread is undefined.
742 */
743
744STATIC INLINE Thread_Control *_Thread_Get (
745  Objects_Id         id,
746  Objects_Locations *location
747);
748
749/*
750 *  _Thread_Is_proxy_blocking
751 *
752 *  DESCRIPTION:
753 *
754 *  This function returns TRUE if the status code is equal to the
755 *  status which indicates that a proxy is blocking, and FALSE otherwise.
756 */
757 
758STATIC INLINE boolean _Thread_Is_proxy_blocking (
759  unsigned32 code
760);
761
762#include <rtems/score/thread.inl>
763#include <rtems/score/threadmp.h>
764
765#ifdef __cplusplus
766}
767#endif
768
769#endif
770/* end of include file */
Note: See TracBrowser for help on using the repository browser.