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

4.104.114.84.95
Last change on this file since b2b52cbc was b2b52cbc, checked in by Joel Sherrill <joel.sherrill@…>, on 02/14/96 at 19:00:00

Removed arguments from _Thread_Start_multitasking.

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