source: rtems/cpukit/include/rtems/score/thread.h @ 9278f3d

Last change on this file since 9278f3d was 9278f3d, checked in by Sebastian Huber <sebastian.huber@…>, on 11/27/20 at 16:21:23

score: Canonicalize Doxygen @file comments

Use common phrases for the file brief descriptions.

Update #3706.

  • Property mode set to 100644
File size: 32.3 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 Thread life states.
663 *
664 * The thread life states are orthogonal to the thread states 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 values 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  THREAD_LIFE_PROTECTED = 0x1,
673  THREAD_LIFE_RESTARTING = 0x2,
674  THREAD_LIFE_TERMINATING = 0x4,
675  THREAD_LIFE_CHANGE_DEFERRED = 0x8,
676  THREAD_LIFE_DETACHED = 0x10
677} Thread_Life_state;
678
679/**
680 * @brief Thread life control.
681 */
682typedef struct {
683  /**
684   * @brief Thread life action used to react upon thread restart and delete
685   * requests.
686   */
687  Thread_Action      Action;
688
689  /**
690   * @brief The current thread life state.
691   */
692  Thread_Life_state  state;
693
694  /**
695   * @brief The count of pending life change requests.
696   */
697  uint32_t pending_life_change_requests;
698
699  /**
700   * @brief The thread exit value.
701   *
702   * It is,
703   * - the value passed to pthread_exit(), or
704   * - PTHREAD_CANCELED in case it is cancelled via pthread_cancel(), or
705   * - NULL.
706   */
707  void *exit_value;
708} Thread_Life_control;
709
710typedef struct  {
711  uint32_t      flags;
712  void *        control;
713}Thread_Capture_control;
714
715/**
716 *  This structure defines the Thread Control Block (TCB).
717 *
718 *  Uses a leading underscore in the structure name to allow forward
719 *  declarations in standard header files provided by Newlib and GCC.
720 *
721 *  In case the second member changes (currently Join_queue), then the memset()
722 *  in _Thread_Initialize() must be adjusted.
723 */
724struct _Thread_Control {
725  /** This field is the object management structure for each thread. */
726  Objects_Control          Object;
727
728  /**
729   * @brief Thread queue for thread join operations and multi-purpose lock.
730   *
731   * The lock of this thread queue is used for various purposes.  It protects
732   * the following fields
733   *
734   * - RTEMS_API_Control::Signal,
735   * - Thread_Control::budget_algorithm,
736   * - Thread_Control::budget_callout,
737   * - Thread_Control::cpu_time_budget,
738   * - Thread_Control::current_state,
739   * - Thread_Control::Post_switch_actions,
740   * - Thread_Control::Scheduler::control, and
741   * - Thread_Control::Scheduler::own_control.
742   *
743   * @see _Thread_State_acquire().
744   */
745  Thread_queue_Control     Join_queue;
746
747  /** This field is the current execution state of this thread. */
748  States_Control           current_state;
749
750  /**
751   * @brief The base priority of this thread in its home scheduler instance.
752   */
753  Priority_Node            Real_priority;
754
755#if defined(RTEMS_SCORE_THREAD_ENABLE_RESOURCE_COUNT)
756  /** This field is the number of mutexes currently held by this thread. */
757  uint32_t                 resource_count;
758#endif
759
760  /**
761   * @brief Scheduler related control.
762   */
763  Thread_Scheduler_control Scheduler;
764
765  /** This field is the blocking information for this thread. */
766  Thread_Wait_information  Wait;
767  /** This field is the Watchdog used to manage thread delays and timeouts. */
768  Thread_Timer_information Timer;
769#if defined(RTEMS_MULTIPROCESSING)
770  /** This field is the received response packet in an MP system. */
771  MP_packet_Prefix        *receive_packet;
772#endif
773     /*================= end of common block =================*/
774
775#if defined(RTEMS_SMP) && defined(RTEMS_PROFILING)
776  /**
777   * @brief Potpourri lock statistics.
778   *
779   * These SMP lock statistics are used for all lock objects that lack a
780   * storage space for the statistics.  Examples are lock objects used in
781   * external libraries which are independent of the actual RTEMS build
782   * configuration.
783   */
784  SMP_lock_Stats Potpourri_stats;
785#endif
786
787  /** This field is true if the thread is an idle thread. */
788  bool                                  is_idle;
789#if defined(RTEMS_MULTIPROCESSING)
790  /** This field is true if the thread is offered globally */
791  bool                                  is_global;
792#endif
793  /** This field is true if the thread is preemptible. */
794  bool                                  is_preemptible;
795  /** This field is true if the thread uses the floating point unit. */
796  bool                                  is_fp;
797
798  /**
799   * @brief True, if the thread was created with an inherited scheduler
800   * (PTHREAD_INHERIT_SCHED), and false otherwise.
801   */
802  bool was_created_with_inherited_scheduler;
803
804  /** This field is the length of the time quantum that this thread is
805   *  allowed to consume.  The algorithm used to manage limits on CPU usage
806   *  is specified by budget_algorithm.
807   */
808  uint32_t                              cpu_time_budget;
809  /** This field is the algorithm used to manage this thread's time
810   *  quantum.  The algorithm may be specified as none which case,
811   *  no limit is in place.
812   */
813  Thread_CPU_budget_algorithms          budget_algorithm;
814  /** This field is the method invoked with the budgeted time is consumed. */
815  Thread_CPU_budget_algorithm_callout   budget_callout;
816  /** This field is the amount of CPU time consumed by this thread
817   *  since it was created.
818   */
819  Timestamp_Control                     cpu_time_used;
820
821  /** This field contains information about the starting state of
822   *  this thread.
823   */
824  Thread_Start_information              Start;
825
826  Thread_Action_control                 Post_switch_actions;
827
828  /** This field contains the context of this thread. */
829  Context_Control                       Registers;
830#if ( CPU_HARDWARE_FP == TRUE ) || ( CPU_SOFTWARE_FP == TRUE )
831  /** This field points to the floating point context for this thread.
832   *  If NULL, the thread is integer only.
833   */
834  Context_Control_fp                   *fp_context;
835#endif
836  /** This field points to the newlib reentrancy structure for this thread. */
837  struct _reent                        *libc_reent;
838  /** This array contains the API extension area pointers. */
839  void                                 *API_Extensions[ THREAD_API_LAST + 1 ];
840
841  /**
842   * @brief The POSIX Keys information.
843   */
844  Thread_Keys_information               Keys;
845
846  /**
847   * @brief Thread life-cycle control.
848   *
849   * Control state changes triggered by thread restart and delete requests.
850   */
851  Thread_Life_control                   Life;
852
853  Thread_Capture_control                Capture;
854
855  /**
856   * @brief Pointer to an optional thread-specific POSIX user environment.
857   */
858  struct rtems_user_env_t *user_environment;
859
860  /**
861   * @brief LIFO list of POSIX cleanup contexts.
862   */
863  struct _pthread_cleanup_context *last_cleanup_context;
864
865  /**
866   * @brief LIFO list of user extensions iterators.
867   */
868  struct User_extensions_Iterator *last_user_extensions_iterator;
869
870  /**
871   * @brief Variable length array of user extension pointers.
872   *
873   * The length is defined by the application via <rtems/confdefs.h>.
874   */
875  void                                 *extensions[ RTEMS_ZERO_LENGTH_ARRAY ];
876};
877
878typedef void (*rtems_per_thread_routine)( Thread_Control * );
879
880/**
881 * @brief Deprecated, use rtems_task_iterate() instead.
882 *
883 * Use rtems_task_iterate() instead.
884 */
885void rtems_iterate_over_all_threads(
886  rtems_per_thread_routine routine
887) RTEMS_DEPRECATED;
888
889/**
890 * @brief Thread control add-on.
891 */
892typedef struct {
893  /**
894   * @brief Offset of the pointer field in Thread_Control referencing an
895   * application configuration dependent memory area in the thread control
896   * block.
897   */
898  size_t destination_offset;
899
900  /**
901   * @brief Offset relative to the thread control block begin to an application
902   * configuration dependent memory area.
903   */
904  size_t source_offset;
905} Thread_Control_add_on;
906
907/**
908 * @brief Thread control add-ons.
909 *
910 * The thread control block contains fields that point to application
911 * configuration dependent memory areas, like the scheduler information, the
912 * API control blocks, the user extension context table, and the Newlib
913 * re-entrancy support.  Account for these areas in the configuration and
914 * avoid extra workspace allocations for these areas.
915 *
916 * This array is provided via <rtems/confdefs.h>.
917 *
918 * @see _Thread_Control_add_on_count.
919 */
920extern const Thread_Control_add_on _Thread_Control_add_ons[];
921
922/**
923 * @brief Thread control add-on count.
924 *
925 * Count of entries in _Thread_Control_add_ons.
926 *
927 * This value is provided via <rtems/confdefs.h>.
928 */
929extern const size_t _Thread_Control_add_on_count;
930
931/**
932 * @brief Count of configured threads.
933 *
934 * This value is provided via <rtems/confdefs.h>.
935 */
936extern const size_t _Thread_Initial_thread_count;
937
938/**
939 * @brief The default maximum size of a thread name in characters (including
940 * the terminating '\0' character).
941 *
942 * This is the default value for the application configuration option
943 * CONFIGURE_MAXIMUM_THREAD_NAME_SIZE.
944 */
945#define THREAD_DEFAULT_MAXIMUM_NAME_SIZE 16
946
947/**
948 * @brief Maximum size of a thread name in characters (including the
949 * terminating '\0' character).
950 *
951 * This value is provided via <rtems/confdefs.h>.
952 */
953extern const size_t _Thread_Maximum_name_size;
954
955/**
956 * @brief If this constant is greater than zero, then it defines the maximum
957 * thread-local storage size, otherwise the thread-local storage size is defined
958 * by the linker depending on the thread-local storage objects used by the
959 * application in the statically-linked executable.
960 *
961 * This value is provided via <rtems/confdefs.h>.
962 */
963extern const size_t _Thread_Maximum_TLS_size;
964
965/**
966 * @brief The configured thread control block.
967 *
968 * This type is defined in <rtems/confdefs.h> and depends on the application
969 * configuration.
970 */
971typedef struct Thread_Configured_control Thread_Configured_control;
972
973/**
974 * @brief The configured thread queue heads.
975 *
976 * In SMP configurations, this type is defined in <rtems/confdefs.h> and depends
977 * on the application configuration.
978 */
979#if defined(RTEMS_SMP)
980typedef struct Thread_queue_Configured_heads Thread_queue_Configured_heads;
981#else
982typedef Thread_queue_Heads Thread_queue_Configured_heads;
983#endif
984
985/**
986 * @brief Size of the thread queue heads of a particular application.
987 *
988 * In SMP configurations, this value is provided via <rtems/confdefs.h>.
989 */
990#if defined(RTEMS_SMP)
991extern const size_t _Thread_queue_Heads_size;
992#else
993#define _Thread_queue_Heads_size sizeof(Thread_queue_Heads)
994#endif
995
996/**
997 * @brief The thread object information.
998 */
999typedef struct {
1000  /**
1001   * @brief The object information.
1002   */
1003  Objects_Information Objects;
1004
1005  /**
1006   * @brief Thread queue heads maintenance.
1007   */
1008  union {
1009    /**
1010     * @brief Contains the initial set of thread queue heads.
1011     *
1012     * This is set by <rtems/confdefs.h> via THREAD_INFORMATION_DEFINE().
1013     */
1014    Thread_queue_Configured_heads *initial;
1015
1016    /**
1017     * @brief The free thread queue heads.
1018     *
1019     * This member is initialized by _Thread_Initialize_information().
1020     */
1021    Freechain_Control Free;
1022  } Thread_queue_heads;
1023} Thread_Information;
1024
1025/**
1026 * @brief The internal thread  objects information.
1027 */
1028extern Thread_Information _Thread_Information;
1029
1030#define THREAD_INFORMATION_DEFINE_ZERO( name, api, cls ) \
1031Thread_Information name##_Information = { \
1032  { \
1033    _Objects_Build_id( api, cls, 1, 0 ), \
1034    NULL, \
1035    _Objects_Allocate_none, \
1036    NULL, \
1037    0, \
1038    0, \
1039    0, \
1040    0, \
1041    CHAIN_INITIALIZER_EMPTY( name##_Information.Objects.Inactive ), \
1042    NULL, \
1043    NULL, \
1044    NULL \
1045    OBJECTS_INFORMATION_MP( name##_Information.Objects, NULL ), \
1046  }, { \
1047    NULL \
1048  } \
1049}
1050
1051/**
1052 * @brief Return an inactive thread object or NULL.
1053 *
1054 * @retval NULL No inactive object is available.
1055 * @retval object An inactive object.
1056 */
1057Objects_Control *_Thread_Allocate_unlimited( Objects_Information *information );
1058
1059#define THREAD_INFORMATION_DEFINE( name, api, cls, max ) \
1060static Objects_Control * \
1061name##_Local_table[ _Objects_Maximum_per_allocation( max ) ]; \
1062static Thread_Configured_control \
1063name##_Objects[ _Objects_Maximum_per_allocation( max ) ]; \
1064static Thread_queue_Configured_heads \
1065name##_Heads[ _Objects_Maximum_per_allocation( max ) ]; \
1066Thread_Information name##_Information = { \
1067  { \
1068    _Objects_Build_id( api, cls, 1, _Objects_Maximum_per_allocation( max ) ), \
1069    name##_Local_table, \
1070    _Objects_Is_unlimited( max ) ? \
1071      _Thread_Allocate_unlimited : _Objects_Allocate_static, \
1072    _Objects_Is_unlimited( max ) ? \
1073      _Objects_Free_unlimited : _Objects_Free_static, \
1074    0, \
1075    _Objects_Is_unlimited( max ) ? _Objects_Maximum_per_allocation( max ) : 0, \
1076    sizeof( Thread_Configured_control ), \
1077    OBJECTS_NO_STRING_NAME, \
1078    CHAIN_INITIALIZER_EMPTY( name##_Information.Objects.Inactive ), \
1079    NULL, \
1080    NULL, \
1081    &name##_Objects[ 0 ].Control.Object \
1082    OBJECTS_INFORMATION_MP( name##_Information.Objects, NULL ) \
1083  }, { \
1084    &name##_Heads[ 0 ] \
1085  } \
1086}
1087
1088/**
1089 * @brief The idle thread stacks.
1090 *
1091 * Provided by the application via <rtems/confdefs.h>.
1092 */
1093extern char _Thread_Idle_stacks[];
1094
1095#if defined(RTEMS_MULTIPROCESSING)
1096/**
1097 * @brief The configured thread control block.
1098 *
1099 * This type is defined in <rtems/confdefs.h> and depends on the application
1100 * configuration.
1101 */
1102typedef struct Thread_Configured_proxy_control Thread_Configured_proxy_control;
1103
1104/**
1105 * @brief The configured proxies.
1106 *
1107 * Provided by the application via <rtems/confdefs.h>.
1108 */
1109extern Thread_Configured_proxy_control * const _Thread_MP_Proxies;
1110#endif
1111
1112/** @} */
1113
1114#ifdef __cplusplus
1115}
1116#endif
1117
1118#endif
1119/* end of include file */
Note: See TracBrowser for help on using the repository browser.