source: rtems/cpukit/score/include/rtems/score/thread.h @ 500a8e9c

5
Last change on this file since 500a8e9c was 500a8e9c, checked in by Sebastian Huber <sebastian.huber@…>, on 04/28/16 at 04:26:01

score: Delete RTEMS_STRICT_ORDER_MUTEX

Remove support for strict order mutexes.

Close #2124.

  • Property mode set to 100644
File size: 28.8 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#if !defined(RTEMS_SMP)
177/**
178 *  @brief Forward reference to the per task variable structure..
179 *
180 *  Forward reference to the per task variable structure.
181 */
182struct rtems_task_variable_tt;
183
184/**
185 *  @brief Internal structure used to manager per task variables.
186 *
187 *  This is the internal structure used to manager per Task Variables.
188 */
189typedef struct {
190  /** This field points to the next per task variable for this task. */
191  struct rtems_task_variable_tt  *next;
192  /** This field points to the physical memory location of this per
193   *  task variable.
194   */
195  void                          **ptr;
196  /** This field is to the global value for this per task variable. */
197  void                           *gval;
198  /** This field is to this thread's value for this per task variable. */
199  void                           *tval;
200  /** This field points to the destructor for this per task variable. */
201  void                          (*dtor)(void *);
202} rtems_task_variable_t;
203#endif
204
205/**
206 *  The following structure contains the information which defines
207 *  the starting state of a thread.
208 */
209typedef struct {
210  /** This field contains the thread entry information. */
211  Thread_Entry_information             Entry;
212  /*-------------- initial execution modes ----------------- */
213  /** This field indicates whether the thread was preemptible when
214    * it started.
215    */
216  bool                                 is_preemptible;
217  /** This field indicates the CPU budget algorith. */
218  Thread_CPU_budget_algorithms         budget_algorithm;
219  /** This field is the routine to invoke when the CPU allotment is
220   *  consumed.
221   */
222  Thread_CPU_budget_algorithm_callout  budget_callout;
223  /** This field is the initial ISR disable level of this thread. */
224  uint32_t                             isr_level;
225  /** This field is the initial priority. */
226  Priority_Control                     initial_priority;
227  #if defined(RTEMS_SCORE_THREAD_ENABLE_USER_PROVIDED_STACK_VIA_API)
228    /** This field indicates whether the SuperCore allocated the stack. */
229    bool                                 core_allocated_stack;
230  #endif
231  /** This field is the stack information. */
232  Stack_Control                        Initial_stack;
233  #if ( CPU_HARDWARE_FP == TRUE ) || ( CPU_SOFTWARE_FP == TRUE )
234    /** This field is the initial FP context area address. */
235    Context_Control_fp                  *fp_context;
236  #endif
237  /** This field is the initial stack area address. */
238  void                                *stack;
239  /** The thread-local storage (TLS) area */
240  void                                *tls_area;
241} Thread_Start_information;
242
243/**
244 *  @brief Union type to hold a pointer to an immutable or a mutable object.
245 *
246 *  The main purpose is to enable passing of pointers to read-only send buffers
247 *  in the message passing subsystem.  This approach is somewhat fragile since
248 *  it prevents the compiler to check if the operations on objects are valid
249 *  with respect to the constant qualifier.  An alternative would be to add a
250 *  third pointer argument for immutable objects, but this would increase the
251 *  structure size.
252 */
253typedef union {
254  void       *mutable_object;
255  const void *immutable_object;
256} Thread_Wait_information_Object_argument_type;
257
258/**
259 * @brief This type is able to contain several flags used to control the wait
260 * class and state of a thread.
261 *
262 * The mutually exclusive wait class flags are
263 * - @ref THREAD_WAIT_CLASS_EVENT,
264 * - @ref THREAD_WAIT_CLASS_SYSTEM_EVENT, and
265 * - @ref THREAD_WAIT_CLASS_OBJECT.
266 *
267 * The mutually exclusive wait state flags are
268 * - @ref THREAD_WAIT_STATE_INTEND_TO_BLOCK,
269 * - @ref THREAD_WAIT_STATE_BLOCKED, and
270 * - @ref THREAD_WAIT_STATE_READY_AGAIN.
271 */
272typedef unsigned int Thread_Wait_flags;
273
274/**
275 *  @brief Information required to manage a thread while it is blocked.
276 *
277 *  This contains the information required to manage a thread while it is
278 *  blocked and to return information to it.
279 */
280typedef struct {
281  /**
282   * @brief Node for thread queues.
283   */
284  union {
285    /**
286     * @brief A node for chains.
287     */
288    Chain_Node Chain;
289
290    /**
291     * @brief A node for red-black trees.
292     */
293    RBTree_Node RBTree;
294  } Node;
295
296#if defined(RTEMS_MULTIPROCESSING)
297  /*
298   * @brief This field is the identifier of the remote object this thread is
299   * waiting upon.
300   */
301  Objects_Id            remote_id;
302#endif
303  /** This field is used to return an integer while when blocked. */
304  uint32_t              count;
305  /** This field is for a pointer to a user return argument. */
306  void                 *return_argument;
307  /** This field is for a pointer to a second user return argument. */
308  Thread_Wait_information_Object_argument_type
309                        return_argument_second;
310  /** This field contains any options in effect on this blocking operation. */
311  uint32_t              option;
312  /** This field will contain the return status from a blocking operation.
313   *
314   *  @note The following assumes that all API return codes can be
315   *        treated as an uint32_t.
316   */
317  uint32_t              return_code;
318
319  /**
320   * @brief Code to set the timeout return code in _Thread_Timeout().
321   */
322  uint32_t timeout_code;
323
324  /**
325   * @brief The current thread queue.
326   *
327   * In case this field is @c NULL, then the thread is not blocked on a thread
328   * queue.  This field is protected by the thread lock.
329   *
330   * @see _Thread_Lock_set() and _Thread_Wait_set_queue().
331   */
332  Thread_queue_Queue *queue;
333
334  /**
335   * @brief This field contains several flags used to control the wait class
336   * and state of a thread in case fine-grained locking is used.
337   */
338#if defined(RTEMS_SMP)
339  Atomic_Uint           flags;
340#else
341  Thread_Wait_flags     flags;
342#endif
343
344  /**
345   * @brief The current thread queue operations.
346   *
347   * This field is protected by the thread lock.
348   *
349   * @see _Thread_Lock_set() and _Thread_Wait_set_operations().
350   */
351  const Thread_queue_Operations *operations;
352
353  Thread_queue_Heads *spare_heads;
354}   Thread_Wait_information;
355
356/**
357 * @brief Information required to manage a thread timer.
358 */
359typedef struct {
360  ISR_LOCK_MEMBER( Lock )
361  Watchdog_Header *header;
362  Watchdog_Control Watchdog;
363} Thread_Timer_information;
364
365/**
366 *  The following defines the control block used to manage
367 *  each thread proxy.
368 *
369 *  @note It is critical that proxies and threads have identical
370 *        memory images for the shared part.
371 */
372typedef struct {
373  /** This field is the object management structure for each proxy. */
374  Objects_Control          Object;
375  /** This field is the current execution state of this proxy. */
376  States_Control           current_state;
377
378  /**
379   * @brief This field is the current priority state of this thread.
380   *
381   * Writes to this field are only allowed in _Thread_Initialize() or via
382   * _Thread_Change_priority().
383   */
384  Priority_Control         current_priority;
385
386  /**
387   * @brief This field is the base priority of this thread.
388   *
389   * Writes to this field are only allowed in _Thread_Initialize() or via
390   * _Thread_Change_priority().
391   */
392  Priority_Control         real_priority;
393
394  /**
395   * @brief Generation of the current priority value.
396   *
397   * It is used in _Thread_Change_priority() to serialize the update of
398   * priority related data structures.
399   */
400  uint32_t                 priority_generation;
401
402  /**
403   * @brief Hints if a priority restore is necessary once the resource count
404   * changes from one to zero.
405   *
406   * This is an optimization to speed up the mutex surrender sequence in case
407   * no attempt to change the priority was made during the mutex ownership.  On
408   * SMP configurations atomic fences must synchronize writes to
409   * Thread_Control::priority_restore_hint and Thread_Control::resource_count.
410   */
411  bool                     priority_restore_hint;
412
413  /** This field is the number of mutexes currently held by this proxy. */
414  uint32_t                 resource_count;
415
416  /** This field is the blocking information for this proxy. */
417  Thread_Wait_information  Wait;
418  /** This field is the Watchdog used to manage proxy delays and timeouts. */
419  Thread_Timer_information Timer;
420#if defined(RTEMS_MULTIPROCESSING)
421  /** This field is the received response packet in an MP system. */
422  MP_packet_Prefix        *receive_packet;
423     /****************** end of common block ********************/
424
425  /**
426   * @brief Thread queue callout for _Thread_queue_Enqueue_critical().
427   */
428  Thread_queue_MP_callout  thread_queue_callout;
429
430  /**
431   * @brief Thread queue object identifier for
432   * _Thread_queue_Enqueue_critical().
433   */
434  Objects_Id               thread_queue_id;
435
436  /**
437   * @brief This field is used to manage the set of active proxies in the system.
438   */
439  RBTree_Node              Active;
440
441  /**
442   * @brief Provide thread queue heads for this thread proxy.
443   *
444   * The actual size of the thread queue heads depends on the application
445   * configuration.  Since thread proxies are never destroyed we can use the
446   * same storage place for the thread queue heads.
447   */
448  Thread_queue_Heads       Thread_queue_heads[ RTEMS_ZERO_LENGTH_ARRAY ];
449#endif
450}   Thread_Proxy_control;
451
452/**
453 *  The following record defines the control block used
454 *  to manage each thread.
455 *
456 *  @note It is critical that proxies and threads have identical
457 *        memory images for the shared part.
458 */
459typedef enum {
460  /** This value is for the Classic RTEMS API. */
461  THREAD_API_RTEMS,
462  /** This value is for the POSIX API. */
463  THREAD_API_POSIX
464}  Thread_APIs;
465
466/** This macro defines the first API which has threads. */
467#define THREAD_API_FIRST THREAD_API_RTEMS
468
469/** This macro defines the last API which has threads. */
470#define THREAD_API_LAST  THREAD_API_POSIX
471
472typedef struct Thread_Action Thread_Action;
473
474/**
475 * @brief Thread action handler.
476 *
477 * The thread action handler will be called with interrupts disabled and the
478 * thread action lock acquired.  The handler must release the thread action
479 * lock with _Thread_Action_release_and_ISR_enable().  So the thread action
480 * lock can be used to protect private data fields of the particular action.
481 *
482 * Since the action is passed to the handler private data fields can be added
483 * below the common thread action fields.
484 *
485 * @param[in] thread The thread performing the action.
486 * @param[in] action The thread action.
487 * @param[in] cpu The processor of the thread.
488 * @param[in] level The ISR level for _Thread_Action_release_and_ISR_enable().
489 */
490typedef void ( *Thread_Action_handler )(
491  Thread_Control         *thread,
492  Thread_Action          *action,
493  struct Per_CPU_Control *cpu,
494  ISR_Level               level
495);
496
497/**
498 * @brief Thread action.
499 *
500 * Thread actions can be chained together to trigger a set of actions on
501 * particular events like for example a thread post-switch.  Use
502 * _Thread_Action_initialize() to initialize this structure.
503 *
504 * Thread actions are the building block for efficient implementation of
505 * - Classic signals delivery,
506 * - POSIX signals delivery,
507 * - thread restart notification,
508 * - thread delete notification,
509 * - forced thread migration on SMP configurations, and
510 * - the Multiprocessor Resource Sharing Protocol (MrsP).
511 *
512 * @see _Thread_Run_post_switch_actions().
513 */
514struct Thread_Action {
515  Chain_Node            Node;
516  Thread_Action_handler handler;
517};
518
519/**
520 * @brief Per-thread information for POSIX Keys.
521 */
522typedef struct {
523  /**
524   * @brief Key value pairs registered for this thread.
525   */
526  RBTree_Control Key_value_pairs;
527
528  /**
529   * @brief Lock to protect the tree operations.
530   */
531  ISR_LOCK_MEMBER( Lock )
532} Thread_Keys_information;
533
534/**
535 * @brief Control block to manage thread actions.
536 *
537 * Use _Thread_Action_control_initialize() to initialize this structure.
538 */
539typedef struct {
540  Chain_Control Chain;
541} Thread_Action_control;
542
543/**
544 * @brief Thread life states.
545 *
546 * The thread life states are orthogonal to the thread states used for
547 * synchronization primitives and blocking operations.  They reflect the state
548 * changes triggered with thread restart and delete requests.
549 */
550typedef enum {
551  THREAD_LIFE_NORMAL = 0x0,
552  THREAD_LIFE_PROTECTED = 0x1,
553  THREAD_LIFE_RESTARTING = 0x2,
554  THREAD_LIFE_PROTECTED_RESTARTING = 0x3,
555  THREAD_LIFE_TERMINATING = 0x4,
556  THREAD_LIFE_PROTECTED_TERMINATING = 0x5,
557  THREAD_LIFE_RESTARTING_TERMINATING = 0x6,
558  THREAD_LIFE_PROTECTED_RESTARTING_TERMINATING = 0x7
559} Thread_Life_state;
560
561/**
562 * @brief Thread life control.
563 */
564typedef struct {
565  /**
566   * @brief Thread life action used to react upon thread restart and delete
567   * requests.
568   */
569  Thread_Action      Action;
570
571  /**
572   * @brief The current thread life state.
573   */
574  Thread_Life_state  state;
575
576  /**
577   * @brief The terminator thread of this thread.
578   *
579   * In case the thread is terminated and another thread (the terminator) waits
580   * for the actual termination completion, then this field references the
581   * terminator thread.
582   */
583  Thread_Control    *terminator;
584} Thread_Life_control;
585
586#if defined(RTEMS_SMP)
587/**
588 * @brief The thread state with respect to the scheduler.
589 */
590typedef enum {
591  /**
592   * @brief This thread is blocked with respect to the scheduler.
593   *
594   * This thread uses no scheduler nodes.
595   */
596  THREAD_SCHEDULER_BLOCKED,
597
598  /**
599   * @brief This thread is scheduled with respect to the scheduler.
600   *
601   * This thread executes using one of its scheduler nodes.  This could be its
602   * own scheduler node or in case it owns resources taking part in the
603   * scheduler helping protocol a scheduler node of another thread.
604   */
605  THREAD_SCHEDULER_SCHEDULED,
606
607  /**
608   * @brief This thread is ready with respect to the scheduler.
609   *
610   * None of the scheduler nodes of this thread is scheduled.
611   */
612  THREAD_SCHEDULER_READY
613} Thread_Scheduler_state;
614#endif
615
616/**
617 * @brief Thread scheduler control.
618 */
619typedef struct {
620#if defined(RTEMS_SMP)
621  /**
622   * @brief The current scheduler state of this thread.
623   */
624  Thread_Scheduler_state state;
625
626  /**
627   * @brief The own scheduler control of this thread.
628   *
629   * This field is constant after initialization.
630   */
631  const struct Scheduler_Control *own_control;
632
633  /**
634   * @brief The scheduler control of this thread.
635   *
636   * The scheduler helping protocol may change this field.
637   */
638  const struct Scheduler_Control *control;
639
640  /**
641   * @brief The own scheduler node of this thread.
642   *
643   * This field is constant after initialization.  It is used by change
644   * priority and ask for help operations.
645   */
646  struct Scheduler_Node *own_node;
647#endif
648
649  /**
650   * @brief The scheduler node of this thread.
651   *
652   * On uni-processor configurations this field is constant after
653   * initialization.
654   *
655   * On SMP configurations the scheduler helping protocol may change this
656   * field.
657   */
658  struct Scheduler_Node *node;
659
660#if defined(RTEMS_SMP)
661  /**
662   * @brief The processor assigned by the current scheduler.
663   */
664  struct Per_CPU_Control *cpu;
665
666#if defined(RTEMS_DEBUG)
667  /**
668   * @brief The processor on which this thread executed the last time or is
669   * executing.
670   */
671  struct Per_CPU_Control *debug_real_cpu;
672#endif
673#endif
674} Thread_Scheduler_control;
675
676typedef struct  {
677  uint32_t      flags;
678  void *        control;
679}Thread_Capture_control;
680
681#if defined(RTEMS_SMP)
682/**
683 * @brief Thread lock control.
684 *
685 * The thread lock is either the default lock or the lock of the resource on
686 * which the thread is currently blocked.  The generation number takes care
687 * that the up to date lock is used.  Only resources using fine grained locking
688 * provide their own lock.
689 *
690 * The thread lock protects the following thread variables
691 *  - Thread_Control::current_priority,
692 *  - Thread_Control::Wait::queue, and
693 *  - Thread_Control::Wait::operations.
694 *
695 * @see _Thread_Lock_acquire(), _Thread_Lock_release(), _Thread_Lock_set() and
696 * _Thread_Lock_restore_default().
697 */
698typedef struct {
699  /**
700   * @brief The current thread lock.
701   *
702   * This is a plain ticket lock without SMP lock statistics support.  This
703   * enables external libraries to use thread locks since they are independent
704   * of the actual RTEMS build configuration, e.g. profiling enabled or
705   * disabled.
706   */
707  SMP_ticket_lock_Control *current;
708
709  /**
710   * @brief The default thread lock in case the thread is not blocked on a
711   * resource.
712   */
713  SMP_ticket_lock_Control Default;
714
715#if defined(RTEMS_PROFILING)
716  /**
717   * @brief The thread lock statistics.
718   *
719   * These statistics are used by the executing thread in case it acquires a
720   * thread lock.  Thus the statistics are an aggregation of acquire and
721   * release operations of diffent locks.
722   */
723  SMP_lock_Stats Stats;
724#endif
725
726  /**
727   * @brief Generation number to invalidate stale locks.
728   */
729  Atomic_Uint generation;
730} Thread_Lock_control;
731#endif
732
733/**
734 *  This structure defines the Thread Control Block (TCB).
735 *
736 *  Uses a leading underscore in the structure name to allow forward
737 *  declarations in standard header files provided by Newlib and GCC.
738 */
739struct _Thread_Control {
740  /** This field is the object management structure for each thread. */
741  Objects_Control          Object;
742  /** This field is the current execution state of this thread. */
743  States_Control           current_state;
744
745  /**
746   * @brief This field is the current priority state of this thread.
747   *
748   * Writes to this field are only allowed in _Thread_Initialize() or via
749   * _Thread_Change_priority().
750   */
751  Priority_Control         current_priority;
752
753  /**
754   * @brief This field is the base priority of this thread.
755   *
756   * Writes to this field are only allowed in _Thread_Initialize() or via
757   * _Thread_Change_priority().
758   */
759  Priority_Control         real_priority;
760
761  /**
762   * @brief Generation of the current priority value.
763   *
764   * It is used in _Thread_Change_priority() to serialize the update of
765   * priority related data structures.
766   */
767  uint32_t                 priority_generation;
768
769  /**
770   * @brief Hints if a priority restore is necessary once the resource count
771   * changes from one to zero.
772   *
773   * This is an optimization to speed up the mutex surrender sequence in case
774   * no attempt to change the priority was made during the mutex ownership.  On
775   * SMP configurations atomic fences must synchronize writes to
776   * Thread_Control::priority_restore_hint and Thread_Control::resource_count.
777   */
778  bool                     priority_restore_hint;
779
780  /** This field is the number of mutexes currently held by this thread. */
781  uint32_t                 resource_count;
782  /** This field is the blocking information for this thread. */
783  Thread_Wait_information  Wait;
784  /** This field is the Watchdog used to manage thread delays and timeouts. */
785  Thread_Timer_information Timer;
786#if defined(RTEMS_MULTIPROCESSING)
787  /** This field is the received response packet in an MP system. */
788  MP_packet_Prefix        *receive_packet;
789#endif
790     /*================= end of common block =================*/
791
792#if defined(RTEMS_SMP)
793  /**
794   * @brief Thread lock control.
795   */
796  Thread_Lock_control Lock;
797#endif
798
799#if defined(RTEMS_SMP) && defined(RTEMS_PROFILING)
800  /**
801   * @brief Potpourri lock statistics.
802   *
803   * These SMP lock statistics are used for all lock objects that lack a
804   * storage space for the statistics.  Examples are lock objects used in
805   * external libraries which are independent of the actual RTEMS build
806   * configuration.
807   */
808  SMP_lock_Stats Potpourri_stats;
809#endif
810
811#if defined(RTEMS_SMP)
812  /**
813   * @brief Resource node to build a dependency tree in case this thread owns
814   * resources or depends on a resource.
815   */
816  Resource_Node            Resource_node;
817#endif
818#if defined(RTEMS_MULTIPROCESSING)
819  /** This field is true if the thread is offered globally */
820  bool                                  is_global;
821#endif
822  /** This field is true if the thread is preemptible. */
823  bool                                  is_preemptible;
824  /** This field is true if the thread uses the floating point unit. */
825  bool                                  is_fp;
826
827  /**
828   * @brief Scheduler related control.
829   */
830  Thread_Scheduler_control              Scheduler;
831
832#if __RTEMS_ADA__
833  /** This field is the GNAT self context pointer. */
834  void                                 *rtems_ada_self;
835#endif
836  /** This field is the length of the time quantum that this thread is
837   *  allowed to consume.  The algorithm used to manage limits on CPU usage
838   *  is specified by budget_algorithm.
839   */
840  uint32_t                              cpu_time_budget;
841  /** This field is the algorithm used to manage this thread's time
842   *  quantum.  The algorithm may be specified as none which case,
843   *  no limit is in place.
844   */
845  Thread_CPU_budget_algorithms          budget_algorithm;
846  /** This field is the method invoked with the budgeted time is consumed. */
847  Thread_CPU_budget_algorithm_callout   budget_callout;
848  /** This field is the amount of CPU time consumed by this thread
849   *  since it was created.
850   */
851  Timestamp_Control                     cpu_time_used;
852
853  /** This field contains information about the starting state of
854   *  this thread.
855   */
856  Thread_Start_information              Start;
857
858  Thread_Action_control                 Post_switch_actions;
859
860  /** This field contains the context of this thread. */
861  Context_Control                       Registers;
862#if ( CPU_HARDWARE_FP == TRUE ) || ( CPU_SOFTWARE_FP == TRUE )
863  /** This field points to the floating point context for this thread.
864   *  If NULL, the thread is integer only.
865   */
866  Context_Control_fp                   *fp_context;
867#endif
868  /** This field points to the newlib reentrancy structure for this thread. */
869  struct _reent                        *libc_reent;
870  /** This array contains the API extension area pointers. */
871  void                                 *API_Extensions[ THREAD_API_LAST + 1 ];
872
873#if !defined(RTEMS_SMP)
874  /** This field points to the set of per task variables. */
875  rtems_task_variable_t                *task_variables;
876#endif
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 LIFO list of POSIX cleanup contexts.
894   */
895  struct _pthread_cleanup_context *last_cleanup_context;
896
897  /**
898   * @brief LIFO list of user extensions iterators.
899   */
900  struct User_extensions_Iterator *last_user_extensions_iterator;
901
902  /**
903   * @brief Variable length array of user extension pointers.
904   *
905   * The length is defined by the application via <rtems/confdefs.h>.
906   */
907  void                                 *extensions[ RTEMS_ZERO_LENGTH_ARRAY ];
908};
909
910#if (CPU_PROVIDES_IDLE_THREAD_BODY == FALSE)
911/**
912 *  This routine is the body of the system idle thread.
913 *
914 *  NOTE: This routine is actually instantiated by confdefs.h when needed.
915 */
916void *_Thread_Idle_body(
917  uintptr_t  ignored
918);
919#endif
920
921/**  This defines the type for a method which operates on a single thread.
922 */
923typedef void (*rtems_per_thread_routine)( Thread_Control * );
924
925/**
926 *  @brief Iterates over all threads.
927 *  This routine iterates over all threads regardless of API and
928 *  invokes the specified routine.
929 */
930void rtems_iterate_over_all_threads(
931  rtems_per_thread_routine routine
932);
933
934/**
935 * @brief Thread control add-on.
936 */
937typedef struct {
938  /**
939   * @brief Offset of the pointer field in Thread_Control referencing an
940   * application configuration dependent memory area in the thread control
941   * block.
942   */
943  size_t destination_offset;
944
945  /**
946   * @brief Offset relative to the thread control block begin to an application
947   * configuration dependent memory area.
948   */
949  size_t source_offset;
950} Thread_Control_add_on;
951
952/**
953 * @brief Thread control add-ons.
954 *
955 * The thread control block contains fields that point to application
956 * configuration dependent memory areas, like the scheduler information, the
957 * API control blocks, the user extension context table, and the Newlib
958 * re-entrancy support.  Account for these areas in the configuration and
959 * avoid extra workspace allocations for these areas.
960 *
961 * This array is provided via <rtems/confdefs.h>.
962 *
963 * @see _Thread_Control_add_on_count and _Thread_Control_size.
964 */
965extern const Thread_Control_add_on _Thread_Control_add_ons[];
966
967/**
968 * @brief Thread control add-on count.
969 *
970 * Count of entries in _Thread_Control_add_ons.
971 *
972 * This value is provided via <rtems/confdefs.h>.
973 */
974extern const size_t _Thread_Control_add_on_count;
975
976/**
977 * @brief Size of the thread control block of a particular application.
978 *
979 * This value is provided via <rtems/confdefs.h>.
980 *
981 * @see _Thread_Control_add_ons.
982 */
983extern const size_t _Thread_Control_size;
984
985/**@}*/
986
987#ifdef __cplusplus
988}
989#endif
990
991#endif
992/* end of include file */
Note: See TracBrowser for help on using the repository browser.