source: rtems/cpukit/score/include/rtems/score/thread.h @ 105b4e6

5
Last change on this file since 105b4e6 was 105b4e6, checked in by Sebastian Huber <sebastian.huber@…>, on 05/10/16 at 04:47:19

rtems: Use thread state lock for signals

  • Property mode set to 100644
File size: 28.0 KB
Line 
1/**
2 *  @file  rtems/score/thread.h
3 *
4 *  @brief Constants and Structures Related with the Thread Control Block
5 *
6 *  This include file contains all constants and structures associated
7 *  with the thread control block.
8 */
9
10/*
11 *  COPYRIGHT (c) 1989-2014.
12 *  On-Line Applications Research Corporation (OAR).
13 *
14 *  Copyright (c) 2014 embedded brains GmbH.
15 *
16 *  The license and distribution terms for this file may be
17 *  found in the file LICENSE in this distribution or at
18 *  http://www.rtems.org/license/LICENSE.
19 */
20
21#ifndef _RTEMS_SCORE_THREAD_H
22#define _RTEMS_SCORE_THREAD_H
23
24#include <rtems/score/atomic.h>
25#include <rtems/score/context.h>
26#if defined(RTEMS_MULTIPROCESSING)
27#include <rtems/score/mppkt.h>
28#endif
29#include <rtems/score/isrlock.h>
30#include <rtems/score/object.h>
31#include <rtems/score/priority.h>
32#include <rtems/score/resource.h>
33#include <rtems/score/stack.h>
34#include <rtems/score/states.h>
35#include <rtems/score/threadq.h>
36#include <rtems/score/timestamp.h>
37#include <rtems/score/watchdog.h>
38
39#if defined(RTEMS_SMP)
40  #include <rtems/score/cpuset.h>
41#endif
42
43struct _pthread_cleanup_context;
44
45struct Per_CPU_Control;
46
47struct Scheduler_Control;
48
49struct Scheduler_Node;
50
51struct User_extensions_Iterator;
52
53#ifdef __cplusplus
54extern "C" {
55#endif
56
57/**
58 *  @defgroup ScoreThread Thread Handler
59 *
60 *  @ingroup Score
61 *
62 *  This handler encapsulates functionality related to the management of
63 *  threads.  This includes the creation, deletion, and scheduling of threads.
64 *
65 *  The following variables are maintained as part of the per cpu data
66 *  structure.
67 *
68 *  + Idle thread pointer
69 *  + Executing thread pointer
70 *  + Heir thread pointer
71 */
72/**@{*/
73
74#if defined(RTEMS_POSIX_API)
75  #define RTEMS_SCORE_THREAD_ENABLE_EXHAUST_TIMESLICE
76#endif
77
78/*
79 * With the addition of the Constant Block Scheduler (CBS),
80 * this feature is needed even when POSIX is disabled.
81 */
82#define RTEMS_SCORE_THREAD_ENABLE_SCHEDULER_CALLOUT
83
84#if defined(RTEMS_POSIX_API)
85  #define RTEMS_SCORE_THREAD_ENABLE_USER_PROVIDED_STACK_VIA_API
86#endif
87
88/*
89 * Only provided for backward compatiblity to not break application
90 * configurations.
91 */
92typedef void *Thread RTEMS_DEPRECATED;
93
94/**
95 *  @brief Type of the numeric argument of a thread entry function with at
96 *  least one numeric argument.
97 *
98 *  This numeric argument type designates an unsigned integer type with the
99 *  property that any valid pointer to void can be converted to this type and
100 *  then converted back to a pointer to void.  The result will compare equal to
101 *  the original pointer.
102 */
103typedef CPU_Uint32ptr Thread_Entry_numeric_type;
104
105/**
106 * @brief Data for idle thread entry.
107 */
108typedef struct {
109  void *( *entry )( uintptr_t argument );
110} Thread_Entry_idle;
111
112/**
113 * @brief Data for thread entry with one numeric argument and no return value.
114 */
115typedef struct {
116  void ( *entry )( Thread_Entry_numeric_type argument );
117  Thread_Entry_numeric_type argument;
118} Thread_Entry_numeric;
119
120/**
121 * @brief Data for thread entry with one pointer argument and a pointer return
122 * value.
123 */
124typedef struct {
125  void *( *entry )( void *argument  );
126  void *argument;
127} Thread_Entry_pointer;
128
129/**
130 * @brief Thread entry information.
131 */
132typedef struct {
133  /**
134   * @brief Thread entry adaptor.
135   *
136   * Calls the corresponding thread entry with the right parameters.
137   *
138   * @param executing The executing thread.
139   */
140  void ( *adaptor )( Thread_Control *executing );
141
142  /**
143   * @brief Thread entry data used by the adaptor to call the thread entry
144   * function with the right parameters.
145   */
146  union {
147    Thread_Entry_idle Idle;
148    Thread_Entry_numeric Numeric;
149    Thread_Entry_pointer Pointer;
150  } Kinds;
151} Thread_Entry_information;
152
153/**
154 *  The following lists the algorithms used to manage the thread cpu budget.
155 *
156 *  Reset Timeslice:   At each context switch, reset the time quantum.
157 *  Exhaust Timeslice: Only reset the quantum once it is consumed.
158 *  Callout:           Execute routine when budget is consumed.
159 */
160typedef enum {
161  THREAD_CPU_BUDGET_ALGORITHM_NONE,
162  THREAD_CPU_BUDGET_ALGORITHM_RESET_TIMESLICE,
163  #if defined(RTEMS_SCORE_THREAD_ENABLE_EXHAUST_TIMESLICE)
164    THREAD_CPU_BUDGET_ALGORITHM_EXHAUST_TIMESLICE,
165  #endif
166  #if defined(RTEMS_SCORE_THREAD_ENABLE_SCHEDULER_CALLOUT)
167    THREAD_CPU_BUDGET_ALGORITHM_CALLOUT
168  #endif
169}  Thread_CPU_budget_algorithms;
170
171/**  This defines thes the entry point for the thread specific timeslice
172 *   budget management algorithm.
173 */
174typedef void (*Thread_CPU_budget_algorithm_callout )( Thread_Control * );
175
176/**
177 *  The following structure contains the information which defines
178 *  the starting state of a thread.
179 */
180typedef struct {
181  /** This field contains the thread entry information. */
182  Thread_Entry_information             Entry;
183  /*-------------- initial execution modes ----------------- */
184  /** This field indicates whether the thread was preemptible when
185    * it started.
186    */
187  bool                                 is_preemptible;
188  /** This field indicates the CPU budget algorith. */
189  Thread_CPU_budget_algorithms         budget_algorithm;
190  /** This field is the routine to invoke when the CPU allotment is
191   *  consumed.
192   */
193  Thread_CPU_budget_algorithm_callout  budget_callout;
194  /** This field is the initial ISR disable level of this thread. */
195  uint32_t                             isr_level;
196  /** This field is the initial priority. */
197  Priority_Control                     initial_priority;
198  #if defined(RTEMS_SCORE_THREAD_ENABLE_USER_PROVIDED_STACK_VIA_API)
199    /** This field indicates whether the SuperCore allocated the stack. */
200    bool                                 core_allocated_stack;
201  #endif
202  /** This field is the stack information. */
203  Stack_Control                        Initial_stack;
204  #if ( CPU_HARDWARE_FP == TRUE ) || ( CPU_SOFTWARE_FP == TRUE )
205    /** This field is the initial FP context area address. */
206    Context_Control_fp                  *fp_context;
207  #endif
208  /** This field is the initial stack area address. */
209  void                                *stack;
210  /** The thread-local storage (TLS) area */
211  void                                *tls_area;
212} Thread_Start_information;
213
214/**
215 *  @brief Union type to hold a pointer to an immutable or a mutable object.
216 *
217 *  The main purpose is to enable passing of pointers to read-only send buffers
218 *  in the message passing subsystem.  This approach is somewhat fragile since
219 *  it prevents the compiler to check if the operations on objects are valid
220 *  with respect to the constant qualifier.  An alternative would be to add a
221 *  third pointer argument for immutable objects, but this would increase the
222 *  structure size.
223 */
224typedef union {
225  void       *mutable_object;
226  const void *immutable_object;
227} Thread_Wait_information_Object_argument_type;
228
229/**
230 * @brief This type is able to contain several flags used to control the wait
231 * class and state of a thread.
232 *
233 * The mutually exclusive wait class flags are
234 * - @ref THREAD_WAIT_CLASS_EVENT,
235 * - @ref THREAD_WAIT_CLASS_SYSTEM_EVENT, and
236 * - @ref THREAD_WAIT_CLASS_OBJECT.
237 *
238 * The mutually exclusive wait state flags are
239 * - @ref THREAD_WAIT_STATE_INTEND_TO_BLOCK,
240 * - @ref THREAD_WAIT_STATE_BLOCKED, and
241 * - @ref THREAD_WAIT_STATE_READY_AGAIN.
242 */
243typedef unsigned int Thread_Wait_flags;
244
245/**
246 *  @brief Information required to manage a thread while it is blocked.
247 *
248 *  This contains the information required to manage a thread while it is
249 *  blocked and to return information to it.
250 */
251typedef struct {
252  /**
253   * @brief Node for thread queues.
254   */
255  union {
256    /**
257     * @brief A node for chains.
258     */
259    Chain_Node Chain;
260
261    /**
262     * @brief A node for red-black trees.
263     */
264    RBTree_Node RBTree;
265  } Node;
266
267#if defined(RTEMS_MULTIPROCESSING)
268  /*
269   * @brief This field is the identifier of the remote object this thread is
270   * waiting upon.
271   */
272  Objects_Id            remote_id;
273#endif
274  /** This field is used to return an integer while when blocked. */
275  uint32_t              count;
276  /** This field is for a pointer to a user return argument. */
277  void                 *return_argument;
278  /** This field is for a pointer to a second user return argument. */
279  Thread_Wait_information_Object_argument_type
280                        return_argument_second;
281  /** This field contains any options in effect on this blocking operation. */
282  uint32_t              option;
283  /** This field will contain the return status from a blocking operation.
284   *
285   *  @note The following assumes that all API return codes can be
286   *        treated as an uint32_t.
287   */
288  uint32_t              return_code;
289
290  /**
291   * @brief Code to set the timeout return code in _Thread_Timeout().
292   */
293  uint32_t timeout_code;
294
295  /**
296   * @brief The current thread queue.
297   *
298   * In case this field is @c NULL, then the thread is not blocked on a thread
299   * queue.  This field is protected by the thread lock.
300   *
301   * @see _Thread_Lock_set() and _Thread_Wait_set_queue().
302   */
303  Thread_queue_Queue *queue;
304
305  /**
306   * @brief This field contains several flags used to control the wait class
307   * and state of a thread in case fine-grained locking is used.
308   */
309#if defined(RTEMS_SMP)
310  Atomic_Uint           flags;
311#else
312  Thread_Wait_flags     flags;
313#endif
314
315  /**
316   * @brief The current thread queue operations.
317   *
318   * This field is protected by the thread lock.
319   *
320   * @see _Thread_Lock_set() and _Thread_Wait_set_operations().
321   */
322  const Thread_queue_Operations *operations;
323
324  Thread_queue_Heads *spare_heads;
325}   Thread_Wait_information;
326
327/**
328 * @brief Information required to manage a thread timer.
329 */
330typedef struct {
331  ISR_LOCK_MEMBER( Lock )
332  Watchdog_Header *header;
333  Watchdog_Control Watchdog;
334} Thread_Timer_information;
335
336/**
337 *  The following defines the control block used to manage
338 *  each thread proxy.
339 *
340 *  @note It is critical that proxies and threads have identical
341 *        memory images for the shared part.
342 */
343typedef struct {
344  /** This field is the object management structure for each proxy. */
345  Objects_Control          Object;
346
347  /**
348   * @see Thread_Control::Join_queue
349   */
350  Thread_queue_Control     Join_queue;
351
352  /** This field is the current execution state of this proxy. */
353  States_Control           current_state;
354  /**
355   * @brief This field is the current priority state of this thread.
356   *
357   * Writes to this field are only allowed in _Thread_Initialize() or via
358   * _Thread_Change_priority().
359   */
360  Priority_Control         current_priority;
361
362  /**
363   * @brief This field is the base priority of this thread.
364   *
365   * Writes to this field are only allowed in _Thread_Initialize() or via
366   * _Thread_Change_priority().
367   */
368  Priority_Control         real_priority;
369
370  /**
371   * @brief Generation of the current priority value.
372   *
373   * It is used in _Thread_Change_priority() to serialize the update of
374   * priority related data structures.
375   */
376  uint32_t                 priority_generation;
377
378  /**
379   * @brief Hints if a priority restore is necessary once the resource count
380   * changes from one to zero.
381   *
382   * This is an optimization to speed up the mutex surrender sequence in case
383   * no attempt to change the priority was made during the mutex ownership.  On
384   * SMP configurations atomic fences must synchronize writes to
385   * Thread_Control::priority_restore_hint and Thread_Control::resource_count.
386   */
387  bool                     priority_restore_hint;
388
389  /** This field is the number of mutexes currently held by this proxy. */
390  uint32_t                 resource_count;
391
392  /** This field is the blocking information for this proxy. */
393  Thread_Wait_information  Wait;
394  /** This field is the Watchdog used to manage proxy delays and timeouts. */
395  Thread_Timer_information Timer;
396#if defined(RTEMS_MULTIPROCESSING)
397  /** This field is the received response packet in an MP system. */
398  MP_packet_Prefix        *receive_packet;
399     /****************** end of common block ********************/
400
401  /**
402   * @brief Thread queue callout for _Thread_queue_Enqueue_critical().
403   */
404  Thread_queue_MP_callout  thread_queue_callout;
405
406  /**
407   * @brief Thread queue object identifier for
408   * _Thread_queue_Enqueue_critical().
409   */
410  Objects_Id               thread_queue_id;
411
412  /**
413   * @brief This field is used to manage the set of active proxies in the system.
414   */
415  RBTree_Node              Active;
416
417  /**
418   * @brief Provide thread queue heads for this thread proxy.
419   *
420   * The actual size of the thread queue heads depends on the application
421   * configuration.  Since thread proxies are never destroyed we can use the
422   * same storage place for the thread queue heads.
423   */
424  Thread_queue_Heads       Thread_queue_heads[ RTEMS_ZERO_LENGTH_ARRAY ];
425#endif
426}   Thread_Proxy_control;
427
428/**
429 *  The following record defines the control block used
430 *  to manage each thread.
431 *
432 *  @note It is critical that proxies and threads have identical
433 *        memory images for the shared part.
434 */
435typedef enum {
436  /** This value is for the Classic RTEMS API. */
437  THREAD_API_RTEMS,
438  /** This value is for the POSIX API. */
439  THREAD_API_POSIX
440}  Thread_APIs;
441
442/** This macro defines the first API which has threads. */
443#define THREAD_API_FIRST THREAD_API_RTEMS
444
445/** This macro defines the last API which has threads. */
446#define THREAD_API_LAST  THREAD_API_POSIX
447
448typedef struct Thread_Action Thread_Action;
449
450/**
451 * @brief Thread action handler.
452 *
453 * The thread action handler will be called with interrupts disabled and a
454 * corresponding lock acquired, e.g. _Thread_State_acquire().  The handler must
455 * release the corresponding lock, e.g. _Thread_State_release().  So, the
456 * corresponding lock may be used to protect private data used by the
457 * particular action.
458 *
459 * Since the action is passed to the handler additional data may be accessed
460 * via RTEMS_CONTAINER_OF().
461 *
462 * @param[in] the_thread The thread performing the action.
463 * @param[in] action The thread action.
464 * @param[in] lock_context The lock context to use for the lock release.
465 */
466typedef void ( *Thread_Action_handler )(
467  Thread_Control   *the_thread,
468  Thread_Action    *action,
469  ISR_lock_Context *lock_context
470);
471
472/**
473 * @brief Thread action.
474 *
475 * Thread actions can be chained together to trigger a set of actions on
476 * particular events like for example a thread post-switch.  Use
477 * _Thread_Action_initialize() to initialize this structure.
478 *
479 * Thread actions are the building block for efficient implementation of
480 * - Classic signals delivery,
481 * - POSIX signals delivery, and
482 * - thread life-cycle changes.
483 *
484 * @see _Thread_Add_post_switch_action() and _Thread_Run_post_switch_actions().
485 */
486struct Thread_Action {
487  Chain_Node            Node;
488  Thread_Action_handler handler;
489};
490
491/**
492 * @brief Per-thread information for POSIX Keys.
493 */
494typedef struct {
495  /**
496   * @brief Key value pairs registered for this thread.
497   */
498  RBTree_Control Key_value_pairs;
499
500  /**
501   * @brief Lock to protect the tree operations.
502   */
503  ISR_LOCK_MEMBER( Lock )
504} Thread_Keys_information;
505
506/**
507 * @brief Control block to manage thread actions.
508 *
509 * Use _Thread_Action_control_initialize() to initialize this structure.
510 */
511typedef struct {
512  Chain_Control Chain;
513} Thread_Action_control;
514
515/**
516 * @brief Thread life states.
517 *
518 * The thread life states are orthogonal to the thread states used for
519 * synchronization primitives and blocking operations.  They reflect the state
520 * changes triggered with thread restart and delete requests.
521 */
522typedef enum {
523  THREAD_LIFE_NORMAL = 0x0,
524  THREAD_LIFE_PROTECTED = 0x1,
525  THREAD_LIFE_RESTARTING = 0x2,
526  THREAD_LIFE_PROTECTED_RESTARTING = 0x3,
527  THREAD_LIFE_TERMINATING = 0x4,
528  THREAD_LIFE_PROTECTED_TERMINATING = 0x5,
529  THREAD_LIFE_RESTARTING_TERMINATING = 0x6,
530  THREAD_LIFE_PROTECTED_RESTARTING_TERMINATING = 0x7
531} Thread_Life_state;
532
533/**
534 * @brief Thread life control.
535 */
536typedef struct {
537  /**
538   * @brief Thread life action used to react upon thread restart and delete
539   * requests.
540   */
541  Thread_Action      Action;
542
543  /**
544   * @brief The current thread life state.
545   */
546  Thread_Life_state  state;
547
548  /**
549   * @brief The terminator thread of this thread.
550   *
551   * In case the thread is terminated and another thread (the terminator) waits
552   * for the actual termination completion, then this field references the
553   * terminator thread.
554   */
555  Thread_Control    *terminator;
556} Thread_Life_control;
557
558#if defined(RTEMS_SMP)
559/**
560 * @brief The thread state with respect to the scheduler.
561 */
562typedef enum {
563  /**
564   * @brief This thread is blocked with respect to the scheduler.
565   *
566   * This thread uses no scheduler nodes.
567   */
568  THREAD_SCHEDULER_BLOCKED,
569
570  /**
571   * @brief This thread is scheduled with respect to the scheduler.
572   *
573   * This thread executes using one of its scheduler nodes.  This could be its
574   * own scheduler node or in case it owns resources taking part in the
575   * scheduler helping protocol a scheduler node of another thread.
576   */
577  THREAD_SCHEDULER_SCHEDULED,
578
579  /**
580   * @brief This thread is ready with respect to the scheduler.
581   *
582   * None of the scheduler nodes of this thread is scheduled.
583   */
584  THREAD_SCHEDULER_READY
585} Thread_Scheduler_state;
586#endif
587
588/**
589 * @brief Thread scheduler control.
590 */
591typedef struct {
592#if defined(RTEMS_SMP)
593  /**
594   * @brief The current scheduler state of this thread.
595   */
596  Thread_Scheduler_state state;
597
598  /**
599   * @brief The own scheduler control of this thread.
600   *
601   * This field is constant after initialization.
602   */
603  const struct Scheduler_Control *own_control;
604
605  /**
606   * @brief The scheduler control of this thread.
607   *
608   * The scheduler helping protocol may change this field.
609   */
610  const struct Scheduler_Control *control;
611
612  /**
613   * @brief The own scheduler node of this thread.
614   *
615   * This field is constant after initialization.  It is used by change
616   * priority and ask for help operations.
617   */
618  struct Scheduler_Node *own_node;
619#endif
620
621  /**
622   * @brief The scheduler node of this thread.
623   *
624   * On uni-processor configurations this field is constant after
625   * initialization.
626   *
627   * On SMP configurations the scheduler helping protocol may change this
628   * field.
629   */
630  struct Scheduler_Node *node;
631
632#if defined(RTEMS_SMP)
633  /**
634   * @brief The processor assigned by the current scheduler.
635   */
636  struct Per_CPU_Control *cpu;
637
638#if defined(RTEMS_DEBUG)
639  /**
640   * @brief The processor on which this thread executed the last time or is
641   * executing.
642   */
643  struct Per_CPU_Control *debug_real_cpu;
644#endif
645#endif
646} Thread_Scheduler_control;
647
648typedef struct  {
649  uint32_t      flags;
650  void *        control;
651}Thread_Capture_control;
652
653#if defined(RTEMS_SMP)
654/**
655 * @brief Thread lock control.
656 *
657 * The thread lock is either the default lock or the lock of the resource on
658 * which the thread is currently blocked.  The generation number takes care
659 * that the up to date lock is used.  Only resources using fine grained locking
660 * provide their own lock.
661 *
662 * The thread lock protects the following thread variables
663 *  - Thread_Control::current_priority,
664 *  - Thread_Control::Wait::queue, and
665 *  - Thread_Control::Wait::operations.
666 *
667 * @see _Thread_Lock_acquire(), _Thread_Lock_release(), _Thread_Lock_set() and
668 * _Thread_Lock_restore_default().
669 */
670typedef struct {
671  /**
672   * @brief The current thread lock.
673   *
674   * This is a plain ticket lock without SMP lock statistics support.  This
675   * enables external libraries to use thread locks since they are independent
676   * of the actual RTEMS build configuration, e.g. profiling enabled or
677   * disabled.
678   */
679  SMP_ticket_lock_Control *current;
680
681  /**
682   * @brief The default thread lock in case the thread is not blocked on a
683   * resource.
684   */
685  SMP_ticket_lock_Control Default;
686
687#if defined(RTEMS_PROFILING)
688  /**
689   * @brief The thread lock statistics.
690   *
691   * These statistics are used by the executing thread in case it acquires a
692   * thread lock.  Thus the statistics are an aggregation of acquire and
693   * release operations of diffent locks.
694   */
695  SMP_lock_Stats Stats;
696#endif
697
698  /**
699   * @brief Generation number to invalidate stale locks.
700   */
701  Atomic_Uint generation;
702} Thread_Lock_control;
703#endif
704
705/**
706 *  This structure defines the Thread Control Block (TCB).
707 *
708 *  Uses a leading underscore in the structure name to allow forward
709 *  declarations in standard header files provided by Newlib and GCC.
710 */
711struct _Thread_Control {
712  /** This field is the object management structure for each thread. */
713  Objects_Control          Object;
714
715  /**
716   * @brief Thread queue for thread join operations and multi-purpose lock.
717   *
718   * The lock of this thread queue is used for various purposes.  It protects
719   * the following fields
720   *
721   * - RTEMS_API_Control::Signal, and
722   * - Thread_Control::Post_switch_actions.
723   *
724   * @see _Thread_State_acquire().
725   */
726  Thread_queue_Control     Join_queue;
727
728  /** This field is the current execution state of this thread. */
729  States_Control           current_state;
730
731  /**
732   * @brief This field is the current priority state of this thread.
733   *
734   * Writes to this field are only allowed in _Thread_Initialize() or via
735   * _Thread_Change_priority().
736   */
737  Priority_Control         current_priority;
738
739  /**
740   * @brief This field is the base priority of this thread.
741   *
742   * Writes to this field are only allowed in _Thread_Initialize() or via
743   * _Thread_Change_priority().
744   */
745  Priority_Control         real_priority;
746
747  /**
748   * @brief Generation of the current priority value.
749   *
750   * It is used in _Thread_Change_priority() to serialize the update of
751   * priority related data structures.
752   */
753  uint32_t                 priority_generation;
754
755  /**
756   * @brief Hints if a priority restore is necessary once the resource count
757   * changes from one to zero.
758   *
759   * This is an optimization to speed up the mutex surrender sequence in case
760   * no attempt to change the priority was made during the mutex ownership.  On
761   * SMP configurations atomic fences must synchronize writes to
762   * Thread_Control::priority_restore_hint and Thread_Control::resource_count.
763   */
764  bool                     priority_restore_hint;
765
766  /** This field is the number of mutexes currently held by this thread. */
767  uint32_t                 resource_count;
768  /** This field is the blocking information for this thread. */
769  Thread_Wait_information  Wait;
770  /** This field is the Watchdog used to manage thread delays and timeouts. */
771  Thread_Timer_information Timer;
772#if defined(RTEMS_MULTIPROCESSING)
773  /** This field is the received response packet in an MP system. */
774  MP_packet_Prefix        *receive_packet;
775#endif
776     /*================= end of common block =================*/
777
778#if defined(RTEMS_SMP)
779  /**
780   * @brief Thread lock control.
781   */
782  Thread_Lock_control Lock;
783#endif
784
785#if defined(RTEMS_SMP) && defined(RTEMS_PROFILING)
786  /**
787   * @brief Potpourri lock statistics.
788   *
789   * These SMP lock statistics are used for all lock objects that lack a
790   * storage space for the statistics.  Examples are lock objects used in
791   * external libraries which are independent of the actual RTEMS build
792   * configuration.
793   */
794  SMP_lock_Stats Potpourri_stats;
795#endif
796
797#if defined(RTEMS_SMP)
798  /**
799   * @brief Resource node to build a dependency tree in case this thread owns
800   * resources or depends on a resource.
801   */
802  Resource_Node            Resource_node;
803#endif
804#if defined(RTEMS_MULTIPROCESSING)
805  /** This field is true if the thread is offered globally */
806  bool                                  is_global;
807#endif
808  /** This field is true if the thread is preemptible. */
809  bool                                  is_preemptible;
810  /** This field is true if the thread uses the floating point unit. */
811  bool                                  is_fp;
812
813  /**
814   * @brief Scheduler related control.
815   */
816  Thread_Scheduler_control              Scheduler;
817
818#if __RTEMS_ADA__
819  /** This field is the GNAT self context pointer. */
820  void                                 *rtems_ada_self;
821#endif
822  /** This field is the length of the time quantum that this thread is
823   *  allowed to consume.  The algorithm used to manage limits on CPU usage
824   *  is specified by budget_algorithm.
825   */
826  uint32_t                              cpu_time_budget;
827  /** This field is the algorithm used to manage this thread's time
828   *  quantum.  The algorithm may be specified as none which case,
829   *  no limit is in place.
830   */
831  Thread_CPU_budget_algorithms          budget_algorithm;
832  /** This field is the method invoked with the budgeted time is consumed. */
833  Thread_CPU_budget_algorithm_callout   budget_callout;
834  /** This field is the amount of CPU time consumed by this thread
835   *  since it was created.
836   */
837  Timestamp_Control                     cpu_time_used;
838
839  /** This field contains information about the starting state of
840   *  this thread.
841   */
842  Thread_Start_information              Start;
843
844  Thread_Action_control                 Post_switch_actions;
845
846  /** This field contains the context of this thread. */
847  Context_Control                       Registers;
848#if ( CPU_HARDWARE_FP == TRUE ) || ( CPU_SOFTWARE_FP == TRUE )
849  /** This field points to the floating point context for this thread.
850   *  If NULL, the thread is integer only.
851   */
852  Context_Control_fp                   *fp_context;
853#endif
854  /** This field points to the newlib reentrancy structure for this thread. */
855  struct _reent                        *libc_reent;
856  /** This array contains the API extension area pointers. */
857  void                                 *API_Extensions[ THREAD_API_LAST + 1 ];
858
859  /**
860   * @brief The POSIX Keys information.
861   */
862  Thread_Keys_information               Keys;
863
864  /**
865   * @brief Thread life-cycle control.
866   *
867   * Control state changes triggered by thread restart and delete requests.
868   */
869  Thread_Life_control                   Life;
870
871  Thread_Capture_control                Capture;
872
873  /**
874   * @brief LIFO list of POSIX cleanup contexts.
875   */
876  struct _pthread_cleanup_context *last_cleanup_context;
877
878  /**
879   * @brief LIFO list of user extensions iterators.
880   */
881  struct User_extensions_Iterator *last_user_extensions_iterator;
882
883  /**
884   * @brief Variable length array of user extension pointers.
885   *
886   * The length is defined by the application via <rtems/confdefs.h>.
887   */
888  void                                 *extensions[ RTEMS_ZERO_LENGTH_ARRAY ];
889};
890
891#if (CPU_PROVIDES_IDLE_THREAD_BODY == FALSE)
892/**
893 *  This routine is the body of the system idle thread.
894 *
895 *  NOTE: This routine is actually instantiated by confdefs.h when needed.
896 */
897void *_Thread_Idle_body(
898  uintptr_t  ignored
899);
900#endif
901
902/**  This defines the type for a method which operates on a single thread.
903 */
904typedef void (*rtems_per_thread_routine)( Thread_Control * );
905
906/**
907 *  @brief Iterates over all threads.
908 *  This routine iterates over all threads regardless of API and
909 *  invokes the specified routine.
910 */
911void rtems_iterate_over_all_threads(
912  rtems_per_thread_routine routine
913);
914
915/**
916 * @brief Thread control add-on.
917 */
918typedef struct {
919  /**
920   * @brief Offset of the pointer field in Thread_Control referencing an
921   * application configuration dependent memory area in the thread control
922   * block.
923   */
924  size_t destination_offset;
925
926  /**
927   * @brief Offset relative to the thread control block begin to an application
928   * configuration dependent memory area.
929   */
930  size_t source_offset;
931} Thread_Control_add_on;
932
933/**
934 * @brief Thread control add-ons.
935 *
936 * The thread control block contains fields that point to application
937 * configuration dependent memory areas, like the scheduler information, the
938 * API control blocks, the user extension context table, and the Newlib
939 * re-entrancy support.  Account for these areas in the configuration and
940 * avoid extra workspace allocations for these areas.
941 *
942 * This array is provided via <rtems/confdefs.h>.
943 *
944 * @see _Thread_Control_add_on_count and _Thread_Control_size.
945 */
946extern const Thread_Control_add_on _Thread_Control_add_ons[];
947
948/**
949 * @brief Thread control add-on count.
950 *
951 * Count of entries in _Thread_Control_add_ons.
952 *
953 * This value is provided via <rtems/confdefs.h>.
954 */
955extern const size_t _Thread_Control_add_on_count;
956
957/**
958 * @brief Size of the thread control block of a particular application.
959 *
960 * This value is provided via <rtems/confdefs.h>.
961 *
962 * @see _Thread_Control_add_ons.
963 */
964extern const size_t _Thread_Control_size;
965
966/**@}*/
967
968#ifdef __cplusplus
969}
970#endif
971
972#endif
973/* end of include file */
Note: See TracBrowser for help on using the repository browser.