source: rtems/cpukit/score/include/rtems/score/thread.h @ 57947f1

4.115
Last change on this file since 57947f1 was 57947f1, checked in by Sebastian Huber <sebastian.huber@…>, on 03/23/15 at 14:05:32

score: Add thread lock

Update #2273.

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