source: rtems/cpukit/score/include/rtems/score/thread.h @ 5250ff39

4.104.114.84.95
Last change on this file since 5250ff39 was 5250ff39, checked in by Joel Sherrill <joel.sherrill@…>, on 08/23/95 at 21:06:31

Moved _Thread_Information -> _RTEMS_tasks_Information.

Added a table of object information control blocks.

Modified _Thread_Get so it looks up a thread regardless of which
thread management "entity" (manager, internal, etc) actually "owns" it.

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