source: rtems/cpukit/include/rtems/score/thread.h @ 21275b58

Last change on this file since 21275b58 was 21275b58, checked in by Sebastian Huber <sebastian.huber@…>, on Nov 22, 2018 at 6:14:51 PM

score: Static Objects_Information initialization

Statically allocate the objects information together with the initial
set of objects either via <rtems/confdefs.h>. Provide default object
informations with zero objects via librtemscpu.a. This greatly
simplifies the workspace size estimate. RTEMS applications which do not
use the unlimited objects option are easier to debug since all objects
reside now in statically allocated objects of the right types.

Close #3621.

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