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

4.104.114.84.95
Last change on this file since 95fbca1 was 95fbca1, checked in by Joel Sherrill <joel.sherrill@…>, on 08/18/95 at 21:41:27

+ Added object type field to object id.

+ Added name pointer to Object_Control.

+ Modified Object Open and Close to address name field.

+ Removed name as separate element from Thread and Proxy Control.

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