source: rtems/cpukit/score/include/rtems/score/thread.h @ 7b35a36

4.115
Last change on this file since 7b35a36 was 6a941e3, checked in by Sebastian Huber <sebastian.huber@…>, on 03/17/15 at 15:24:44

score: Fix _Thread_Change_priority()

Atomically update the current priority of a thread and the wait queue.
Serialize the scheduler update in a separate critical section with a
generation number.

New test sptests/spintrcritical23.

Close #2310.

  • Property mode set to 100644
File size: 25.1 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
377typedef struct Thread_Action Thread_Action;
378
379/**
380 * @brief Thread action handler.
381 *
382 * The thread action handler will be called with interrupts disabled and the
383 * thread action lock acquired.  The handler must release the thread action
384 * lock with _Thread_Action_release_and_ISR_enable().  So the thread action
385 * lock can be used to protect private data fields of the particular action.
386 *
387 * Since the action is passed to the handler private data fields can be added
388 * below the common thread action fields.
389 *
390 * @param[in] thread The thread performing the action.
391 * @param[in] action The thread action.
392 * @param[in] cpu The processor of the thread.
393 * @param[in] level The ISR level for _Thread_Action_release_and_ISR_enable().
394 */
395typedef void ( *Thread_Action_handler )(
396  Thread_Control  *thread,
397  Thread_Action   *action,
398  Per_CPU_Control *cpu,
399  ISR_Level        level
400);
401
402/**
403 * @brief Thread action.
404 *
405 * Thread actions can be chained together to trigger a set of actions on
406 * particular events like for example a thread post-switch.  Use
407 * _Thread_Action_initialize() to initialize this structure.
408 *
409 * Thread actions are the building block for efficient implementation of
410 * - Classic signals delivery,
411 * - POSIX signals delivery,
412 * - thread restart notification,
413 * - thread delete notification,
414 * - forced thread migration on SMP configurations, and
415 * - the Multiprocessor Resource Sharing Protocol (MrsP).
416 *
417 * @see _Thread_Run_post_switch_actions().
418 */
419struct Thread_Action {
420  Chain_Node            Node;
421  Thread_Action_handler handler;
422};
423
424/**
425 * @brief Control block to manage thread actions.
426 *
427 * Use _Thread_Action_control_initialize() to initialize this structure.
428 */
429typedef struct {
430  Chain_Control Chain;
431} Thread_Action_control;
432
433/**
434 * @brief Thread life states.
435 *
436 * The thread life states are orthogonal to the thread states used for
437 * synchronization primitives and blocking operations.  They reflect the state
438 * changes triggered with thread restart and delete requests.
439 */
440typedef enum {
441  THREAD_LIFE_NORMAL = 0x0,
442  THREAD_LIFE_PROTECTED = 0x1,
443  THREAD_LIFE_RESTARTING = 0x2,
444  THREAD_LIFE_PROTECTED_RESTARTING = 0x3,
445  THREAD_LIFE_TERMINATING = 0x4,
446  THREAD_LIFE_PROTECTED_TERMINATING = 0x5,
447  THREAD_LIFE_RESTARTING_TERMINATING = 0x6,
448  THREAD_LIFE_PROTECTED_RESTARTING_TERMINATING = 0x7
449} Thread_Life_state;
450
451/**
452 * @brief Thread life control.
453 */
454typedef struct {
455  /**
456   * @brief Thread life action used to react upon thread restart and delete
457   * requests.
458   */
459  Thread_Action      Action;
460
461  /**
462   * @brief The current thread life state.
463   */
464  Thread_Life_state  state;
465
466  /**
467   * @brief The terminator thread of this thread.
468   *
469   * In case the thread is terminated and another thread (the terminator) waits
470   * for the actual termination completion, then this field references the
471   * terminator thread.
472   */
473  Thread_Control    *terminator;
474} Thread_Life_control;
475
476#if defined(RTEMS_SMP)
477/**
478 * @brief The thread state with respect to the scheduler.
479 */
480typedef enum {
481  /**
482   * @brief This thread is blocked with respect to the scheduler.
483   *
484   * This thread uses no scheduler nodes.
485   */
486  THREAD_SCHEDULER_BLOCKED,
487
488  /**
489   * @brief This thread is scheduled with respect to the scheduler.
490   *
491   * This thread executes using one of its scheduler nodes.  This could be its
492   * own scheduler node or in case it owns resources taking part in the
493   * scheduler helping protocol a scheduler node of another thread.
494   */
495  THREAD_SCHEDULER_SCHEDULED,
496
497  /**
498   * @brief This thread is ready with respect to the scheduler.
499   *
500   * None of the scheduler nodes of this thread is scheduled.
501   */
502  THREAD_SCHEDULER_READY
503} Thread_Scheduler_state;
504#endif
505
506/**
507 * @brief Thread scheduler control.
508 */
509typedef struct {
510#if defined(RTEMS_SMP)
511  /**
512   * @brief The current scheduler state of this thread.
513   */
514  Thread_Scheduler_state state;
515
516  /**
517   * @brief The own scheduler control of this thread.
518   *
519   * This field is constant after initialization.
520   */
521  const struct Scheduler_Control *own_control;
522
523  /**
524   * @brief The scheduler control of this thread.
525   *
526   * The scheduler helping protocol may change this field.
527   */
528  const struct Scheduler_Control *control;
529
530  /**
531   * @brief The own scheduler node of this thread.
532   *
533   * This field is constant after initialization.  It is used by change
534   * priority and ask for help operations.
535   */
536  struct Scheduler_Node *own_node;
537#endif
538
539  /**
540   * @brief The scheduler node of this thread.
541   *
542   * On uni-processor configurations this field is constant after
543   * initialization.
544   *
545   * On SMP configurations the scheduler helping protocol may change this
546   * field.
547   */
548  struct Scheduler_Node *node;
549
550#if defined(RTEMS_SMP)
551  /**
552   * @brief The processor assigned by the current scheduler.
553   */
554  Per_CPU_Control *cpu;
555
556#if defined(RTEMS_DEBUG)
557  /**
558   * @brief The processor on which this thread executed the last time or is
559   * executing.
560   */
561  Per_CPU_Control *debug_real_cpu;
562#endif
563#endif
564} Thread_Scheduler_control;
565
566typedef struct  {
567  uint32_t      flags;
568  void *        control;
569}Thread_Capture_control;
570
571/**
572 *  This structure defines the Thread Control Block (TCB).
573 */
574struct Thread_Control_struct {
575  /** This field is the object management structure for each thread. */
576  Objects_Control          Object;
577  /** This field is used to enqueue the thread on RBTrees. */
578  RBTree_Node              RBNode;
579  /** This field is the current execution state of this thread. */
580  States_Control           current_state;
581  /** This field is the current priority state of this thread. */
582  Priority_Control         current_priority;
583  /** This field is the base priority of this thread. */
584  Priority_Control         real_priority;
585
586  /**
587   * @brief Generation of the current priority value.
588   *
589   * It is used in _Thread_Change_priority() to serialize the update of
590   * priority related data structures.
591   */
592  uint32_t                 priority_generation;
593
594  /** This field is the number of mutexes currently held by this thread. */
595  uint32_t                 resource_count;
596  /** This field is the blocking information for this thread. */
597  Thread_Wait_information  Wait;
598  /** This field is the Watchdog used to manage thread delays and timeouts. */
599  Watchdog_Control         Timer;
600#if defined(RTEMS_MULTIPROCESSING)
601  /** This field is the received response packet in an MP system. */
602  MP_packet_Prefix        *receive_packet;
603#endif
604#ifdef __RTEMS_STRICT_ORDER_MUTEX__
605  /** This field is the head of queue of priority inheritance mutex
606   *  held by the thread.
607   */
608  Chain_Control            lock_mutex;
609#endif
610#if defined(RTEMS_SMP)
611  /**
612   * @brief Resource node to build a dependency tree in case this thread owns
613   * resources or depends on a resource.
614   */
615  Resource_Node            Resource_node;
616#endif
617     /*================= end of common block =================*/
618#if defined(RTEMS_MULTIPROCESSING)
619  /** This field is true if the thread is offered globally */
620  bool                                  is_global;
621#endif
622  /** This field is true if the thread is preemptible. */
623  bool                                  is_preemptible;
624
625  /**
626   * @brief Scheduler related control.
627   */
628  Thread_Scheduler_control              Scheduler;
629
630#if __RTEMS_ADA__
631  /** This field is the GNAT self context pointer. */
632  void                                 *rtems_ada_self;
633#endif
634  /** This field is the length of the time quantum that this thread is
635   *  allowed to consume.  The algorithm used to manage limits on CPU usage
636   *  is specified by budget_algorithm.
637   */
638  uint32_t                              cpu_time_budget;
639  /** This field is the algorithm used to manage this thread's time
640   *  quantum.  The algorithm may be specified as none which case,
641   *  no limit is in place.
642   */
643  Thread_CPU_budget_algorithms          budget_algorithm;
644  /** This field is the method invoked with the budgeted time is consumed. */
645  Thread_CPU_budget_algorithm_callout   budget_callout;
646  /** This field is the amount of CPU time consumed by this thread
647   *  since it was created.
648   */
649  Thread_CPU_usage_t                    cpu_time_used;
650
651  /** This field contains information about the starting state of
652   *  this thread.
653   */
654  Thread_Start_information              Start;
655
656  Thread_Action_control                 Post_switch_actions;
657
658  /** This field contains the context of this thread. */
659  Context_Control                       Registers;
660#if ( CPU_HARDWARE_FP == TRUE ) || ( CPU_SOFTWARE_FP == TRUE )
661  /** This field points to the floating point context for this thread.
662   *  If NULL, the thread is integer only.
663   */
664  Context_Control_fp                   *fp_context;
665#endif
666  /** This field points to the newlib reentrancy structure for this thread. */
667  struct _reent                        *libc_reent;
668  /** This array contains the API extension area pointers. */
669  void                                 *API_Extensions[ THREAD_API_LAST + 1 ];
670
671#if !defined(RTEMS_SMP)
672  /** This field points to the set of per task variables. */
673  rtems_task_variable_t                *task_variables;
674#endif
675
676  /**
677   * This is the thread key value chain's control, which is used
678   * to track all key value for specific thread, and when thread
679   * exits, we can remove all key value for specific thread by
680   * iterating this chain, or we have to search a whole rbtree,
681   * which is inefficient.
682   */
683  Chain_Control           Key_Chain;
684
685  /**
686   * @brief Thread life-cycle control.
687   *
688   * Control state changes triggered by thread restart and delete requests.
689   */
690  Thread_Life_control                   Life;
691
692  Thread_Capture_control                Capture;
693
694  /**
695   * @brief Variable length array of user extension pointers.
696   *
697   * The length is defined by the application via <rtems/confdefs.h>.
698   */
699  void                                 *extensions[ RTEMS_ZERO_LENGTH_ARRAY ];
700};
701
702#if (CPU_PROVIDES_IDLE_THREAD_BODY == FALSE)
703/**
704 *  This routine is the body of the system idle thread.
705 *
706 *  NOTE: This routine is actually instantiated by confdefs.h when needed.
707 */
708void *_Thread_Idle_body(
709  uintptr_t  ignored
710);
711#endif
712
713/**  This defines the type for a method which operates on a single thread.
714 */
715typedef void (*rtems_per_thread_routine)( Thread_Control * );
716
717/**
718 *  @brief Iterates over all threads.
719 *  This routine iterates over all threads regardless of API and
720 *  invokes the specified routine.
721 */
722void rtems_iterate_over_all_threads(
723  rtems_per_thread_routine routine
724);
725
726/**
727 * @brief Returns the thread control block of the executing thread.
728 *
729 * This function can be called in any context.  On SMP configurations
730 * interrupts are disabled to ensure that the processor index is used
731 * consistently.
732 *
733 * @return The thread control block of the executing thread.
734 */
735RTEMS_INLINE_ROUTINE Thread_Control *_Thread_Get_executing( void )
736{
737  Thread_Control *executing;
738
739  #if defined( RTEMS_SMP )
740    ISR_Level level;
741
742    _ISR_Disable_without_giant( level );
743  #endif
744
745  executing = _Thread_Executing;
746
747  #if defined( RTEMS_SMP )
748    _ISR_Enable_without_giant( level );
749  #endif
750
751  return executing;
752}
753
754/**
755 * @brief Thread control add-on.
756 */
757typedef struct {
758  /**
759   * @brief Offset of the pointer field in Thread_Control referencing an
760   * application configuration dependent memory area in the thread control
761   * block.
762   */
763  size_t destination_offset;
764
765  /**
766   * @brief Offset relative to the thread control block begin to an application
767   * configuration dependent memory area.
768   */
769  size_t source_offset;
770} Thread_Control_add_on;
771
772/**
773 * @brief Thread control add-ons.
774 *
775 * The thread control block contains fields that point to application
776 * configuration dependent memory areas, like the scheduler information, the
777 * API control blocks, the user extension context table, the RTEMS notepads and
778 * the Newlib re-entrancy support.  Account for these areas in the
779 * configuration and avoid extra workspace allocations for these areas.
780 *
781 * This array is provided via <rtems/confdefs.h>.
782 *
783 * @see _Thread_Control_add_on_count and _Thread_Control_size.
784 */
785extern const Thread_Control_add_on _Thread_Control_add_ons[];
786
787/**
788 * @brief Thread control add-on count.
789 *
790 * Count of entries in _Thread_Control_add_ons.
791 *
792 * This value is provided via <rtems/confdefs.h>.
793 */
794extern const size_t _Thread_Control_add_on_count;
795
796/**
797 * @brief Size of the thread control block of a particular application.
798 *
799 * This value is provided via <rtems/confdefs.h>.
800 *
801 * @see _Thread_Control_add_ons.
802 */
803extern const size_t _Thread_Control_size;
804
805/**@}*/
806
807#ifdef __cplusplus
808}
809#endif
810
811#endif
812/* end of include file */
Note: See TracBrowser for help on using the repository browser.