source: rtems/cpukit/score/include/rtems/score/thread.h @ 4d9fa26

4.104.114.84.95
Last change on this file since 4d9fa26 was 4d9fa26, checked in by Joel Sherrill <joel.sherrill@…>, on 08/11/95 at 14:13:51

added constant for number of notepads

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