source: rtems/cpukit/score/include/rtems/score/thread.h @ bd67d7d2

4.11
Last change on this file since bd67d7d2 was bd67d7d2, checked in by Sebastian Huber <sebastian.huber@…>, on Jun 25, 2015 at 11:48:00 AM

score: Simplify <rtems/score/thread.h>

Avoid Thread_Control typedef in <rtems/score/percpu.h>. This helps to
get rid of the <rtems/score/percpu.h> include in <rtems/score/thread.h>
which exposes a lot of implementation details.

  • Property mode set to 100644
File size: 27.7 KB
Line 
1/**
2 *  @file  rtems/score/thread.h
3 *
4 *  @brief Constants and Structures Related with the Thread Control Block
5 *
6 *  This include file contains all constants and structures associated
7 *  with the thread control block.
8 */
9
10/*
11 *  COPYRIGHT (c) 1989-2014.
12 *  On-Line Applications Research Corporation (OAR).
13 *
14 *  Copyright (c) 2014 embedded brains GmbH.
15 *
16 *  The license and distribution terms for this file may be
17 *  found in the file LICENSE in this distribution or at
18 *  http://www.rtems.org/license/LICENSE.
19 */
20
21#ifndef _RTEMS_SCORE_THREAD_H
22#define _RTEMS_SCORE_THREAD_H
23
24#include <rtems/score/atomic.h>
25#include <rtems/score/context.h>
26#if defined(RTEMS_MULTIPROCESSING)
27#include <rtems/score/mppkt.h>
28#endif
29#include <rtems/score/isrlock.h>
30#include <rtems/score/object.h>
31#include <rtems/score/priority.h>
32#include <rtems/score/resource.h>
33#include <rtems/score/stack.h>
34#include <rtems/score/states.h>
35#include <rtems/score/threadq.h>
36#include <rtems/score/watchdog.h>
37
38#if defined(RTEMS_SMP)
39  #include <rtems/score/cpuset.h>
40#endif
41
42struct Per_CPU_Control;
43
44struct Scheduler_Control;
45
46struct Scheduler_Node;
47
48#ifdef __cplusplus
49extern "C" {
50#endif
51
52/**
53 *  @defgroup ScoreThread Thread Handler
54 *
55 *  @ingroup Score
56 *
57 *  This handler encapsulates functionality related to the management of
58 *  threads.  This includes the creation, deletion, and scheduling of threads.
59 *
60 *  The following variables are maintained as part of the per cpu data
61 *  structure.
62 *
63 *  + Idle thread pointer
64 *  + Executing thread pointer
65 *  + Heir thread pointer
66 */
67/**@{*/
68
69#if defined(RTEMS_POSIX_API)
70  #define RTEMS_SCORE_THREAD_ENABLE_EXHAUST_TIMESLICE
71#endif
72
73/*
74 * With the addition of the Constant Block Scheduler (CBS),
75 * this feature is needed even when POSIX is disabled.
76 */
77#define RTEMS_SCORE_THREAD_ENABLE_SCHEDULER_CALLOUT
78
79#if defined(RTEMS_POSIX_API)
80  #define RTEMS_SCORE_THREAD_ENABLE_USER_PROVIDED_STACK_VIA_API
81#endif
82
83/*
84 *  The user can define this at configure time and go back to ticks
85 *  resolution.
86 */
87#include <rtems/score/timestamp.h>
88
89typedef Timestamp_Control Thread_CPU_usage_t;
90
91/**
92 *  The following defines the "return type" of a thread.
93 *
94 *  @note  This cannot always be right.  Some APIs have void
95 *         tasks/threads, others return pointers, others may
96 *         return a numeric value.  Hopefully a pointer is
97 *         always at least as big as an uint32_t  . :)
98 */
99typedef void *Thread;
100
101/**
102 *  @brief Type of the numeric argument of a thread entry function with at
103 *  least one numeric argument.
104 *
105 *  This numeric argument type designates an unsigned integer type with the
106 *  property that any valid pointer to void can be converted to this type and
107 *  then converted back to a pointer to void.  The result will compare equal to
108 *  the original pointer.
109 */
110typedef CPU_Uint32ptr Thread_Entry_numeric_type;
111
112/**
113 *  The following defines the ways in which the entry point for a
114 *  thread can be invoked.  Basically, it can be passed any
115 *  combination/permutation of a pointer and an uint32_t   value.
116 *
117 *  @note For now, we are ignoring the return type.
118 */
119typedef enum {
120  THREAD_START_NUMERIC,
121  THREAD_START_POINTER,
122  #if defined(FUNCTIONALITY_NOT_CURRENTLY_USED_BY_ANY_API)
123    THREAD_START_BOTH_POINTER_FIRST,
124    THREAD_START_BOTH_NUMERIC_FIRST
125  #endif
126} Thread_Start_types;
127
128/** This type corresponds to a very simple style thread entry point. */
129typedef Thread ( *Thread_Entry )( void );   /* basic type */
130
131/** This type corresponds to a thread entry point which takes a single
132 *  unsigned thirty-two bit integer as an argument.
133 */
134typedef Thread ( *Thread_Entry_numeric )( Thread_Entry_numeric_type );
135
136/** This type corresponds to a thread entry point which takes a single
137 *  untyped pointer as an argument.
138 */
139typedef Thread ( *Thread_Entry_pointer )( void * );
140
141/** This type corresponds to a thread entry point which takes a single
142 *  untyped pointer and an unsigned thirty-two bit integer as arguments.
143 */
144typedef Thread ( *Thread_Entry_both_pointer_first )( void *, Thread_Entry_numeric_type );
145
146/** This type corresponds to a thread entry point which takes a single
147 *  unsigned thirty-two bit integer and an untyped pointer and an
148 *  as arguments.
149 */
150typedef Thread ( *Thread_Entry_both_numeric_first )( Thread_Entry_numeric_type, void * );
151
152/**
153 *  The following lists the algorithms used to manage the thread cpu budget.
154 *
155 *  Reset Timeslice:   At each context switch, reset the time quantum.
156 *  Exhaust Timeslice: Only reset the quantum once it is consumed.
157 *  Callout:           Execute routine when budget is consumed.
158 */
159typedef enum {
160  THREAD_CPU_BUDGET_ALGORITHM_NONE,
161  THREAD_CPU_BUDGET_ALGORITHM_RESET_TIMESLICE,
162  #if defined(RTEMS_SCORE_THREAD_ENABLE_EXHAUST_TIMESLICE)
163    THREAD_CPU_BUDGET_ALGORITHM_EXHAUST_TIMESLICE,
164  #endif
165  #if defined(RTEMS_SCORE_THREAD_ENABLE_SCHEDULER_CALLOUT)
166    THREAD_CPU_BUDGET_ALGORITHM_CALLOUT
167  #endif
168}  Thread_CPU_budget_algorithms;
169
170/**  This defines thes the entry point for the thread specific timeslice
171 *   budget management algorithm.
172 */
173typedef void (*Thread_CPU_budget_algorithm_callout )( Thread_Control * );
174
175#if !defined(RTEMS_SMP)
176/**
177 *  @brief Forward reference to the per task variable structure..
178 *
179 *  Forward reference to the per task variable structure.
180 */
181struct rtems_task_variable_tt;
182
183/**
184 *  @brief Internal structure used to manager per task variables.
185 *
186 *  This is the internal structure used to manager per Task Variables.
187 */
188typedef struct {
189  /** This field points to the next per task variable for this task. */
190  struct rtems_task_variable_tt  *next;
191  /** This field points to the physical memory location of this per
192   *  task variable.
193   */
194  void                          **ptr;
195  /** This field is to the global value for this per task variable. */
196  void                           *gval;
197  /** This field is to this thread's value for this per task variable. */
198  void                           *tval;
199  /** This field points to the destructor for this per task variable. */
200  void                          (*dtor)(void *);
201} rtems_task_variable_t;
202#endif
203
204/**
205 *  The following structure contains the information which defines
206 *  the starting state of a thread.
207 */
208typedef struct {
209  /** This field is the starting address for the thread. */
210  Thread_Entry                         entry_point;
211  /** This field indicates the how task is invoked. */
212  Thread_Start_types                   prototype;
213  /** This field is the pointer argument passed at thread start. */
214  void                                *pointer_argument;
215  /** This field is the numeric argument passed at thread start. */
216  Thread_Entry_numeric_type            numeric_argument;
217  /*-------------- initial execution modes ----------------- */
218  /** This field indicates whether the thread was preemptible when
219    * it started.
220    */
221  bool                                 is_preemptible;
222  /** This field indicates the CPU budget algorith. */
223  Thread_CPU_budget_algorithms         budget_algorithm;
224  /** This field is the routine to invoke when the CPU allotment is
225   *  consumed.
226   */
227  Thread_CPU_budget_algorithm_callout  budget_callout;
228  /** This field is the initial ISR disable level of this thread. */
229  uint32_t                             isr_level;
230  /** This field is the initial priority. */
231  Priority_Control                     initial_priority;
232  #if defined(RTEMS_SCORE_THREAD_ENABLE_USER_PROVIDED_STACK_VIA_API)
233    /** This field indicates whether the SuperCore allocated the stack. */
234    bool                                 core_allocated_stack;
235  #endif
236  /** This field is the stack information. */
237  Stack_Control                        Initial_stack;
238  #if ( CPU_HARDWARE_FP == TRUE ) || ( CPU_SOFTWARE_FP == TRUE )
239    /** This field is the initial FP context area address. */
240    Context_Control_fp                  *fp_context;
241  #endif
242  /** This field is the initial stack area address. */
243  void                                *stack;
244  /** The thread-local storage (TLS) area */
245  void                                *tls_area;
246} Thread_Start_information;
247
248/**
249 *  @brief Union type to hold a pointer to an immutable or a mutable object.
250 *
251 *  The main purpose is to enable passing of pointers to read-only send buffers
252 *  in the message passing subsystem.  This approach is somewhat fragile since
253 *  it prevents the compiler to check if the operations on objects are valid
254 *  with respect to the constant qualifier.  An alternative would be to add a
255 *  third pointer argument for immutable objects, but this would increase the
256 *  structure size.
257 */
258typedef union {
259  void       *mutable_object;
260  const void *immutable_object;
261} Thread_Wait_information_Object_argument_type;
262
263/**
264 * @brief This type is able to contain several flags used to control the wait
265 * class and state of a thread.
266 *
267 * The mutually exclusive wait class flags are
268 * - @ref THREAD_WAIT_CLASS_EVENT,
269 * - @ref THREAD_WAIT_CLASS_SYSTEM_EVENT, and
270 * - @ref THREAD_WAIT_CLASS_OBJECT.
271 *
272 * The mutually exclusive wait state flags are
273 * - @ref THREAD_WAIT_STATE_INTEND_TO_BLOCK,
274 * - @ref THREAD_WAIT_STATE_BLOCKED, and
275 * - @ref THREAD_WAIT_STATE_READY_AGAIN.
276 */
277typedef unsigned int Thread_Wait_flags;
278
279/**
280 *  @brief Information required to manage a thread while it is blocked.
281 *
282 *  This contains the information required to manage a thread while it is
283 *  blocked and to return information to it.
284 */
285typedef struct {
286  /**
287   * @brief Node for thread queues.
288   */
289  union {
290    /**
291     * @brief A node for chains.
292     */
293    Chain_Node Chain;
294
295    /**
296     * @brief A node for red-black trees.
297     */
298    RBTree_Node RBTree;
299  } Node;
300
301  /** This field is the Id of the object this thread is waiting upon. */
302  Objects_Id            id;
303  /** This field is used to return an integer while when blocked. */
304  uint32_t              count;
305  /** This field is for a pointer to a user return argument. */
306  void                 *return_argument;
307  /** This field is for a pointer to a second user return argument. */
308  Thread_Wait_information_Object_argument_type
309                        return_argument_second;
310  /** This field contains any options in effect on this blocking operation. */
311  uint32_t              option;
312  /** This field will contain the return status from a blocking operation.
313   *
314   *  @note The following assumes that all API return codes can be
315   *        treated as an uint32_t.
316   */
317  uint32_t              return_code;
318
319  /**
320   * @brief Code to set the timeout return code in _Thread_Timeout().
321   */
322  uint32_t timeout_code;
323
324  /**
325   * @brief The current thread queue.
326   *
327   * In case this field is @c NULL, then the thread is not blocked on a thread
328   * queue.  This field is protected by the thread lock.
329   *
330   * @see _Thread_Lock_set() and _Thread_Wait_set_queue().
331   */
332  Thread_queue_Control *queue;
333
334  /**
335   * @brief This field contains several flags used to control the wait class
336   * and state of a thread in case fine-grained locking is used.
337   */
338#if defined(RTEMS_SMP)
339  Atomic_Uint           flags;
340#else
341  Thread_Wait_flags     flags;
342#endif
343
344  /**
345   * @brief The current thread queue operations.
346   *
347   * This field is protected by the thread lock.
348   *
349   * @see _Thread_Lock_set() and _Thread_Wait_set_operations().
350   */
351  const Thread_queue_Operations *operations;
352}   Thread_Wait_information;
353
354/**
355 *  The following defines the control block used to manage
356 *  each thread proxy.
357 *
358 *  @note It is critical that proxies and threads have identical
359 *        memory images for the shared part.
360 */
361typedef struct {
362  /** This field is the object management structure for each proxy. */
363  Objects_Control          Object;
364  /** This field is the current execution state of this proxy. */
365  States_Control           current_state;
366
367  /**
368   * @brief This field is the current priority state of this thread.
369   *
370   * Writes to this field are only allowed in _Thread_Initialize() or via
371   * _Thread_Change_priority().
372   */
373  Priority_Control         current_priority;
374
375  /**
376   * @brief This field is the base priority of this thread.
377   *
378   * Writes to this field are only allowed in _Thread_Initialize() or via
379   * _Thread_Change_priority().
380   */
381  Priority_Control         real_priority;
382
383  /**
384   * @brief Generation of the current priority value.
385   *
386   * It is used in _Thread_Change_priority() to serialize the update of
387   * priority related data structures.
388   */
389  uint32_t                 priority_generation;
390
391  /**
392   * @brief Hints if a priority restore is necessary once the resource count
393   * changes from one to zero.
394   *
395   * This is an optimization to speed up the mutex surrender sequence in case
396   * no attempt to change the priority was made during the mutex ownership.  On
397   * SMP configurations atomic fences must synchronize writes to
398   * Thread_Control::priority_restore_hint and Thread_Control::resource_count.
399   */
400  bool                     priority_restore_hint;
401
402  /** This field is the number of mutexes currently held by this proxy. */
403  uint32_t                 resource_count;
404
405  /** This field is the blocking information for this proxy. */
406  Thread_Wait_information  Wait;
407  /** This field is the Watchdog used to manage proxy delays and timeouts. */
408  Watchdog_Control         Timer;
409#if defined(RTEMS_MULTIPROCESSING)
410  /** This field is the received response packet in an MP system. */
411  MP_packet_Prefix        *receive_packet;
412#endif
413     /****************** end of common block ********************/
414  /** This field is used to manage the set of proxies in the system. */
415  Chain_Node               Active;
416}   Thread_Proxy_control;
417
418/**
419 *  The following record defines the control block used
420 *  to manage each thread.
421 *
422 *  @note It is critical that proxies and threads have identical
423 *        memory images for the shared part.
424 */
425typedef enum {
426  /** This value is for the Classic RTEMS API. */
427  THREAD_API_RTEMS,
428  /** This value is for the POSIX API. */
429  THREAD_API_POSIX
430}  Thread_APIs;
431
432/** This macro defines the first API which has threads. */
433#define THREAD_API_FIRST THREAD_API_RTEMS
434
435/** This macro defines the last API which has threads. */
436#define THREAD_API_LAST  THREAD_API_POSIX
437
438typedef struct Thread_Action Thread_Action;
439
440/**
441 * @brief Thread action handler.
442 *
443 * The thread action handler will be called with interrupts disabled and the
444 * thread action lock acquired.  The handler must release the thread action
445 * lock with _Thread_Action_release_and_ISR_enable().  So the thread action
446 * lock can be used to protect private data fields of the particular action.
447 *
448 * Since the action is passed to the handler private data fields can be added
449 * below the common thread action fields.
450 *
451 * @param[in] thread The thread performing the action.
452 * @param[in] action The thread action.
453 * @param[in] cpu The processor of the thread.
454 * @param[in] level The ISR level for _Thread_Action_release_and_ISR_enable().
455 */
456typedef void ( *Thread_Action_handler )(
457  Thread_Control         *thread,
458  Thread_Action          *action,
459  struct Per_CPU_Control *cpu,
460  ISR_Level               level
461);
462
463/**
464 * @brief Thread action.
465 *
466 * Thread actions can be chained together to trigger a set of actions on
467 * particular events like for example a thread post-switch.  Use
468 * _Thread_Action_initialize() to initialize this structure.
469 *
470 * Thread actions are the building block for efficient implementation of
471 * - Classic signals delivery,
472 * - POSIX signals delivery,
473 * - thread restart notification,
474 * - thread delete notification,
475 * - forced thread migration on SMP configurations, and
476 * - the Multiprocessor Resource Sharing Protocol (MrsP).
477 *
478 * @see _Thread_Run_post_switch_actions().
479 */
480struct Thread_Action {
481  Chain_Node            Node;
482  Thread_Action_handler handler;
483};
484
485/**
486 * @brief Control block to manage thread actions.
487 *
488 * Use _Thread_Action_control_initialize() to initialize this structure.
489 */
490typedef struct {
491  Chain_Control Chain;
492} Thread_Action_control;
493
494/**
495 * @brief Thread life states.
496 *
497 * The thread life states are orthogonal to the thread states used for
498 * synchronization primitives and blocking operations.  They reflect the state
499 * changes triggered with thread restart and delete requests.
500 */
501typedef enum {
502  THREAD_LIFE_NORMAL = 0x0,
503  THREAD_LIFE_PROTECTED = 0x1,
504  THREAD_LIFE_RESTARTING = 0x2,
505  THREAD_LIFE_PROTECTED_RESTARTING = 0x3,
506  THREAD_LIFE_TERMINATING = 0x4,
507  THREAD_LIFE_PROTECTED_TERMINATING = 0x5,
508  THREAD_LIFE_RESTARTING_TERMINATING = 0x6,
509  THREAD_LIFE_PROTECTED_RESTARTING_TERMINATING = 0x7
510} Thread_Life_state;
511
512/**
513 * @brief Thread life control.
514 */
515typedef struct {
516  /**
517   * @brief Thread life action used to react upon thread restart and delete
518   * requests.
519   */
520  Thread_Action      Action;
521
522  /**
523   * @brief The current thread life state.
524   */
525  Thread_Life_state  state;
526
527  /**
528   * @brief The terminator thread of this thread.
529   *
530   * In case the thread is terminated and another thread (the terminator) waits
531   * for the actual termination completion, then this field references the
532   * terminator thread.
533   */
534  Thread_Control    *terminator;
535} Thread_Life_control;
536
537#if defined(RTEMS_SMP)
538/**
539 * @brief The thread state with respect to the scheduler.
540 */
541typedef enum {
542  /**
543   * @brief This thread is blocked with respect to the scheduler.
544   *
545   * This thread uses no scheduler nodes.
546   */
547  THREAD_SCHEDULER_BLOCKED,
548
549  /**
550   * @brief This thread is scheduled with respect to the scheduler.
551   *
552   * This thread executes using one of its scheduler nodes.  This could be its
553   * own scheduler node or in case it owns resources taking part in the
554   * scheduler helping protocol a scheduler node of another thread.
555   */
556  THREAD_SCHEDULER_SCHEDULED,
557
558  /**
559   * @brief This thread is ready with respect to the scheduler.
560   *
561   * None of the scheduler nodes of this thread is scheduled.
562   */
563  THREAD_SCHEDULER_READY
564} Thread_Scheduler_state;
565#endif
566
567/**
568 * @brief Thread scheduler control.
569 */
570typedef struct {
571#if defined(RTEMS_SMP)
572  /**
573   * @brief The current scheduler state of this thread.
574   */
575  Thread_Scheduler_state state;
576
577  /**
578   * @brief The own scheduler control of this thread.
579   *
580   * This field is constant after initialization.
581   */
582  const struct Scheduler_Control *own_control;
583
584  /**
585   * @brief The scheduler control of this thread.
586   *
587   * The scheduler helping protocol may change this field.
588   */
589  const struct Scheduler_Control *control;
590
591  /**
592   * @brief The own scheduler node of this thread.
593   *
594   * This field is constant after initialization.  It is used by change
595   * priority and ask for help operations.
596   */
597  struct Scheduler_Node *own_node;
598#endif
599
600  /**
601   * @brief The scheduler node of this thread.
602   *
603   * On uni-processor configurations this field is constant after
604   * initialization.
605   *
606   * On SMP configurations the scheduler helping protocol may change this
607   * field.
608   */
609  struct Scheduler_Node *node;
610
611#if defined(RTEMS_SMP)
612  /**
613   * @brief The processor assigned by the current scheduler.
614   */
615  struct Per_CPU_Control *cpu;
616
617#if defined(RTEMS_DEBUG)
618  /**
619   * @brief The processor on which this thread executed the last time or is
620   * executing.
621   */
622  struct Per_CPU_Control *debug_real_cpu;
623#endif
624#endif
625} Thread_Scheduler_control;
626
627typedef struct  {
628  uint32_t      flags;
629  void *        control;
630}Thread_Capture_control;
631
632#if defined(RTEMS_SMP)
633/**
634 * @brief Thread lock control.
635 *
636 * The thread lock is either the default lock or the lock of the resource on
637 * which the thread is currently blocked.  The generation number takes care
638 * that the up to date lock is used.  Only resources using fine grained locking
639 * provide their own lock.
640 *
641 * The thread lock protects the following thread variables
642 *  - Thread_Control::current_priority,
643 *  - Thread_Control::Wait::queue, and
644 *  - Thread_Control::Wait::operations.
645 *
646 * @see _Thread_Lock_acquire(), _Thread_Lock_release(), _Thread_Lock_set() and
647 * _Thread_Lock_restore_default().
648 */
649typedef struct {
650  /**
651   * @brief The current thread lock.
652   */
653  ISR_lock_Control *current;
654
655  /**
656   * @brief The default thread lock in case the thread is not blocked on a
657   * resource.
658   */
659  ISR_lock_Control Default;
660
661  /**
662   * @brief Generation number to invalidate stale locks.
663   */
664  Atomic_Uint generation;
665} Thread_Lock_control;
666#endif
667
668/**
669 *  This structure defines the Thread Control Block (TCB).
670 */
671struct Thread_Control {
672  /** This field is the object management structure for each thread. */
673  Objects_Control          Object;
674  /** This field is the current execution state of this thread. */
675  States_Control           current_state;
676
677  /**
678   * @brief This field is the current priority state of this thread.
679   *
680   * Writes to this field are only allowed in _Thread_Initialize() or via
681   * _Thread_Change_priority().
682   */
683  Priority_Control         current_priority;
684
685  /**
686   * @brief This field is the base priority of this thread.
687   *
688   * Writes to this field are only allowed in _Thread_Initialize() or via
689   * _Thread_Change_priority().
690   */
691  Priority_Control         real_priority;
692
693  /**
694   * @brief Generation of the current priority value.
695   *
696   * It is used in _Thread_Change_priority() to serialize the update of
697   * priority related data structures.
698   */
699  uint32_t                 priority_generation;
700
701  /**
702   * @brief Hints if a priority restore is necessary once the resource count
703   * changes from one to zero.
704   *
705   * This is an optimization to speed up the mutex surrender sequence in case
706   * no attempt to change the priority was made during the mutex ownership.  On
707   * SMP configurations atomic fences must synchronize writes to
708   * Thread_Control::priority_restore_hint and Thread_Control::resource_count.
709   */
710  bool                     priority_restore_hint;
711
712  /** This field is the number of mutexes currently held by this thread. */
713  uint32_t                 resource_count;
714  /** This field is the blocking information for this thread. */
715  Thread_Wait_information  Wait;
716  /** This field is the Watchdog used to manage thread delays and timeouts. */
717  Watchdog_Control         Timer;
718#if defined(RTEMS_MULTIPROCESSING)
719  /** This field is the received response packet in an MP system. */
720  MP_packet_Prefix        *receive_packet;
721#endif
722     /*================= end of common block =================*/
723
724#if defined(RTEMS_SMP)
725  /**
726   * @brief Thread lock control.
727   */
728  Thread_Lock_control Lock;
729#endif
730
731#ifdef __RTEMS_STRICT_ORDER_MUTEX__
732  /** This field is the head of queue of priority inheritance mutex
733   *  held by the thread.
734   */
735  Chain_Control            lock_mutex;
736#endif
737#if defined(RTEMS_SMP)
738  /**
739   * @brief Resource node to build a dependency tree in case this thread owns
740   * resources or depends on a resource.
741   */
742  Resource_Node            Resource_node;
743#endif
744#if defined(RTEMS_MULTIPROCESSING)
745  /** This field is true if the thread is offered globally */
746  bool                                  is_global;
747#endif
748  /** This field is true if the thread is preemptible. */
749  bool                                  is_preemptible;
750  /** This field is true if the thread uses the floating point unit. */
751  bool                                  is_fp;
752
753  /**
754   * @brief Scheduler related control.
755   */
756  Thread_Scheduler_control              Scheduler;
757
758#if __RTEMS_ADA__
759  /** This field is the GNAT self context pointer. */
760  void                                 *rtems_ada_self;
761#endif
762  /** This field is the length of the time quantum that this thread is
763   *  allowed to consume.  The algorithm used to manage limits on CPU usage
764   *  is specified by budget_algorithm.
765   */
766  uint32_t                              cpu_time_budget;
767  /** This field is the algorithm used to manage this thread's time
768   *  quantum.  The algorithm may be specified as none which case,
769   *  no limit is in place.
770   */
771  Thread_CPU_budget_algorithms          budget_algorithm;
772  /** This field is the method invoked with the budgeted time is consumed. */
773  Thread_CPU_budget_algorithm_callout   budget_callout;
774  /** This field is the amount of CPU time consumed by this thread
775   *  since it was created.
776   */
777  Thread_CPU_usage_t                    cpu_time_used;
778
779  /** This field contains information about the starting state of
780   *  this thread.
781   */
782  Thread_Start_information              Start;
783
784  Thread_Action_control                 Post_switch_actions;
785
786  /** This field contains the context of this thread. */
787  Context_Control                       Registers;
788#if ( CPU_HARDWARE_FP == TRUE ) || ( CPU_SOFTWARE_FP == TRUE )
789  /** This field points to the floating point context for this thread.
790   *  If NULL, the thread is integer only.
791   */
792  Context_Control_fp                   *fp_context;
793#endif
794  /** This field points to the newlib reentrancy structure for this thread. */
795  struct _reent                        *libc_reent;
796  /** This array contains the API extension area pointers. */
797  void                                 *API_Extensions[ THREAD_API_LAST + 1 ];
798
799#if !defined(RTEMS_SMP)
800  /** This field points to the set of per task variables. */
801  rtems_task_variable_t                *task_variables;
802#endif
803
804  /**
805   * This is the thread key value chain's control, which is used
806   * to track all key value for specific thread, and when thread
807   * exits, we can remove all key value for specific thread by
808   * iterating this chain, or we have to search a whole rbtree,
809   * which is inefficient.
810   */
811  Chain_Control           Key_Chain;
812
813  /**
814   * @brief Thread life-cycle control.
815   *
816   * Control state changes triggered by thread restart and delete requests.
817   */
818  Thread_Life_control                   Life;
819
820  Thread_Capture_control                Capture;
821
822  /**
823   * @brief Variable length array of user extension pointers.
824   *
825   * The length is defined by the application via <rtems/confdefs.h>.
826   */
827  void                                 *extensions[ RTEMS_ZERO_LENGTH_ARRAY ];
828};
829
830#if (CPU_PROVIDES_IDLE_THREAD_BODY == FALSE)
831/**
832 *  This routine is the body of the system idle thread.
833 *
834 *  NOTE: This routine is actually instantiated by confdefs.h when needed.
835 */
836void *_Thread_Idle_body(
837  uintptr_t  ignored
838);
839#endif
840
841/**  This defines the type for a method which operates on a single thread.
842 */
843typedef void (*rtems_per_thread_routine)( Thread_Control * );
844
845/**
846 *  @brief Iterates over all threads.
847 *  This routine iterates over all threads regardless of API and
848 *  invokes the specified routine.
849 */
850void rtems_iterate_over_all_threads(
851  rtems_per_thread_routine routine
852);
853
854/**
855 * @brief Thread control add-on.
856 */
857typedef struct {
858  /**
859   * @brief Offset of the pointer field in Thread_Control referencing an
860   * application configuration dependent memory area in the thread control
861   * block.
862   */
863  size_t destination_offset;
864
865  /**
866   * @brief Offset relative to the thread control block begin to an application
867   * configuration dependent memory area.
868   */
869  size_t source_offset;
870} Thread_Control_add_on;
871
872/**
873 * @brief Thread control add-ons.
874 *
875 * The thread control block contains fields that point to application
876 * configuration dependent memory areas, like the scheduler information, the
877 * API control blocks, the user extension context table, the RTEMS notepads and
878 * the Newlib re-entrancy support.  Account for these areas in the
879 * configuration and avoid extra workspace allocations for these areas.
880 *
881 * This array is provided via <rtems/confdefs.h>.
882 *
883 * @see _Thread_Control_add_on_count and _Thread_Control_size.
884 */
885extern const Thread_Control_add_on _Thread_Control_add_ons[];
886
887/**
888 * @brief Thread control add-on count.
889 *
890 * Count of entries in _Thread_Control_add_ons.
891 *
892 * This value is provided via <rtems/confdefs.h>.
893 */
894extern const size_t _Thread_Control_add_on_count;
895
896/**
897 * @brief Size of the thread control block of a particular application.
898 *
899 * This value is provided via <rtems/confdefs.h>.
900 *
901 * @see _Thread_Control_add_ons.
902 */
903extern const size_t _Thread_Control_size;
904
905/**@}*/
906
907#ifdef __cplusplus
908}
909#endif
910
911#endif
912/* end of include file */
Note: See TracBrowser for help on using the repository browser.