source: rtems/cpukit/score/include/rtems/score/thread.h @ 80fca28

4.115
Last change on this file since 80fca28 was 335e5ca, checked in by Sebastian Huber <sebastian.huber@…>, on 06/02/15 at 19:43:54

score: Add Thread_Control::is_fp

Store the floating-point unit property in the thread control block
regardless of the CPU_HARDWARE_FP and CPU_SOFTWARE_FP settings. Make
sure the floating-point unit is only enabled for the corresponding
multilibs. This helps targets which have a volatile only floating point
context like SPARC for example.

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