source: rtems/cpukit/score/include/rtems/score/thread.h @ 84dc9df

5
Last change on this file since 84dc9df was 84dc9df, checked in by Sebastian Huber <sebastian.huber@…>, on 04/04/16 at 04:17:36

score: Use red-black tree for active MP proxies

Update #2555.

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