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

4.104.114.84.95
Last change on this file since ac7d5ef0 was ac7d5ef0, checked in by Joel Sherrill <joel.sherrill@…>, on 05/11/95 at 17:39:37

Initial revision

  • Property mode set to 100644
File size: 17.6 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 __RTEMS_THREAD_h
18#define __RTEMS_THREAD_h
19
20#ifdef __cplusplus
21extern "C" {
22#endif
23
24#include <rtems/asr.h>
25#include <rtems/attr.h>
26#include <rtems/context.h>
27#include <rtems/cpu.h>
28#include <rtems/eventset.h>
29#include <rtems/modes.h>
30#include <rtems/mppkt.h>
31#include <rtems/object.h>
32#include <rtems/options.h>
33#include <rtems/priority.h>
34#include <rtems/stack.h>
35#include <rtems/states.h>
36#include <rtems/tod.h>
37#include <rtems/tqdata.h>
38#include <rtems/watchdog.h>
39
40/*
41 *  Notepads constants (indices into notepad array)
42 */
43
44#define RTEMS_NOTEPAD_FIRST 0             /* lowest numbered notepad */
45#define RTEMS_NOTEPAD_0    0              /* notepad location 0  */
46#define RTEMS_NOTEPAD_1    1              /* notepad location 1  */
47#define RTEMS_NOTEPAD_2    2              /* notepad location 2  */
48#define RTEMS_NOTEPAD_3    3              /* notepad location 3  */
49#define RTEMS_NOTEPAD_4    4              /* notepad location 4  */
50#define RTEMS_NOTEPAD_5    5              /* notepad location 5  */
51#define RTEMS_NOTEPAD_6    6              /* notepad location 6  */
52#define RTEMS_NOTEPAD_7    7              /* notepad location 7  */
53#define RTEMS_NOTEPAD_8    8              /* notepad location 8  */
54#define RTEMS_NOTEPAD_9    9              /* notepad location 9  */
55#define RTEMS_NOTEPAD_10   10             /* notepad location 10 */
56#define RTEMS_NOTEPAD_11   11             /* notepad location 11 */
57#define RTEMS_NOTEPAD_12   12             /* notepad location 12 */
58#define RTEMS_NOTEPAD_13   13             /* notepad location 13 */
59#define RTEMS_NOTEPAD_14   14             /* notepad location 14 */
60#define RTEMS_NOTEPAD_15   15             /* notepad location 15 */
61#define RTEMS_NOTEPAD_LAST RTEMS_NOTEPAD_15     /* highest numbered notepad */
62
63/*
64 *  The following defines the "return type" of an RTEMS thread.
65 *
66 *  NOTE:  Keep both types for internal threads.
67 */
68
69typedef void rtems_task;
70typedef void Thread;
71
72/*
73 *  The following defines the argument to an RTEMS thread.
74 */
75
76typedef unsigned32 rtems_task_argument;
77typedef unsigned32 Thread_Argument;
78
79/*
80 *  The following defines the type for the entry point of an RTEMS thread.
81 */
82
83typedef rtems_task ( *rtems_task_entry )(
84                      rtems_task_argument
85                   );
86
87typedef Thread ( *Thread_Entry )(
88                      Thread_Argument
89                   );
90
91/*
92 *  The following structure contains the information which defines
93 *  the starting state of a thread.
94 */
95
96typedef struct {
97  Thread_Entry         entry_point;      /* starting thread address         */
98  unsigned32           initial_argument; /* initial argument                */
99  rtems_mode           initial_modes;    /* initial mode                    */
100  rtems_task_priority  initial_priority; /* initial priority                */
101  void                *fp_context;       /* initial FP context area address */
102  Stack_Control        Initial_stack;    /* stack information               */
103}   Thread_Start_information;
104
105/*
106 *  The following structure contains the information necessary to manage
107 *  a thread which it is  waiting for a resource.
108 */
109
110typedef struct {
111  Objects_Id            id;              /* waiting on this object       */
112  rtems_option          option_set;      /* wait mode                    */
113  union {
114    unsigned32          segment_size;    /* size of segment requested    */
115    rtems_event_set     event_condition;
116  } Extra;
117  void                 *return_argument; /* address of user return param */
118  rtems_status_code     return_code;     /* status for thread awakened   */
119  Chain_Control         Block2n;         /* 2 - n priority blocked chain */
120  Thread_queue_Control *queue;           /* pointer to thread queue      */
121}   Thread_Wait_information;
122
123/*
124 *  The following defines the control block used to manage
125 *  each thread proxy.
126 *
127 *  NOTE: It is critical that proxies and threads have identical
128 *        memory images for the shared part.
129 */
130
131typedef struct {
132  Objects_Control          Object;
133  Objects_Name             name;
134  States_Control           current_state;
135  rtems_task_priority         current_priority;
136  rtems_task_priority         real_priority;
137  unsigned32               resource_count;
138  Thread_Wait_information  Wait;
139  Watchdog_Control         Timer;
140  rtems_packet_prefix        *receive_packet;
141     /****************** end of common block ********************/
142  Chain_Node               Active;
143}   Thread_Proxy_control;
144
145
146/*
147 *  The following record defines the control block used
148 *  to manage each thread.
149 *
150 *  NOTE: It is critical that proxies and threads have identical
151 *        memory images for the shared part.
152 */
153
154typedef struct {
155  Objects_Control           Object;
156  Objects_Name              name;
157  States_Control            current_state;
158  rtems_task_priority          current_priority;
159  rtems_task_priority          real_priority;
160  unsigned32                resource_count;
161  Thread_Wait_information   Wait;
162  Watchdog_Control          Timer;
163  rtems_packet_prefix         *receive_packet;
164     /****************** end of common block ********************/
165  Chain_Control            *ready;
166  Priority_Information      Priority_map;
167  rtems_event_set        pending_events;
168  rtems_event_set        events_out;
169  Thread_Start_information  Start;
170  ASR_Information           Signal;
171  rtems_mode             current_modes;
172  rtems_attribute        attribute_set;
173  Context_Control           Registers;
174  void                     *fp_context;
175  unsigned32                Notepads[ 16 ];
176  void                     *extension;
177}   Thread_Control;
178
179/*
180 *  External API name for Thread_Control
181 */
182
183typedef Thread_Control rtems_tcb;
184
185/*
186 *  The following declares the dispatch critical section nesting
187 *  counter which is used to prevent context switches at inopportune
188 *  moments.
189 */
190
191EXTERN unsigned32 _Thread_Dispatch_disable_level;
192
193/*
194 *  The following data items are used to manage timeslicing.
195 */
196
197EXTERN unsigned32 _Thread_Ticks_remaining_in_timeslice;
198EXTERN unsigned32 _Thread_Ticks_per_timeslice;
199
200/*
201 *  The following points to the array of FIFOs used to manage the
202 *  set of ready threads.
203 */
204
205EXTERN Chain_Control *_Thread_Ready_chain;
206
207/*
208 *  The following points to the thread which is currently executing.
209 *  This thread is implicitly manipulated by numerous directives.
210 */
211
212EXTERN Thread_Control *_Thread_Executing;
213
214/*
215 *  The following points to the highest priority ready thread
216 *  in the system.  Unless the current thread is RTEMS_NO_PREEMPT,
217 *  then this thread will be context switched to when the next
218 *  dispatch occurs.
219 */
220
221EXTERN Thread_Control *_Thread_Heir;
222
223/*
224 *  The following points to the thread whose floating point
225 *  context is currently loaded.
226 */
227
228EXTERN Thread_Control *_Thread_Allocated_fp;
229
230/*
231 *  The following defines the information control block used to
232 *  manage this class of objects.
233 */
234
235EXTERN Objects_Information _Thread_Information;
236
237/*
238 *  The following context area contains the context of the "thread"
239 *  which invoked rtems_initialize_executive.  This context is restored
240 *  as the last action of the rtems_shutdown_executive directive.  Thus
241 *  control of the processor can be returned to the environment
242 *  which initiated RTEMS.
243 */
244
245EXTERN Context_Control _Thread_BSP_context;
246
247/*
248 *  _Thread_Handler_initialization
249 *
250 *  DESCRIPTION:
251 *
252 *  This routine performs the initialization necessary for this handler.
253 */
254
255void _Thread_Handler_initialization (
256  unsigned32 maximum_tasks,
257  unsigned32 ticks_per_timeslice,
258  unsigned32 maximum_proxies
259);
260
261/*
262 *  _Thread_Start_multitasking
263 *
264 *  DESCRIPTION:
265 *
266 *  This routine initiates multitasking.  It is invoked only as
267 *  part of initialization and its invocation is the last act of
268 *  the rtems_initialize_executive directive.
269 */
270
271void _Thread_Start_multitasking (
272  Thread_Control *system_thread,
273  Thread_Control *idle_thread
274);
275
276/*
277 *  _Thread_Stop_multitasking
278 *
279 *  DESCRIPTION:
280 *
281 *  This routine halts multitasking and returns control to
282 *  the "thread" which initially invoked the rtems_initialize_executive
283 *  directive.
284 */
285
286STATIC INLINE void _Thread_Stop_multitasking( void );
287
288/*
289 *  _Thread_Dispatch_initialization
290 *
291 *  DESCRIPTION:
292 *
293 *  This routine initializes the thread dispatching subsystem.
294 */
295
296STATIC INLINE void _Thread_Dispatch_initialization( void );
297
298/*
299 *  _Thread_Dispatch
300 *
301 *  DESCRIPTION:
302 *
303 *  This routine is responsible for transferring control of the
304 *  processor from the executing thread to the heir thread.  As part
305 *  of this process, it is responsible for the following actions:
306 *
307 *     + saving the context of the executing thread
308 *     + restoring the context of the heir thread
309 *     + dispatching any signals for the resulting executing thread
310 */
311
312void _Thread_Dispatch( void );
313
314/*
315 *  _Thread_Ready
316 *
317 *  DESCRIPTION:
318 *
319 *  This routine removes any set states for the_thread.  It performs
320 *  any necessary scheduling operations including the selection of
321 *  a new heir thread.
322 */
323
324void _Thread_Ready(
325  Thread_Control *the_thread
326);
327
328/*
329 *  _Thread_Clear_state
330 *
331 *  DESCRIPTION:
332 *
333 *  This routine clears the indicated STATES for the_thread.  It performs
334 *  any necessary scheduling operations including the selection of
335 *  a new heir thread.
336 */
337
338void _Thread_Clear_state(
339  Thread_Control *the_thread,
340  States_Control  state
341);
342
343/*
344 *  _Thread_Set_state
345 *
346 *  DESCRIPTION:
347 *
348 *  This routine sets the indicated states for the_thread.  It performs
349 *  any necessary scheduling operations including the selection of
350 *  a new heir thread.
351 *
352 */
353
354void _Thread_Set_state(
355  Thread_Control *the_thread,
356  States_Control  state
357);
358
359/*
360 *  _Thread_Set_transient
361 *
362 *  DESCRIPTION:
363 *
364 *  This routine sets the TRANSIENT state for the_thread.  It performs
365 *  any necessary scheduling operations including the selection of
366 *  a new heir thread.
367 */
368
369void _Thread_Set_transient(
370  Thread_Control *the_thread
371);
372
373/*
374 *  _Thread_Reset_timeslice
375 *
376 *  DESCRIPTION:
377 *
378 *  This routine is invoked upon expiration of the currently
379 *  executing thread's timeslice.  If no other thread's are ready
380 *  at the priority of the currently executing thread, then the
381 *  executing thread's timeslice is reset.  Otherwise, the
382 *  currently executing thread is placed at the rear of the
383 *  RTEMS_FIFO for this priority and a new heir is selected.
384 */
385
386void _Thread_Reset_timeslice( void );
387
388/*
389 *  _Thread_Tickle_timeslice
390 *
391 *  DESCRIPTION:
392 *
393 *  This routine is invoked as part of processing each clock tick.
394 *  It is responsible for determining if the current thread allows
395 *  timeslicing and, if so, when its timeslice expires.
396 */
397
398void _Thread_Tickle_timeslice( void );
399
400/*
401 *  _Thread_Yield_processor
402 *
403 *  DESCRIPTION:
404 *
405 *  This routine is invoked when a thread wishes to voluntarily
406 *  transfer control of the processor to another thread of equal
407 *  or greater priority.
408 */
409
410void _Thread_Yield_processor( void );
411
412/*
413 *  _Thread_Is_executing
414 *
415 *  DESCRIPTION:
416 *
417 *  This function returns TRUE if the_thread is the currently executing
418 *  thread, and FALSE otherwise.
419 */
420
421STATIC INLINE boolean _Thread_Is_executing (
422  Thread_Control *the_thread
423);
424
425/*
426 *  _Thread_Is_heir
427 *
428 *  DESCRIPTION:
429 *
430 *  This function returns TRUE if the_thread is the heir
431 *  thread, and FALSE otherwise.
432 */
433
434STATIC INLINE boolean _Thread_Is_executing (
435  Thread_Control *the_thread
436);
437
438/*
439 *  _Thread_Is_executing_also_the_heir
440 *
441 *  DESCRIPTION:
442 *
443 *  This function returns TRUE if the currently executing thread
444 *  is also the heir thread, and FALSE otherwise.
445 */
446
447STATIC INLINE boolean _Thread_Is_executing_also_the_heir( void );
448
449/*
450 *  _Thread_Load_environment
451 *
452 *  DESCRIPTION:
453 *
454 *  This routine initializes the context of the_thread to its
455 *  appropriate starting state.
456 */
457
458void _Thread_Load_environment(
459  Thread_Control *the_thread
460);
461
462/*
463 *  _Thread_Handler
464 *
465 *  DESCRIPTION:
466 *
467 *  This routine is the wrapper function for all threads.  It is
468 *  the starting point for all threads.  The user provided thread
469 *  entry point is invoked by this routine.  Operations
470 *  which must be performed immediately before and after the user's
471 *  thread executes are found here.
472 */
473
474void _Thread_Handler( void );
475
476/*
477 *  _Thread_Delay_ended
478 *
479 *  DESCRIPTION:
480 *
481 *  This routine is invoked when a thread must be unblocked at the
482 *  end of a delay such as the rtems_task_wake_after and rtems_task_wake_when
483 *  directives.
484 */
485
486void _Thread_Delay_ended(
487  Objects_Id  id,
488  void       *ignored
489);
490
491/*
492 *  _Thread_Change_priority
493 *
494 *  DESCRIPTION:
495 *
496 *  This routine changes the current priority of the_thread to
497 *  new_priority.  It performs any necessary scheduling operations
498 *  including the selection of a new heir thread.
499 */
500
501void _Thread_Change_priority (
502  Thread_Control   *the_thread,
503  rtems_task_priority  new_priority
504);
505
506/*
507 *  _Thread_Set_priority
508 *
509 *  DESCRIPTION:
510 *
511 *  This routine updates the priority related fields in the_thread
512 *  control block to indicate the current priority is now new_priority.
513 */
514
515void _Thread_Set_priority(
516  Thread_Control   *the_thread,
517  rtems_task_priority  new_priority
518);
519
520/*
521 *  _Thread_Change_mode
522 *
523 *  DESCRIPTION:
524 *
525 *  This routine changes the current values of the modes
526 *  indicated by mask of the calling thread are changed to that
527 *  indicated in mode_set.  The former mode of the thread is
528 *  returned in mode_set.  If the changes in the current mode
529 *  indicate that a thread dispatch operation may be necessary,
530 *  then need_dispatch is TRUE, otherwise it is FALSE.
531 */
532
533boolean _Thread_Change_mode(
534  rtems_mode  new_mode_set,
535  rtems_mode  mask,
536  rtems_mode *old_mode_set
537);
538
539/*
540 *  _Thread_Resume
541 *
542 *  DESCRIPTION:
543 *
544 *  This routine clears the SUSPENDED state for the_thread.  It performs
545 *  any necessary scheduling operations including the selection of
546 *  a new heir thread.
547 */
548
549STATIC INLINE void _Thread_Resume (
550  Thread_Control *the_thread
551);
552
553/*
554 *  _Thread_Unblock
555 *
556 *  DESCRIPTION:
557 *
558 *  This routine clears any blocking state for the_thread.  It performs
559 *  any necessary scheduling operations including the selection of
560 *  a new heir thread.
561 */
562
563STATIC INLINE void _Thread_Unblock (
564  Thread_Control *the_thread
565);
566
567/*
568 *  _Thread_Restart_self
569 *
570 *  DESCRIPTION:
571 *
572 *  This routine resets the current context of the calling thread
573 *  to that of its initial state.
574 */
575
576STATIC INLINE void _Thread_Restart_self( void );
577
578/*
579 *  _Thread_Calculate_heir
580 *
581 *  DESCRIPTION:
582 *
583 *  This function returns a pointer to the highest priority
584 *  ready thread.
585 */
586
587STATIC INLINE void _Thread_Calculate_heir( void );
588
589/*
590 *  _Thread_Is_allocated_fp
591 *
592 *  DESCRIPTION:
593 *
594 *  This function returns TRUE if the floating point context of
595 *  the_thread is currently loaded in the floating point unit, and
596 *  FALSE otherwise.
597 */
598
599STATIC INLINE boolean _Thread_Is_allocated_fp (
600  Thread_Control *the_thread
601);
602
603/*
604 *  _Thread_Deallocate_fp
605 *
606 *  DESCRIPTION:
607 *
608 *  This routine is invoked when the currently loaded floating
609 *  point context is now longer associated with an active thread.
610 */
611
612STATIC INLINE void _Thread_Deallocate_fp( void );
613
614/*
615 *  _Thread_Disable_dispatch
616 *
617 *  DESCRIPTION:
618 *
619 *  This routine prevents dispatching.
620 */
621
622STATIC INLINE void _Thread_Disable_dispatch( void );
623
624/*
625 *  _Thread_Enable_dispatch
626 *
627 *  DESCRIPTION:
628 *
629 *  This routine allows dispatching to occur again.  If this is
630 *  the outer most dispatching critical section, then a dispatching
631 *  operation will be performed and, if necessary, control of the
632 *  processor will be transferred to the heir thread.
633 */
634
635#if ( CPU_INLINE_ENABLE_DISPATCH == TRUE )
636
637STATIC INLINE void _Thread_Enable_dispatch();
638
639#endif
640
641#if ( CPU_INLINE_ENABLE_DISPATCH == FALSE )
642
643void _Thread_Enable_dispatch( void );
644
645#endif
646
647/*
648 *  _Thread_Unnest_dispatch
649 *
650 *  DESCRIPTION:
651 *
652 *  This routine allows dispatching to occur again.  However,
653 *  no dispatching operation is performed even if this is the outer
654 *  most dispatching critical section.
655 */
656
657STATIC INLINE void _Thread_Unnest_dispatch( void );
658
659/*
660 *  _Thread_Is_dispatching_enabled
661 *
662 *  DESCRIPTION:
663 *
664 *  This function returns TRUE if dispatching is disabled, and FALSE
665 *  otherwise.
666 */
667
668STATIC INLINE boolean _Thread_Is_dispatching_enabled( void );
669
670/*
671 *  _Thread_Is_context_switch_necessary
672 *
673 *  DESCRIPTION:
674 *
675 *  This function returns TRUE if dispatching is disabled, and FALSE
676 *  otherwise.
677 */
678
679STATIC INLINE boolean _Thread_Is_context_switch_necessary( void );
680
681/*
682 *  _Thread_Is_null
683 *
684 *  DESCRIPTION:
685 *
686 *  This function returns TRUE if the_thread is NULL and FALSE otherwise.
687 */
688
689STATIC INLINE boolean _Thread_Is_null (
690  Thread_Control *the_thread
691);
692
693/*
694 *  _Thread_Get
695 *
696 *  DESCRIPTION:
697 *
698 *  This function maps thread IDs to thread control
699 *  blocks.  If ID corresponds to a local thread, then it
700 *  returns the_thread control pointer which maps to ID
701 *  and location is set to OBJECTS_LOCAL.  If the thread ID is
702 *  global and resides on a remote node, then location is set
703 *  to OBJECTS_REMOTE, and the_thread is undefined.
704 *  Otherwise, location is set to OBJECTS_ERROR and
705 *  the_thread is undefined.
706 */
707
708STATIC INLINE Thread_Control *_Thread_Get (
709  Objects_Id         id,
710  Objects_Locations *location
711);
712
713#include <rtems/thread.inl>
714#include <rtems/threadmp.h>
715
716#ifdef __cplusplus
717}
718#endif
719
720#endif
721/* end of include file */
Note: See TracBrowser for help on using the repository browser.