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

5
Last change on this file since d79df38 was d79df38, checked in by Sebastian Huber <sebastian.huber@…>, on 07/26/16 at 08:34:21

score: Add deadlock detection

The mutex objects use the owner field of the thread queues for the mutex
owner. Use this and add a deadlock detection to
_Thread_queue_Enqueue_critical() for thread queues with an owner.

Update #2412.
Update #2556.
Close #2765.

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