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

5
Last change on this file since d297c81d was d297c81d, checked in by Sebastian Huber <sebastian.huber@…>, on 03/01/16 at 05:36:16

score: Delete Thread_CPU_usage_t

This type is superfluous since all operations with it are done via the
_Timestamp_*() functions.

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