source: rtems/cpukit/include/rtems/score/thread.h @ 05da65c

Last change on this file since 05da65c was 05da65c, checked in by Sebastian Huber <sebastian.huber@…>, on 01/29/21 at 07:22:31

score: Document Thread_Life_state

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