source: rtems/cpukit/score/include/rtems/score/thread.h @ 0e3c59d6

5
Last change on this file since 0e3c59d6 was 0e3c59d6, checked in by Sebastian Huber <sebastian.huber@…>, on 06/26/15 at 10:54:33

score: Use a plain ticket lock for thread locks

This enables external libraries to use thread locks since they are
independent of the actual RTEMS build configuration, e.g. profiling
enabled or disabled.

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