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

5
Last change on this file since ba74ebde was ba74ebde, checked in by Sebastian Huber <sebastian.huber@…>, on Feb 14, 2020 at 6:09:56 PM

libio: Add POSIX user environment pointer to TCB

The IO library used a POSIX key to store an optional POSIX user
environment pointer. This pulled in the POSIX keys support in every
application configuration. Add a user environment pointer to the thread
control block (TCB) instead. Applications which do not need the POSIX
user environment will just get an overhead of one pointer per thread.

Close #3882.

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