source: rtems/cpukit/score/include/rtems/score/thread.h @ 383cf42

4.115
Last change on this file since 383cf42 was 383cf42, checked in by Sebastian Huber <sebastian.huber@…>, on 04/22/15 at 09:15:46

score: More thread queue operations

Move thread queue discipline specific operations into
Thread_queue_Operations. Use a separate node in the thread control
block for the thread queue to make it independent of the scheduler data
structures.

Update #2273.

  • Property mode set to 100644
File size: 26.8 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  /** This field is the current priority state of this proxy. */
370  Priority_Control         current_priority;
371  /** This field is the base priority of this proxy. */
372  Priority_Control         real_priority;
373
374  /**
375   * @brief Generation of the current priority value.
376   *
377   * It is used in _Thread_Change_priority() to serialize the update of
378   * priority related data structures.
379   */
380  uint32_t                 priority_generation;
381
382  /** This field is the number of mutexes currently held by this proxy. */
383  uint32_t                 resource_count;
384
385  /** This field is the blocking information for this proxy. */
386  Thread_Wait_information  Wait;
387  /** This field is the Watchdog used to manage proxy delays and timeouts. */
388  Watchdog_Control         Timer;
389#if defined(RTEMS_MULTIPROCESSING)
390  /** This field is the received response packet in an MP system. */
391  MP_packet_Prefix        *receive_packet;
392#endif
393     /****************** end of common block ********************/
394  /** This field is used to manage the set of proxies in the system. */
395  Chain_Node               Active;
396}   Thread_Proxy_control;
397
398/**
399 *  The following record defines the control block used
400 *  to manage each thread.
401 *
402 *  @note It is critical that proxies and threads have identical
403 *        memory images for the shared part.
404 */
405typedef enum {
406  /** This value is for the Classic RTEMS API. */
407  THREAD_API_RTEMS,
408  /** This value is for the POSIX API. */
409  THREAD_API_POSIX
410}  Thread_APIs;
411
412/** This macro defines the first API which has threads. */
413#define THREAD_API_FIRST THREAD_API_RTEMS
414
415/** This macro defines the last API which has threads. */
416#define THREAD_API_LAST  THREAD_API_POSIX
417
418typedef struct Thread_Action Thread_Action;
419
420/**
421 * @brief Thread action handler.
422 *
423 * The thread action handler will be called with interrupts disabled and the
424 * thread action lock acquired.  The handler must release the thread action
425 * lock with _Thread_Action_release_and_ISR_enable().  So the thread action
426 * lock can be used to protect private data fields of the particular action.
427 *
428 * Since the action is passed to the handler private data fields can be added
429 * below the common thread action fields.
430 *
431 * @param[in] thread The thread performing the action.
432 * @param[in] action The thread action.
433 * @param[in] cpu The processor of the thread.
434 * @param[in] level The ISR level for _Thread_Action_release_and_ISR_enable().
435 */
436typedef void ( *Thread_Action_handler )(
437  Thread_Control  *thread,
438  Thread_Action   *action,
439  Per_CPU_Control *cpu,
440  ISR_Level        level
441);
442
443/**
444 * @brief Thread action.
445 *
446 * Thread actions can be chained together to trigger a set of actions on
447 * particular events like for example a thread post-switch.  Use
448 * _Thread_Action_initialize() to initialize this structure.
449 *
450 * Thread actions are the building block for efficient implementation of
451 * - Classic signals delivery,
452 * - POSIX signals delivery,
453 * - thread restart notification,
454 * - thread delete notification,
455 * - forced thread migration on SMP configurations, and
456 * - the Multiprocessor Resource Sharing Protocol (MrsP).
457 *
458 * @see _Thread_Run_post_switch_actions().
459 */
460struct Thread_Action {
461  Chain_Node            Node;
462  Thread_Action_handler handler;
463};
464
465/**
466 * @brief Control block to manage thread actions.
467 *
468 * Use _Thread_Action_control_initialize() to initialize this structure.
469 */
470typedef struct {
471  Chain_Control Chain;
472} Thread_Action_control;
473
474/**
475 * @brief Thread life states.
476 *
477 * The thread life states are orthogonal to the thread states used for
478 * synchronization primitives and blocking operations.  They reflect the state
479 * changes triggered with thread restart and delete requests.
480 */
481typedef enum {
482  THREAD_LIFE_NORMAL = 0x0,
483  THREAD_LIFE_PROTECTED = 0x1,
484  THREAD_LIFE_RESTARTING = 0x2,
485  THREAD_LIFE_PROTECTED_RESTARTING = 0x3,
486  THREAD_LIFE_TERMINATING = 0x4,
487  THREAD_LIFE_PROTECTED_TERMINATING = 0x5,
488  THREAD_LIFE_RESTARTING_TERMINATING = 0x6,
489  THREAD_LIFE_PROTECTED_RESTARTING_TERMINATING = 0x7
490} Thread_Life_state;
491
492/**
493 * @brief Thread life control.
494 */
495typedef struct {
496  /**
497   * @brief Thread life action used to react upon thread restart and delete
498   * requests.
499   */
500  Thread_Action      Action;
501
502  /**
503   * @brief The current thread life state.
504   */
505  Thread_Life_state  state;
506
507  /**
508   * @brief The terminator thread of this thread.
509   *
510   * In case the thread is terminated and another thread (the terminator) waits
511   * for the actual termination completion, then this field references the
512   * terminator thread.
513   */
514  Thread_Control    *terminator;
515} Thread_Life_control;
516
517#if defined(RTEMS_SMP)
518/**
519 * @brief The thread state with respect to the scheduler.
520 */
521typedef enum {
522  /**
523   * @brief This thread is blocked with respect to the scheduler.
524   *
525   * This thread uses no scheduler nodes.
526   */
527  THREAD_SCHEDULER_BLOCKED,
528
529  /**
530   * @brief This thread is scheduled with respect to the scheduler.
531   *
532   * This thread executes using one of its scheduler nodes.  This could be its
533   * own scheduler node or in case it owns resources taking part in the
534   * scheduler helping protocol a scheduler node of another thread.
535   */
536  THREAD_SCHEDULER_SCHEDULED,
537
538  /**
539   * @brief This thread is ready with respect to the scheduler.
540   *
541   * None of the scheduler nodes of this thread is scheduled.
542   */
543  THREAD_SCHEDULER_READY
544} Thread_Scheduler_state;
545#endif
546
547/**
548 * @brief Thread scheduler control.
549 */
550typedef struct {
551#if defined(RTEMS_SMP)
552  /**
553   * @brief The current scheduler state of this thread.
554   */
555  Thread_Scheduler_state state;
556
557  /**
558   * @brief The own scheduler control of this thread.
559   *
560   * This field is constant after initialization.
561   */
562  const struct Scheduler_Control *own_control;
563
564  /**
565   * @brief The scheduler control of this thread.
566   *
567   * The scheduler helping protocol may change this field.
568   */
569  const struct Scheduler_Control *control;
570
571  /**
572   * @brief The own scheduler node of this thread.
573   *
574   * This field is constant after initialization.  It is used by change
575   * priority and ask for help operations.
576   */
577  struct Scheduler_Node *own_node;
578#endif
579
580  /**
581   * @brief The scheduler node of this thread.
582   *
583   * On uni-processor configurations this field is constant after
584   * initialization.
585   *
586   * On SMP configurations the scheduler helping protocol may change this
587   * field.
588   */
589  struct Scheduler_Node *node;
590
591#if defined(RTEMS_SMP)
592  /**
593   * @brief The processor assigned by the current scheduler.
594   */
595  Per_CPU_Control *cpu;
596
597#if defined(RTEMS_DEBUG)
598  /**
599   * @brief The processor on which this thread executed the last time or is
600   * executing.
601   */
602  Per_CPU_Control *debug_real_cpu;
603#endif
604#endif
605} Thread_Scheduler_control;
606
607typedef struct  {
608  uint32_t      flags;
609  void *        control;
610}Thread_Capture_control;
611
612#if defined(RTEMS_SMP)
613/**
614 * @brief Thread lock control.
615 *
616 * The thread lock is either the default lock or the lock of the resource on
617 * which the thread is currently blocked.  The generation number takes care
618 * that the up to date lock is used.  Only resources using fine grained locking
619 * provide their own lock.
620 *
621 * The thread lock protects the following thread variables
622 *  - Thread_Control::current_priority,
623 *  - Thread_Control::Wait::queue, and
624 *  - Thread_Control::Wait::operations.
625 *
626 * @see _Thread_Lock_acquire(), _Thread_Lock_release(), _Thread_Lock_set() and
627 * _Thread_Lock_restore_default().
628 */
629typedef struct {
630  /**
631   * @brief The current thread lock.
632   */
633  ISR_lock_Control *current;
634
635  /**
636   * @brief The default thread lock in case the thread is not blocked on a
637   * resource.
638   */
639  ISR_lock_Control Default;
640
641  /**
642   * @brief Generation number to invalidate stale locks.
643   */
644  Atomic_Uint generation;
645} Thread_Lock_control;
646#endif
647
648/**
649 *  This structure defines the Thread Control Block (TCB).
650 */
651struct Thread_Control_struct {
652  /** This field is the object management structure for each thread. */
653  Objects_Control          Object;
654  /** This field is the current execution state of this thread. */
655  States_Control           current_state;
656  /** This field is the current priority state of this thread. */
657  Priority_Control         current_priority;
658  /** This field is the base priority of this thread. */
659  Priority_Control         real_priority;
660
661  /**
662   * @brief Generation of the current priority value.
663   *
664   * It is used in _Thread_Change_priority() to serialize the update of
665   * priority related data structures.
666   */
667  uint32_t                 priority_generation;
668
669  /** This field is the number of mutexes currently held by this thread. */
670  uint32_t                 resource_count;
671  /** This field is the blocking information for this thread. */
672  Thread_Wait_information  Wait;
673  /** This field is the Watchdog used to manage thread delays and timeouts. */
674  Watchdog_Control         Timer;
675#if defined(RTEMS_MULTIPROCESSING)
676  /** This field is the received response packet in an MP system. */
677  MP_packet_Prefix        *receive_packet;
678#endif
679     /*================= end of common block =================*/
680
681#if defined(RTEMS_SMP)
682  /**
683   * @brief Thread lock control.
684   */
685  Thread_Lock_control Lock;
686#endif
687
688#ifdef __RTEMS_STRICT_ORDER_MUTEX__
689  /** This field is the head of queue of priority inheritance mutex
690   *  held by the thread.
691   */
692  Chain_Control            lock_mutex;
693#endif
694#if defined(RTEMS_SMP)
695  /**
696   * @brief Resource node to build a dependency tree in case this thread owns
697   * resources or depends on a resource.
698   */
699  Resource_Node            Resource_node;
700#endif
701#if defined(RTEMS_MULTIPROCESSING)
702  /** This field is true if the thread is offered globally */
703  bool                                  is_global;
704#endif
705  /** This field is true if the thread is preemptible. */
706  bool                                  is_preemptible;
707
708  /**
709   * @brief Scheduler related control.
710   */
711  Thread_Scheduler_control              Scheduler;
712
713#if __RTEMS_ADA__
714  /** This field is the GNAT self context pointer. */
715  void                                 *rtems_ada_self;
716#endif
717  /** This field is the length of the time quantum that this thread is
718   *  allowed to consume.  The algorithm used to manage limits on CPU usage
719   *  is specified by budget_algorithm.
720   */
721  uint32_t                              cpu_time_budget;
722  /** This field is the algorithm used to manage this thread's time
723   *  quantum.  The algorithm may be specified as none which case,
724   *  no limit is in place.
725   */
726  Thread_CPU_budget_algorithms          budget_algorithm;
727  /** This field is the method invoked with the budgeted time is consumed. */
728  Thread_CPU_budget_algorithm_callout   budget_callout;
729  /** This field is the amount of CPU time consumed by this thread
730   *  since it was created.
731   */
732  Thread_CPU_usage_t                    cpu_time_used;
733
734  /** This field contains information about the starting state of
735   *  this thread.
736   */
737  Thread_Start_information              Start;
738
739  Thread_Action_control                 Post_switch_actions;
740
741  /** This field contains the context of this thread. */
742  Context_Control                       Registers;
743#if ( CPU_HARDWARE_FP == TRUE ) || ( CPU_SOFTWARE_FP == TRUE )
744  /** This field points to the floating point context for this thread.
745   *  If NULL, the thread is integer only.
746   */
747  Context_Control_fp                   *fp_context;
748#endif
749  /** This field points to the newlib reentrancy structure for this thread. */
750  struct _reent                        *libc_reent;
751  /** This array contains the API extension area pointers. */
752  void                                 *API_Extensions[ THREAD_API_LAST + 1 ];
753
754#if !defined(RTEMS_SMP)
755  /** This field points to the set of per task variables. */
756  rtems_task_variable_t                *task_variables;
757#endif
758
759  /**
760   * This is the thread key value chain's control, which is used
761   * to track all key value for specific thread, and when thread
762   * exits, we can remove all key value for specific thread by
763   * iterating this chain, or we have to search a whole rbtree,
764   * which is inefficient.
765   */
766  Chain_Control           Key_Chain;
767
768  /**
769   * @brief Thread life-cycle control.
770   *
771   * Control state changes triggered by thread restart and delete requests.
772   */
773  Thread_Life_control                   Life;
774
775  Thread_Capture_control                Capture;
776
777  /**
778   * @brief Variable length array of user extension pointers.
779   *
780   * The length is defined by the application via <rtems/confdefs.h>.
781   */
782  void                                 *extensions[ RTEMS_ZERO_LENGTH_ARRAY ];
783};
784
785#if (CPU_PROVIDES_IDLE_THREAD_BODY == FALSE)
786/**
787 *  This routine is the body of the system idle thread.
788 *
789 *  NOTE: This routine is actually instantiated by confdefs.h when needed.
790 */
791void *_Thread_Idle_body(
792  uintptr_t  ignored
793);
794#endif
795
796/**  This defines the type for a method which operates on a single thread.
797 */
798typedef void (*rtems_per_thread_routine)( Thread_Control * );
799
800/**
801 *  @brief Iterates over all threads.
802 *  This routine iterates over all threads regardless of API and
803 *  invokes the specified routine.
804 */
805void rtems_iterate_over_all_threads(
806  rtems_per_thread_routine routine
807);
808
809/**
810 * @brief Returns the thread control block of the executing thread.
811 *
812 * This function can be called in any context.  On SMP configurations
813 * interrupts are disabled to ensure that the processor index is used
814 * consistently.
815 *
816 * @return The thread control block of the executing thread.
817 */
818RTEMS_INLINE_ROUTINE Thread_Control *_Thread_Get_executing( void )
819{
820  Thread_Control *executing;
821
822  #if defined( RTEMS_SMP )
823    ISR_Level level;
824
825    _ISR_Disable_without_giant( level );
826  #endif
827
828  executing = _Thread_Executing;
829
830  #if defined( RTEMS_SMP )
831    _ISR_Enable_without_giant( level );
832  #endif
833
834  return executing;
835}
836
837/**
838 * @brief Thread control add-on.
839 */
840typedef struct {
841  /**
842   * @brief Offset of the pointer field in Thread_Control referencing an
843   * application configuration dependent memory area in the thread control
844   * block.
845   */
846  size_t destination_offset;
847
848  /**
849   * @brief Offset relative to the thread control block begin to an application
850   * configuration dependent memory area.
851   */
852  size_t source_offset;
853} Thread_Control_add_on;
854
855/**
856 * @brief Thread control add-ons.
857 *
858 * The thread control block contains fields that point to application
859 * configuration dependent memory areas, like the scheduler information, the
860 * API control blocks, the user extension context table, the RTEMS notepads and
861 * the Newlib re-entrancy support.  Account for these areas in the
862 * configuration and avoid extra workspace allocations for these areas.
863 *
864 * This array is provided via <rtems/confdefs.h>.
865 *
866 * @see _Thread_Control_add_on_count and _Thread_Control_size.
867 */
868extern const Thread_Control_add_on _Thread_Control_add_ons[];
869
870/**
871 * @brief Thread control add-on count.
872 *
873 * Count of entries in _Thread_Control_add_ons.
874 *
875 * This value is provided via <rtems/confdefs.h>.
876 */
877extern const size_t _Thread_Control_add_on_count;
878
879/**
880 * @brief Size of the thread control block of a particular application.
881 *
882 * This value is provided via <rtems/confdefs.h>.
883 *
884 * @see _Thread_Control_add_ons.
885 */
886extern const size_t _Thread_Control_size;
887
888/**@}*/
889
890#ifdef __cplusplus
891}
892#endif
893
894#endif
895/* end of include file */
Note: See TracBrowser for help on using the repository browser.