source: rtems/c/src/exec/score/headers/thread.h @ 3a4ae6c

4.104.114.84.95
Last change on this file since 3a4ae6c was 3a4ae6c, checked in by Joel Sherrill <joel.sherrill@…>, on 09/11/95 at 19:35:39

The word "RTEMS" almost completely removed from the core.

Configuration Table Template file added and all tests
modified to use this. All gvar.h and conftbl.h files
removed from test directories.

Configuration parameter maximum_devices added.

Core semaphore and mutex handlers added and RTEMS API Semaphore
Manager updated to reflect this.

Initialization sequence changed to invoke API specific initialization
routines. Initialization tasks table now owned by RTEMS Tasks Manager.

Added user extension for post-switch.

Utilized user extensions to implement API specific functionality
like signal dispatching.

Added extensions to the System Initialization Thread so that an
API can register a function to be invoked while the system
is being initialized. These are largely equivalent to the
pre-driver and post-driver hooks.

Added the Modules file oar-go32_p5, modified oar-go32, and modified
the file make/custom/go32.cfg to look at an environment varable which
determines what CPU model is being used.

All BSPs updated to reflect named devices and clock driver's IOCTL
used by the Shared Memory Driver. Also merged clock isr into
main file and removed ckisr.c where possible.

Updated spsize to reflect new and moved variables.

Makefiles for the executive source and include files updated to show
break down of files into Core, RTEMS API, and Neither.

Header and inline files installed into subdirectory based on whether
logically in the Core or a part of the RTEMS API.

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