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

5
Last change on this file since c3d8d9e was c3d8d9e, checked in by Sebastian Huber <sebastian.huber@…>, on 05/23/16 at 04:55:49

score: Get rid of mp_id parameter

Get rid of the mp_id parameter used for some thread queue methods. Use
THREAD_QUEUE_QUEUE_TO_OBJECT() instead.

  • Property mode set to 100644
File size: 28.3 KB
Line 
1/**
2 *  @file  rtems/score/thread.h
3 *
4 *  @brief Constants and Structures Related with the Thread Control Block
5 *
6 *  This include file contains all constants and structures associated
7 *  with the thread control block.
8 */
9
10/*
11 *  COPYRIGHT (c) 1989-2014.
12 *  On-Line Applications Research Corporation (OAR).
13 *
14 *  Copyright (c) 2014 embedded brains GmbH.
15 *
16 *  The license and distribution terms for this file may be
17 *  found in the file LICENSE in this distribution or at
18 *  http://www.rtems.org/license/LICENSE.
19 */
20
21#ifndef _RTEMS_SCORE_THREAD_H
22#define _RTEMS_SCORE_THREAD_H
23
24#include <rtems/score/atomic.h>
25#include <rtems/score/context.h>
26#if defined(RTEMS_MULTIPROCESSING)
27#include <rtems/score/mppkt.h>
28#endif
29#include <rtems/score/isrlock.h>
30#include <rtems/score/object.h>
31#include <rtems/score/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 Code to set the timeout return code in _Thread_Timeout().
292   */
293  uint32_t timeout_code;
294
295  /**
296   * @brief The current thread queue.
297   *
298   * In case this field is @c NULL, then the thread is not blocked on a thread
299   * queue.  This field is protected by the thread lock.
300   *
301   * @see _Thread_Lock_set() and _Thread_Wait_set_queue().
302   */
303  Thread_queue_Queue *queue;
304
305  /**
306   * @brief This field contains several flags used to control the wait class
307   * and state of a thread in case fine-grained locking is used.
308   */
309#if defined(RTEMS_SMP)
310  Atomic_Uint           flags;
311#else
312  Thread_Wait_flags     flags;
313#endif
314
315  /**
316   * @brief The current thread queue operations.
317   *
318   * This field is protected by the thread lock.
319   *
320   * @see _Thread_Lock_set() and _Thread_Wait_set_operations().
321   */
322  const Thread_queue_Operations *operations;
323
324  Thread_queue_Heads *spare_heads;
325}   Thread_Wait_information;
326
327/**
328 * @brief Information required to manage a thread timer.
329 */
330typedef struct {
331  ISR_LOCK_MEMBER( Lock )
332  Watchdog_Header *header;
333  Watchdog_Control Watchdog;
334} Thread_Timer_information;
335
336/**
337 *  The following defines the control block used to manage
338 *  each thread proxy.
339 *
340 *  @note It is critical that proxies and threads have identical
341 *        memory images for the shared part.
342 */
343typedef struct {
344  /** This field is the object management structure for each proxy. */
345  Objects_Control          Object;
346
347  /**
348   * @see Thread_Control::Join_queue
349   */
350  Thread_queue_Control     Join_queue;
351
352  /** This field is the current execution state of this proxy. */
353  States_Control           current_state;
354  /**
355   * @brief This field is the current priority state of this thread.
356   *
357   * Writes to this field are only allowed in _Thread_Initialize() or via
358   * _Thread_Change_priority().
359   */
360  Priority_Control         current_priority;
361
362  /**
363   * @brief This field is the base priority of this thread.
364   *
365   * Writes to this field are only allowed in _Thread_Initialize() or via
366   * _Thread_Change_priority().
367   */
368  Priority_Control         real_priority;
369
370  /**
371   * @brief Generation of the current priority value.
372   *
373   * It is used in _Thread_Change_priority() to serialize the update of
374   * priority related data structures.
375   */
376  uint32_t                 priority_generation;
377
378  /**
379   * @brief Hints if a priority restore is necessary once the resource count
380   * changes from one to zero.
381   *
382   * This is an optimization to speed up the mutex surrender sequence in case
383   * no attempt to change the priority was made during the mutex ownership.  On
384   * SMP configurations atomic fences must synchronize writes to
385   * Thread_Control::priority_restore_hint and Thread_Control::resource_count.
386   */
387  bool                     priority_restore_hint;
388
389  /** This field is the number of mutexes currently held by this proxy. */
390  uint32_t                 resource_count;
391
392  /** This field is the blocking information for this proxy. */
393  Thread_Wait_information  Wait;
394  /** This field is the Watchdog used to manage proxy delays and timeouts. */
395  Thread_Timer_information Timer;
396#if defined(RTEMS_MULTIPROCESSING)
397  /** This field is the received response packet in an MP system. */
398  MP_packet_Prefix        *receive_packet;
399     /****************** end of common block ********************/
400
401  /**
402   * @brief Thread queue callout for _Thread_queue_Enqueue_critical().
403   */
404  Thread_queue_MP_callout  thread_queue_callout;
405
406  /**
407   * @brief This field is used to manage the set of active proxies in the system.
408   */
409  RBTree_Node              Active;
410
411  /**
412   * @brief Provide thread queue heads for this thread proxy.
413   *
414   * The actual size of the thread queue heads depends on the application
415   * configuration.  Since thread proxies are never destroyed we can use the
416   * same storage place for the thread queue heads.
417   */
418  Thread_queue_Heads       Thread_queue_heads[ RTEMS_ZERO_LENGTH_ARRAY ];
419#endif
420}   Thread_Proxy_control;
421
422/**
423 *  The following record defines the control block used
424 *  to manage each thread.
425 *
426 *  @note It is critical that proxies and threads have identical
427 *        memory images for the shared part.
428 */
429typedef enum {
430  /** This value is for the Classic RTEMS API. */
431  THREAD_API_RTEMS,
432  /** This value is for the POSIX API. */
433  THREAD_API_POSIX
434}  Thread_APIs;
435
436/** This macro defines the first API which has threads. */
437#define THREAD_API_FIRST THREAD_API_RTEMS
438
439/** This macro defines the last API which has threads. */
440#define THREAD_API_LAST  THREAD_API_POSIX
441
442typedef struct Thread_Action Thread_Action;
443
444/**
445 * @brief Thread action handler.
446 *
447 * The thread action handler will be called with interrupts disabled and a
448 * corresponding lock acquired, e.g. _Thread_State_acquire().  The handler must
449 * release the corresponding lock, e.g. _Thread_State_release().  So, the
450 * corresponding lock may be used to protect private data used by the
451 * particular action.
452 *
453 * Since the action is passed to the handler additional data may be accessed
454 * via RTEMS_CONTAINER_OF().
455 *
456 * @param[in] the_thread The thread performing the action.
457 * @param[in] action The thread action.
458 * @param[in] lock_context The lock context to use for the lock release.
459 */
460typedef void ( *Thread_Action_handler )(
461  Thread_Control   *the_thread,
462  Thread_Action    *action,
463  ISR_lock_Context *lock_context
464);
465
466/**
467 * @brief Thread action.
468 *
469 * Thread actions can be chained together to trigger a set of actions on
470 * particular events like for example a thread post-switch.  Use
471 * _Thread_Action_initialize() to initialize this structure.
472 *
473 * Thread actions are the building block for efficient implementation of
474 * - Classic signals delivery,
475 * - POSIX signals delivery, and
476 * - thread life-cycle changes.
477 *
478 * @see _Thread_Add_post_switch_action() and _Thread_Run_post_switch_actions().
479 */
480struct Thread_Action {
481  Chain_Node            Node;
482  Thread_Action_handler handler;
483};
484
485/**
486 * @brief Per-thread information for POSIX Keys.
487 */
488typedef struct {
489  /**
490   * @brief Key value pairs registered for this thread.
491   */
492  RBTree_Control Key_value_pairs;
493
494  /**
495   * @brief Lock to protect the tree operations.
496   */
497  ISR_LOCK_MEMBER( Lock )
498} Thread_Keys_information;
499
500/**
501 * @brief Control block to manage thread actions.
502 *
503 * Use _Thread_Action_control_initialize() to initialize this structure.
504 */
505typedef struct {
506  Chain_Control Chain;
507} Thread_Action_control;
508
509/**
510 * @brief Thread life states.
511 *
512 * The thread life states are orthogonal to the thread states used for
513 * synchronization primitives and blocking operations.  They reflect the state
514 * changes triggered with thread restart and delete requests.
515 *
516 * The individual state values must be a power of two to allow use of bit
517 * operations to manipulate and evaluate the thread life state.
518 */
519typedef enum {
520  THREAD_LIFE_PROTECTED = 0x1,
521  THREAD_LIFE_RESTARTING = 0x2,
522  THREAD_LIFE_TERMINATING = 0x4,
523  THREAD_LIFE_CHANGE_DEFERRED = 0x8,
524  THREAD_LIFE_DETACHED = 0x10
525} Thread_Life_state;
526
527/**
528 * @brief Thread life control.
529 */
530typedef struct {
531  /**
532   * @brief Thread life action used to react upon thread restart and delete
533   * requests.
534   */
535  Thread_Action      Action;
536
537  /**
538   * @brief The current thread life state.
539   */
540  Thread_Life_state  state;
541
542  /**
543   * @brief The count of pending life change requests.
544   */
545  uint32_t pending_life_change_requests;
546
547#if defined(RTEMS_POSIX_API)
548  /**
549   * @brief The thread exit value.
550   *
551   * It is,
552   * - the value passed to pthread_exit(), or
553   * - PTHREAD_CANCELED in case it is cancelled via pthread_cancel(), or
554   * - NULL.
555   */
556  void *exit_value;
557#endif
558} Thread_Life_control;
559
560#if defined(RTEMS_SMP)
561/**
562 * @brief The thread state with respect to the scheduler.
563 */
564typedef enum {
565  /**
566   * @brief This thread is blocked with respect to the scheduler.
567   *
568   * This thread uses no scheduler nodes.
569   */
570  THREAD_SCHEDULER_BLOCKED,
571
572  /**
573   * @brief This thread is scheduled with respect to the scheduler.
574   *
575   * This thread executes using one of its scheduler nodes.  This could be its
576   * own scheduler node or in case it owns resources taking part in the
577   * scheduler helping protocol a scheduler node of another thread.
578   */
579  THREAD_SCHEDULER_SCHEDULED,
580
581  /**
582   * @brief This thread is ready with respect to the scheduler.
583   *
584   * None of the scheduler nodes of this thread is scheduled.
585   */
586  THREAD_SCHEDULER_READY
587} Thread_Scheduler_state;
588#endif
589
590/**
591 * @brief Thread scheduler control.
592 */
593typedef struct {
594#if defined(RTEMS_SMP)
595  /**
596   * @brief The current scheduler state of this thread.
597   */
598  Thread_Scheduler_state state;
599
600  /**
601   * @brief The own scheduler control of this thread.
602   *
603   * This field is constant after initialization.
604   */
605  const struct Scheduler_Control *own_control;
606
607  /**
608   * @brief The scheduler control of this thread.
609   *
610   * The scheduler helping protocol may change this field.
611   */
612  const struct Scheduler_Control *control;
613
614  /**
615   * @brief The own scheduler node of this thread.
616   *
617   * This field is constant after initialization.  It is used by change
618   * priority and ask for help operations.
619   */
620  struct Scheduler_Node *own_node;
621#endif
622
623  /**
624   * @brief The scheduler node of this thread.
625   *
626   * On uni-processor configurations this field is constant after
627   * initialization.
628   *
629   * On SMP configurations the scheduler helping protocol may change this
630   * field.
631   */
632  struct Scheduler_Node *node;
633
634#if defined(RTEMS_SMP)
635  /**
636   * @brief The processor assigned by the current scheduler.
637   */
638  struct Per_CPU_Control *cpu;
639
640#if defined(RTEMS_DEBUG)
641  /**
642   * @brief The processor on which this thread executed the last time or is
643   * executing.
644   */
645  struct Per_CPU_Control *debug_real_cpu;
646#endif
647#endif
648} Thread_Scheduler_control;
649
650typedef struct  {
651  uint32_t      flags;
652  void *        control;
653}Thread_Capture_control;
654
655#if defined(RTEMS_SMP)
656/**
657 * @brief Thread lock control.
658 *
659 * The thread lock is either the default lock or the lock of the resource on
660 * which the thread is currently blocked.  The generation number takes care
661 * that the up to date lock is used.  Only resources using fine grained locking
662 * provide their own lock.
663 *
664 * The thread lock protects the following thread variables
665 *  - Thread_Control::current_priority,
666 *  - Thread_Control::Wait::queue, and
667 *  - Thread_Control::Wait::operations.
668 *
669 * @see _Thread_Lock_acquire(), _Thread_Lock_release(), _Thread_Lock_set() and
670 * _Thread_Lock_restore_default().
671 */
672typedef struct {
673  /**
674   * @brief The current thread lock.
675   *
676   * This is a plain ticket lock without SMP lock statistics support.  This
677   * enables external libraries to use thread locks since they are independent
678   * of the actual RTEMS build configuration, e.g. profiling enabled or
679   * disabled.
680   */
681  SMP_ticket_lock_Control *current;
682
683  /**
684   * @brief The default thread lock in case the thread is not blocked on a
685   * resource.
686   */
687  SMP_ticket_lock_Control Default;
688
689#if defined(RTEMS_PROFILING)
690  /**
691   * @brief The thread lock statistics.
692   *
693   * These statistics are used by the executing thread in case it acquires a
694   * thread lock.  Thus the statistics are an aggregation of acquire and
695   * release operations of diffent locks.
696   */
697  SMP_lock_Stats Stats;
698#endif
699
700  /**
701   * @brief Generation number to invalidate stale locks.
702   */
703  Atomic_Uint generation;
704} Thread_Lock_control;
705#endif
706
707/**
708 *  This structure defines the Thread Control Block (TCB).
709 *
710 *  Uses a leading underscore in the structure name to allow forward
711 *  declarations in standard header files provided by Newlib and GCC.
712 */
713struct _Thread_Control {
714  /** This field is the object management structure for each thread. */
715  Objects_Control          Object;
716
717  /**
718   * @brief Thread queue for thread join operations and multi-purpose lock.
719   *
720   * The lock of this thread queue is used for various purposes.  It protects
721   * the following fields
722   *
723   * - POSIX_API_Control::Attributes,
724   * - POSIX_API_Control::schedparam,
725   * - POSIX_API_Control::schedpolicy,
726   * - RTEMS_API_Control::Signal,
727   * - Thread_Control::budget_algorithm,
728   * - Thread_Control::budget_callout,
729   * - Thread_Control::cpu_time_budget,
730   * - Thread_Control::current_state,
731   * - Thread_Control::Post_switch_actions,
732   * - Thread_Control::Scheduler::control, and
733   * - Thread_Control::Scheduler::own_control.
734   *
735   * @see _Thread_State_acquire().
736   */
737  Thread_queue_Control     Join_queue;
738
739  /** This field is the current execution state of this thread. */
740  States_Control           current_state;
741
742  /**
743   * @brief This field is the current priority state of this thread.
744   *
745   * Writes to this field are only allowed in _Thread_Initialize() or via
746   * _Thread_Change_priority().
747   */
748  Priority_Control         current_priority;
749
750  /**
751   * @brief This field is the base priority of this thread.
752   *
753   * Writes to this field are only allowed in _Thread_Initialize() or via
754   * _Thread_Change_priority().
755   */
756  Priority_Control         real_priority;
757
758  /**
759   * @brief Generation of the current priority value.
760   *
761   * It is used in _Thread_Change_priority() to serialize the update of
762   * priority related data structures.
763   */
764  uint32_t                 priority_generation;
765
766  /**
767   * @brief Hints if a priority restore is necessary once the resource count
768   * changes from one to zero.
769   *
770   * This is an optimization to speed up the mutex surrender sequence in case
771   * no attempt to change the priority was made during the mutex ownership.  On
772   * SMP configurations atomic fences must synchronize writes to
773   * Thread_Control::priority_restore_hint and Thread_Control::resource_count.
774   */
775  bool                     priority_restore_hint;
776
777  /** This field is the number of mutexes currently held by this thread. */
778  uint32_t                 resource_count;
779  /** This field is the blocking information for this thread. */
780  Thread_Wait_information  Wait;
781  /** This field is the Watchdog used to manage thread delays and timeouts. */
782  Thread_Timer_information Timer;
783#if defined(RTEMS_MULTIPROCESSING)
784  /** This field is the received response packet in an MP system. */
785  MP_packet_Prefix        *receive_packet;
786#endif
787     /*================= end of common block =================*/
788
789#if defined(RTEMS_SMP)
790  /**
791   * @brief Thread lock control.
792   */
793  Thread_Lock_control Lock;
794#endif
795
796#if defined(RTEMS_SMP) && defined(RTEMS_PROFILING)
797  /**
798   * @brief Potpourri lock statistics.
799   *
800   * These SMP lock statistics are used for all lock objects that lack a
801   * storage space for the statistics.  Examples are lock objects used in
802   * external libraries which are independent of the actual RTEMS build
803   * configuration.
804   */
805  SMP_lock_Stats Potpourri_stats;
806#endif
807
808#if defined(RTEMS_SMP)
809  /**
810   * @brief Resource node to build a dependency tree in case this thread owns
811   * resources or depends on a resource.
812   */
813  Resource_Node            Resource_node;
814#endif
815#if defined(RTEMS_MULTIPROCESSING)
816  /** This field is true if the thread is offered globally */
817  bool                                  is_global;
818#endif
819  /** This field is true if the thread is preemptible. */
820  bool                                  is_preemptible;
821  /** This field is true if the thread uses the floating point unit. */
822  bool                                  is_fp;
823
824  /**
825   * @brief Scheduler related control.
826   */
827  Thread_Scheduler_control              Scheduler;
828
829#if __RTEMS_ADA__
830  /** This field is the GNAT self context pointer. */
831  void                                 *rtems_ada_self;
832#endif
833  /** This field is the length of the time quantum that this thread is
834   *  allowed to consume.  The algorithm used to manage limits on CPU usage
835   *  is specified by budget_algorithm.
836   */
837  uint32_t                              cpu_time_budget;
838  /** This field is the algorithm used to manage this thread's time
839   *  quantum.  The algorithm may be specified as none which case,
840   *  no limit is in place.
841   */
842  Thread_CPU_budget_algorithms          budget_algorithm;
843  /** This field is the method invoked with the budgeted time is consumed. */
844  Thread_CPU_budget_algorithm_callout   budget_callout;
845  /** This field is the amount of CPU time consumed by this thread
846   *  since it was created.
847   */
848  Timestamp_Control                     cpu_time_used;
849
850  /** This field contains information about the starting state of
851   *  this thread.
852   */
853  Thread_Start_information              Start;
854
855  Thread_Action_control                 Post_switch_actions;
856
857  /** This field contains the context of this thread. */
858  Context_Control                       Registers;
859#if ( CPU_HARDWARE_FP == TRUE ) || ( CPU_SOFTWARE_FP == TRUE )
860  /** This field points to the floating point context for this thread.
861   *  If NULL, the thread is integer only.
862   */
863  Context_Control_fp                   *fp_context;
864#endif
865  /** This field points to the newlib reentrancy structure for this thread. */
866  struct _reent                        *libc_reent;
867  /** This array contains the API extension area pointers. */
868  void                                 *API_Extensions[ THREAD_API_LAST + 1 ];
869
870  /**
871   * @brief The POSIX Keys information.
872   */
873  Thread_Keys_information               Keys;
874
875  /**
876   * @brief Thread life-cycle control.
877   *
878   * Control state changes triggered by thread restart and delete requests.
879   */
880  Thread_Life_control                   Life;
881
882  Thread_Capture_control                Capture;
883
884  /**
885   * @brief LIFO list of POSIX cleanup contexts.
886   */
887  struct _pthread_cleanup_context *last_cleanup_context;
888
889  /**
890   * @brief LIFO list of user extensions iterators.
891   */
892  struct User_extensions_Iterator *last_user_extensions_iterator;
893
894  /**
895   * @brief Variable length array of user extension pointers.
896   *
897   * The length is defined by the application via <rtems/confdefs.h>.
898   */
899  void                                 *extensions[ RTEMS_ZERO_LENGTH_ARRAY ];
900};
901
902#if (CPU_PROVIDES_IDLE_THREAD_BODY == FALSE)
903/**
904 *  This routine is the body of the system idle thread.
905 *
906 *  NOTE: This routine is actually instantiated by confdefs.h when needed.
907 */
908void *_Thread_Idle_body(
909  uintptr_t  ignored
910);
911#endif
912
913/**  This defines the type for a method which operates on a single thread.
914 */
915typedef void (*rtems_per_thread_routine)( Thread_Control * );
916
917/**
918 *  @brief Iterates over all threads.
919 *  This routine iterates over all threads regardless of API and
920 *  invokes the specified routine.
921 */
922void rtems_iterate_over_all_threads(
923  rtems_per_thread_routine routine
924);
925
926/**
927 * @brief Thread control add-on.
928 */
929typedef struct {
930  /**
931   * @brief Offset of the pointer field in Thread_Control referencing an
932   * application configuration dependent memory area in the thread control
933   * block.
934   */
935  size_t destination_offset;
936
937  /**
938   * @brief Offset relative to the thread control block begin to an application
939   * configuration dependent memory area.
940   */
941  size_t source_offset;
942} Thread_Control_add_on;
943
944/**
945 * @brief Thread control add-ons.
946 *
947 * The thread control block contains fields that point to application
948 * configuration dependent memory areas, like the scheduler information, the
949 * API control blocks, the user extension context table, and the Newlib
950 * re-entrancy support.  Account for these areas in the configuration and
951 * avoid extra workspace allocations for these areas.
952 *
953 * This array is provided via <rtems/confdefs.h>.
954 *
955 * @see _Thread_Control_add_on_count and _Thread_Control_size.
956 */
957extern const Thread_Control_add_on _Thread_Control_add_ons[];
958
959/**
960 * @brief Thread control add-on count.
961 *
962 * Count of entries in _Thread_Control_add_ons.
963 *
964 * This value is provided via <rtems/confdefs.h>.
965 */
966extern const size_t _Thread_Control_add_on_count;
967
968/**
969 * @brief Size of the thread control block of a particular application.
970 *
971 * This value is provided via <rtems/confdefs.h>.
972 *
973 * @see _Thread_Control_add_ons.
974 */
975extern const size_t _Thread_Control_size;
976
977/**@}*/
978
979#ifdef __cplusplus
980}
981#endif
982
983#endif
984/* end of include file */
Note: See TracBrowser for help on using the repository browser.