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

4.11
Last change on this file since e6b31b27 was e6b31b27, checked in by Joel Sherrill <joel.sherrill@…>, on May 27, 2015 at 3:13:58 PM

Remove use ticks for statistics configure option.

This was obsolete and broken based upon recent time keeping changes.

Thie build option was previously enabled by adding
USE_TICKS_FOR_STATISTICS=1 to the configure command line.

This propagated into the code as preprocessor conditionals
using the RTEMS_USE_TICKS_FOR_STATISTICS conditional.

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