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

5
Last change on this file since ccd5434 was ccd5434, checked in by Sebastian Huber <sebastian.huber@…>, on 01/07/16 at 08:55:45

score: Introduce Thread_Entry_information

This avoids potential dead code in _Thread_Handler(). It gets rid of
the dangerous function pointer casts.

Update #2514.

  • Property mode set to 100644
File size: 27.9 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 * Only provided for backward compatiblity to not break application
93 * configurations.
94 */
95typedef void *Thread RTEMS_DEPRECATED;
96
97/**
98 *  @brief Type of the numeric argument of a thread entry function with at
99 *  least one numeric argument.
100 *
101 *  This numeric argument type designates an unsigned integer type with the
102 *  property that any valid pointer to void can be converted to this type and
103 *  then converted back to a pointer to void.  The result will compare equal to
104 *  the original pointer.
105 */
106typedef CPU_Uint32ptr Thread_Entry_numeric_type;
107
108/**
109 * @brief Data for idle thread entry.
110 */
111typedef struct {
112  void *( *entry )( uintptr_t argument );
113} Thread_Entry_idle;
114
115/**
116 * @brief Data for thread entry with one numeric argument and no return value.
117 */
118typedef struct {
119  void ( *entry )( Thread_Entry_numeric_type argument );
120  Thread_Entry_numeric_type argument;
121} Thread_Entry_numeric;
122
123/**
124 * @brief Data for thread entry with one pointer argument and a pointer return
125 * value.
126 */
127typedef struct {
128  void *( *entry )( void *argument  );
129  void *argument;
130} Thread_Entry_pointer;
131
132/**
133 * @brief Thread entry information.
134 */
135typedef struct {
136  /**
137   * @brief Thread entry adaptor.
138   *
139   * Calls the corresponding thread entry with the right parameters.
140   *
141   * @param executing The executing thread.
142   */
143  void ( *adaptor )( Thread_Control *executing );
144
145  /**
146   * @brief Thread entry data used by the adaptor to call the thread entry
147   * function with the right parameters.
148   */
149  union {
150    Thread_Entry_idle Idle;
151    Thread_Entry_numeric Numeric;
152    Thread_Entry_pointer Pointer;
153  } Kinds;
154} Thread_Entry_information;
155
156/**
157 *  The following lists the algorithms used to manage the thread cpu budget.
158 *
159 *  Reset Timeslice:   At each context switch, reset the time quantum.
160 *  Exhaust Timeslice: Only reset the quantum once it is consumed.
161 *  Callout:           Execute routine when budget is consumed.
162 */
163typedef enum {
164  THREAD_CPU_BUDGET_ALGORITHM_NONE,
165  THREAD_CPU_BUDGET_ALGORITHM_RESET_TIMESLICE,
166  #if defined(RTEMS_SCORE_THREAD_ENABLE_EXHAUST_TIMESLICE)
167    THREAD_CPU_BUDGET_ALGORITHM_EXHAUST_TIMESLICE,
168  #endif
169  #if defined(RTEMS_SCORE_THREAD_ENABLE_SCHEDULER_CALLOUT)
170    THREAD_CPU_BUDGET_ALGORITHM_CALLOUT
171  #endif
172}  Thread_CPU_budget_algorithms;
173
174/**  This defines thes the entry point for the thread specific timeslice
175 *   budget management algorithm.
176 */
177typedef void (*Thread_CPU_budget_algorithm_callout )( Thread_Control * );
178
179#if !defined(RTEMS_SMP)
180/**
181 *  @brief Forward reference to the per task variable structure..
182 *
183 *  Forward reference to the per task variable structure.
184 */
185struct rtems_task_variable_tt;
186
187/**
188 *  @brief Internal structure used to manager per task variables.
189 *
190 *  This is the internal structure used to manager per Task Variables.
191 */
192typedef struct {
193  /** This field points to the next per task variable for this task. */
194  struct rtems_task_variable_tt  *next;
195  /** This field points to the physical memory location of this per
196   *  task variable.
197   */
198  void                          **ptr;
199  /** This field is to the global value for this per task variable. */
200  void                           *gval;
201  /** This field is to this thread's value for this per task variable. */
202  void                           *tval;
203  /** This field points to the destructor for this per task variable. */
204  void                          (*dtor)(void *);
205} rtems_task_variable_t;
206#endif
207
208/**
209 *  The following structure contains the information which defines
210 *  the starting state of a thread.
211 */
212typedef struct {
213  /** This field contains the thread entry information. */
214  Thread_Entry_information             Entry;
215  /*-------------- initial execution modes ----------------- */
216  /** This field indicates whether the thread was preemptible when
217    * it started.
218    */
219  bool                                 is_preemptible;
220  /** This field indicates the CPU budget algorith. */
221  Thread_CPU_budget_algorithms         budget_algorithm;
222  /** This field is the routine to invoke when the CPU allotment is
223   *  consumed.
224   */
225  Thread_CPU_budget_algorithm_callout  budget_callout;
226  /** This field is the initial ISR disable level of this thread. */
227  uint32_t                             isr_level;
228  /** This field is the initial priority. */
229  Priority_Control                     initial_priority;
230  #if defined(RTEMS_SCORE_THREAD_ENABLE_USER_PROVIDED_STACK_VIA_API)
231    /** This field indicates whether the SuperCore allocated the stack. */
232    bool                                 core_allocated_stack;
233  #endif
234  /** This field is the stack information. */
235  Stack_Control                        Initial_stack;
236  #if ( CPU_HARDWARE_FP == TRUE ) || ( CPU_SOFTWARE_FP == TRUE )
237    /** This field is the initial FP context area address. */
238    Context_Control_fp                  *fp_context;
239  #endif
240  /** This field is the initial stack area address. */
241  void                                *stack;
242  /** The thread-local storage (TLS) area */
243  void                                *tls_area;
244} Thread_Start_information;
245
246/**
247 *  @brief Union type to hold a pointer to an immutable or a mutable object.
248 *
249 *  The main purpose is to enable passing of pointers to read-only send buffers
250 *  in the message passing subsystem.  This approach is somewhat fragile since
251 *  it prevents the compiler to check if the operations on objects are valid
252 *  with respect to the constant qualifier.  An alternative would be to add a
253 *  third pointer argument for immutable objects, but this would increase the
254 *  structure size.
255 */
256typedef union {
257  void       *mutable_object;
258  const void *immutable_object;
259} Thread_Wait_information_Object_argument_type;
260
261/**
262 * @brief This type is able to contain several flags used to control the wait
263 * class and state of a thread.
264 *
265 * The mutually exclusive wait class flags are
266 * - @ref THREAD_WAIT_CLASS_EVENT,
267 * - @ref THREAD_WAIT_CLASS_SYSTEM_EVENT, and
268 * - @ref THREAD_WAIT_CLASS_OBJECT.
269 *
270 * The mutually exclusive wait state flags are
271 * - @ref THREAD_WAIT_STATE_INTEND_TO_BLOCK,
272 * - @ref THREAD_WAIT_STATE_BLOCKED, and
273 * - @ref THREAD_WAIT_STATE_READY_AGAIN.
274 */
275typedef unsigned int Thread_Wait_flags;
276
277/**
278 *  @brief Information required to manage a thread while it is blocked.
279 *
280 *  This contains the information required to manage a thread while it is
281 *  blocked and to return information to it.
282 */
283typedef struct {
284  /**
285   * @brief Node for thread queues.
286   */
287  union {
288    /**
289     * @brief A node for chains.
290     */
291    Chain_Node Chain;
292
293    /**
294     * @brief A node for red-black trees.
295     */
296    RBTree_Node RBTree;
297  } Node;
298
299  /** This field is the Id of the object this thread is waiting upon. */
300  Objects_Id            id;
301  /** This field is used to return an integer while when blocked. */
302  uint32_t              count;
303  /** This field is for a pointer to a user return argument. */
304  void                 *return_argument;
305  /** This field is for a pointer to a second user return argument. */
306  Thread_Wait_information_Object_argument_type
307                        return_argument_second;
308  /** This field contains any options in effect on this blocking operation. */
309  uint32_t              option;
310  /** This field will contain the return status from a blocking operation.
311   *
312   *  @note The following assumes that all API return codes can be
313   *        treated as an uint32_t.
314   */
315  uint32_t              return_code;
316
317  /**
318   * @brief Code to set the timeout return code in _Thread_Timeout().
319   */
320  uint32_t timeout_code;
321
322  /**
323   * @brief The current thread queue.
324   *
325   * In case this field is @c NULL, then the thread is not blocked on a thread
326   * queue.  This field is protected by the thread lock.
327   *
328   * @see _Thread_Lock_set() and _Thread_Wait_set_queue().
329   */
330  Thread_queue_Queue *queue;
331
332  /**
333   * @brief This field contains several flags used to control the wait class
334   * and state of a thread in case fine-grained locking is used.
335   */
336#if defined(RTEMS_SMP)
337  Atomic_Uint           flags;
338#else
339  Thread_Wait_flags     flags;
340#endif
341
342  /**
343   * @brief The current thread queue operations.
344   *
345   * This field is protected by the thread lock.
346   *
347   * @see _Thread_Lock_set() and _Thread_Wait_set_operations().
348   */
349  const Thread_queue_Operations *operations;
350
351  Thread_queue_Heads *spare_heads;
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   * This is a plain ticket lock without SMP lock statistics support.  This
654   * enables external libraries to use thread locks since they are independent
655   * of the actual RTEMS build configuration, e.g. profiling enabled or
656   * disabled.
657   */
658  SMP_ticket_lock_Control *current;
659
660  /**
661   * @brief The default thread lock in case the thread is not blocked on a
662   * resource.
663   */
664  SMP_ticket_lock_Control Default;
665
666#if defined(RTEMS_PROFILING)
667  /**
668   * @brief The thread lock statistics.
669   *
670   * These statistics are used by the executing thread in case it acquires a
671   * thread lock.  Thus the statistics are an aggregation of acquire and
672   * release operations of diffent locks.
673   */
674  SMP_lock_Stats Stats;
675#endif
676
677  /**
678   * @brief Generation number to invalidate stale locks.
679   */
680  Atomic_Uint generation;
681} Thread_Lock_control;
682#endif
683
684/**
685 *  This structure defines the Thread Control Block (TCB).
686 *
687 *  Uses a leading underscore in the structure name to allow forward
688 *  declarations in standard header files provided by Newlib and GCC.
689 */
690struct _Thread_Control {
691  /** This field is the object management structure for each thread. */
692  Objects_Control          Object;
693  /** This field is the current execution state of this thread. */
694  States_Control           current_state;
695
696  /**
697   * @brief This field is the current priority state of this thread.
698   *
699   * Writes to this field are only allowed in _Thread_Initialize() or via
700   * _Thread_Change_priority().
701   */
702  Priority_Control         current_priority;
703
704  /**
705   * @brief This field is the base priority of this thread.
706   *
707   * Writes to this field are only allowed in _Thread_Initialize() or via
708   * _Thread_Change_priority().
709   */
710  Priority_Control         real_priority;
711
712  /**
713   * @brief Generation of the current priority value.
714   *
715   * It is used in _Thread_Change_priority() to serialize the update of
716   * priority related data structures.
717   */
718  uint32_t                 priority_generation;
719
720  /**
721   * @brief Hints if a priority restore is necessary once the resource count
722   * changes from one to zero.
723   *
724   * This is an optimization to speed up the mutex surrender sequence in case
725   * no attempt to change the priority was made during the mutex ownership.  On
726   * SMP configurations atomic fences must synchronize writes to
727   * Thread_Control::priority_restore_hint and Thread_Control::resource_count.
728   */
729  bool                     priority_restore_hint;
730
731  /** This field is the number of mutexes currently held by this thread. */
732  uint32_t                 resource_count;
733  /** This field is the blocking information for this thread. */
734  Thread_Wait_information  Wait;
735  /** This field is the Watchdog used to manage thread delays and timeouts. */
736  Watchdog_Control         Timer;
737#if defined(RTEMS_MULTIPROCESSING)
738  /** This field is the received response packet in an MP system. */
739  MP_packet_Prefix        *receive_packet;
740#endif
741     /*================= end of common block =================*/
742
743#if defined(RTEMS_SMP)
744  /**
745   * @brief Thread lock control.
746   */
747  Thread_Lock_control Lock;
748#endif
749
750#if defined(RTEMS_SMP) && defined(RTEMS_PROFILING)
751  /**
752   * @brief Potpourri lock statistics.
753   *
754   * These SMP lock statistics are used for all lock objects that lack a
755   * storage space for the statistics.  Examples are lock objects used in
756   * external libraries which are independent of the actual RTEMS build
757   * configuration.
758   */
759  SMP_lock_Stats Potpourri_stats;
760#endif
761
762#ifdef __RTEMS_STRICT_ORDER_MUTEX__
763  /** This field is the head of queue of priority inheritance mutex
764   *  held by the thread.
765   */
766  Chain_Control            lock_mutex;
767#endif
768#if defined(RTEMS_SMP)
769  /**
770   * @brief Resource node to build a dependency tree in case this thread owns
771   * resources or depends on a resource.
772   */
773  Resource_Node            Resource_node;
774#endif
775#if defined(RTEMS_MULTIPROCESSING)
776  /** This field is true if the thread is offered globally */
777  bool                                  is_global;
778#endif
779  /** This field is true if the thread is preemptible. */
780  bool                                  is_preemptible;
781  /** This field is true if the thread uses the floating point unit. */
782  bool                                  is_fp;
783
784  /**
785   * @brief Scheduler related control.
786   */
787  Thread_Scheduler_control              Scheduler;
788
789#if __RTEMS_ADA__
790  /** This field is the GNAT self context pointer. */
791  void                                 *rtems_ada_self;
792#endif
793  /** This field is the length of the time quantum that this thread is
794   *  allowed to consume.  The algorithm used to manage limits on CPU usage
795   *  is specified by budget_algorithm.
796   */
797  uint32_t                              cpu_time_budget;
798  /** This field is the algorithm used to manage this thread's time
799   *  quantum.  The algorithm may be specified as none which case,
800   *  no limit is in place.
801   */
802  Thread_CPU_budget_algorithms          budget_algorithm;
803  /** This field is the method invoked with the budgeted time is consumed. */
804  Thread_CPU_budget_algorithm_callout   budget_callout;
805  /** This field is the amount of CPU time consumed by this thread
806   *  since it was created.
807   */
808  Thread_CPU_usage_t                    cpu_time_used;
809
810  /** This field contains information about the starting state of
811   *  this thread.
812   */
813  Thread_Start_information              Start;
814
815  Thread_Action_control                 Post_switch_actions;
816
817  /** This field contains the context of this thread. */
818  Context_Control                       Registers;
819#if ( CPU_HARDWARE_FP == TRUE ) || ( CPU_SOFTWARE_FP == TRUE )
820  /** This field points to the floating point context for this thread.
821   *  If NULL, the thread is integer only.
822   */
823  Context_Control_fp                   *fp_context;
824#endif
825  /** This field points to the newlib reentrancy structure for this thread. */
826  struct _reent                        *libc_reent;
827  /** This array contains the API extension area pointers. */
828  void                                 *API_Extensions[ THREAD_API_LAST + 1 ];
829
830#if !defined(RTEMS_SMP)
831  /** This field points to the set of per task variables. */
832  rtems_task_variable_t                *task_variables;
833#endif
834
835  /**
836   * This is the thread key value chain's control, which is used
837   * to track all key value for specific thread, and when thread
838   * exits, we can remove all key value for specific thread by
839   * iterating this chain, or we have to search a whole rbtree,
840   * which is inefficient.
841   */
842  Chain_Control           Key_Chain;
843
844  /**
845   * @brief Thread life-cycle control.
846   *
847   * Control state changes triggered by thread restart and delete requests.
848   */
849  Thread_Life_control                   Life;
850
851  Thread_Capture_control                Capture;
852
853  /**
854   * @brief Variable length array of user extension pointers.
855   *
856   * The length is defined by the application via <rtems/confdefs.h>.
857   */
858  void                                 *extensions[ RTEMS_ZERO_LENGTH_ARRAY ];
859};
860
861#if (CPU_PROVIDES_IDLE_THREAD_BODY == FALSE)
862/**
863 *  This routine is the body of the system idle thread.
864 *
865 *  NOTE: This routine is actually instantiated by confdefs.h when needed.
866 */
867void *_Thread_Idle_body(
868  uintptr_t  ignored
869);
870#endif
871
872/**  This defines the type for a method which operates on a single thread.
873 */
874typedef void (*rtems_per_thread_routine)( Thread_Control * );
875
876/**
877 *  @brief Iterates over all threads.
878 *  This routine iterates over all threads regardless of API and
879 *  invokes the specified routine.
880 */
881void rtems_iterate_over_all_threads(
882  rtems_per_thread_routine routine
883);
884
885/**
886 * @brief Thread control add-on.
887 */
888typedef struct {
889  /**
890   * @brief Offset of the pointer field in Thread_Control referencing an
891   * application configuration dependent memory area in the thread control
892   * block.
893   */
894  size_t destination_offset;
895
896  /**
897   * @brief Offset relative to the thread control block begin to an application
898   * configuration dependent memory area.
899   */
900  size_t source_offset;
901} Thread_Control_add_on;
902
903/**
904 * @brief Thread control add-ons.
905 *
906 * The thread control block contains fields that point to application
907 * configuration dependent memory areas, like the scheduler information, the
908 * API control blocks, the user extension context table, and the Newlib
909 * re-entrancy support.  Account for these areas in the configuration and
910 * avoid extra workspace allocations for these areas.
911 *
912 * This array is provided via <rtems/confdefs.h>.
913 *
914 * @see _Thread_Control_add_on_count and _Thread_Control_size.
915 */
916extern const Thread_Control_add_on _Thread_Control_add_ons[];
917
918/**
919 * @brief Thread control add-on count.
920 *
921 * Count of entries in _Thread_Control_add_ons.
922 *
923 * This value is provided via <rtems/confdefs.h>.
924 */
925extern const size_t _Thread_Control_add_on_count;
926
927/**
928 * @brief Size of the thread control block of a particular application.
929 *
930 * This value is provided via <rtems/confdefs.h>.
931 *
932 * @see _Thread_Control_add_ons.
933 */
934extern const size_t _Thread_Control_size;
935
936/**@}*/
937
938#ifdef __cplusplus
939}
940#endif
941
942#endif
943/* end of include file */
Note: See TracBrowser for help on using the repository browser.