source: rtems/cpukit/score/include/rtems/score/thread.h @ e358088

4.115
Last change on this file since e358088 was e358088, checked in by Sebastian Huber <sebastian.huber@…>, on 05/28/13 at 08:54:46

smp: New SMP lock API

Move the SMP lock implementation to the CPU port. An optimal SMP lock
implementation is highly architecture dependent. For example the memory
models may be fundamentally different.

The new SMP lock API has a flaw. It does not provide the ability to use
a local context for acquire and release pairs. Such a context is
necessary to implement for example the Mellor-Crummey and Scott (MCS)
locks. The SMP lock is currently used in _Thread_Disable_dispatch() and
_Thread_Enable_dispatch() and makes them to a giant lock acquire and
release. Since these functions do not pass state information via a
local context there is currently no use case for such a feature.

  • Property mode set to 100644
File size: 30.9 KB
RevLine 
[20f02c6]1/**
[11874561]2 *  @file  rtems/score/thread.h
[ac7d5ef0]3 *
[319cb20]4 *  @brief Constants and Structures Related with the Thread Control Block
5 *
[ac7d5ef0]6 *  This include file contains all constants and structures associated
7 *  with the thread control block.
[baff4da]8 */
9
10/*
[3203e09]11 *  COPYRIGHT (c) 1989-2009.
[ac7d5ef0]12 *  On-Line Applications Research Corporation (OAR).
13 *
[98e4ebf5]14 *  The license and distribution terms for this file may be
15 *  found in the file LICENSE in this distribution or at
[dd687d97]16 *  http://www.rtems.com/license/LICENSE.
[ac7d5ef0]17 */
18
[092f142a]19#ifndef _RTEMS_SCORE_THREAD_H
20#define _RTEMS_SCORE_THREAD_H
[ac7d5ef0]21
[baff4da]22/**
23 *  @defgroup ScoreThread Thread Handler
24 *
[d8cd045c]25 *  @ingroup Score
26 *
[6a07436]27 *  This handler encapsulates functionality related to the management of
28 *  threads.  This includes the creation, deletion, and scheduling of threads.
[11e8bc5]29 *
30 *  The following variables are maintained as part of the per cpu data
31 *  structure.
32 *
33 *  + Idle thread pointer
34 *  + Executing thread pointer
35 *  + Heir thread pointer
[baff4da]36 */
37/**@{*/
38
[1ada6163]39#if defined(RTEMS_POSIX_API)
[442eac69]40  #define RTEMS_SCORE_THREAD_ENABLE_EXHAUST_TIMESLICE
41#endif
42
[fdc70e2]43/*
44 * With the addition of the Constant Block Scheduler (CBS),
45 * this feature is needed even when POSIX is disabled.
46 */
47#define RTEMS_SCORE_THREAD_ENABLE_SCHEDULER_CALLOUT
[442eac69]48
[bacf79e]49#if defined(RTEMS_POSIX_API)
50  #define RTEMS_SCORE_THREAD_ENABLE_USER_PROVIDED_STACK_VIA_API
51#endif
[442eac69]52
[d7c3883]53#if defined(RTEMS_SMP) || \
54    defined(RTEMS_HEAVY_STACK_DEBUG) || \
55    defined(RTEMS_HEAVY_MALLOC_DEBUG)
56  #define __THREAD_DO_NOT_INLINE_DISABLE_DISPATCH__
57#endif
58
59#if defined(RTEMS_SMP) || \
60   (CPU_INLINE_ENABLE_DISPATCH == FALSE) || \
[dacdda30]61   (__RTEMS_DO_NOT_INLINE_THREAD_ENABLE_DISPATCH__ == 1)
[d7c3883]62  #define __THREAD_DO_NOT_INLINE_ENABLE_DISPATCH__
63#endif
64
[f78831f1]65/*
66 *  Deferred floating point context switches are not currently
67 *  supported when in SMP configuration.
68 */
69#if defined(RTEMS_SMP)
70  #undef  CPU_USE_DEFERRED_FP_SWITCH
71  #define CPU_USE_DEFERRED_FP_SWITCH FALSE
72#endif
73
[ac7d5ef0]74#ifdef __cplusplus
75extern "C" {
76#endif
77
[11e8bc5]78#include <rtems/score/percpu.h>
[5e9b32b]79#include <rtems/score/context.h>
80#include <rtems/score/cpu.h>
[97e2729d]81#if defined(RTEMS_MULTIPROCESSING)
[5e9b32b]82#include <rtems/score/mppkt.h>
[97e2729d]83#endif
[5e9b32b]84#include <rtems/score/object.h>
85#include <rtems/score/priority.h>
[0faa9dad]86#include <rtems/score/scheduler.h>
[5e9b32b]87#include <rtems/score/stack.h>
88#include <rtems/score/states.h>
89#include <rtems/score/tod.h>
90#include <rtems/score/tqdata.h>
91#include <rtems/score/watchdog.h>
[ac7d5ef0]92
[196fe59]93/*
94 *  The user can define this at configure time and go back to ticks
95 *  resolution.
96 */
97#ifndef __RTEMS_USE_TICKS_FOR_STATISTICS__
98  #include <rtems/score/timestamp.h>
99
100  typedef Timestamp_Control Thread_CPU_usage_t;
101#else
102  typedef uint32_t Thread_CPU_usage_t;
103#endif
104
[baff4da]105/**
[3a4ae6c]106 *  The following defines the "return type" of a thread.
[260b0c2]107 *
[baff4da]108 *  @note  This cannot always be right.  Some APIs have void
[a0ed4ed]109 *         tasks/threads, others return pointers, others may
[260b0c2]110 *         return a numeric value.  Hopefully a pointer is
[d6154c7]111 *         always at least as big as an uint32_t  . :)
[ac7d5ef0]112 */
[260b0c2]113typedef void *Thread;
[ac7d5ef0]114
[3b14b7ad]115/**
116 *  @brief Type of the numeric argument of a thread entry function with at
[20f02c6]117 *  least one numeric argument.
[3b14b7ad]118 *
119 *  This numeric argument type designates an unsigned integer type with the
120 *  property that any valid pointer to void can be converted to this type and
121 *  then converted back to a pointer to void.  The result will compare equal to
122 *  the original pointer.
123 */
124typedef uintptr_t Thread_Entry_numeric_type;
125
[baff4da]126/**
[3a4ae6c]127 *  The following defines the ways in which the entry point for a
128 *  thread can be invoked.  Basically, it can be passed any
[d6154c7]129 *  combination/permutation of a pointer and an uint32_t   value.
[3a4ae6c]130 *
[baff4da]131 *  @note For now, we are ignoring the return type.
[ac7d5ef0]132 */
[3a4ae6c]133typedef enum {
134  THREAD_START_NUMERIC,
135  THREAD_START_POINTER,
[46a67b19]136  #if defined(FUNCTIONALITY_NOT_CURRENTLY_USED_BY_ANY_API)
137    THREAD_START_BOTH_POINTER_FIRST,
138    THREAD_START_BOTH_NUMERIC_FIRST
139  #endif
[3a4ae6c]140} Thread_Start_types;
[ac7d5ef0]141
[6a07436]142/** This type corresponds to a very simple style thread entry point. */
[5742e5e]143typedef Thread ( *Thread_Entry )( void );   /* basic type */
[0d051533]144
[6a07436]145/** This type corresponds to a thread entry point which takes a single
146 *  unsigned thirty-two bit integer as an argument.
147 */
[3b14b7ad]148typedef Thread ( *Thread_Entry_numeric )( Thread_Entry_numeric_type );
[baff4da]149
[6a07436]150/** This type corresponds to a thread entry point which takes a single
151 *  untyped pointer as an argument.
[baff4da]152 */
[0d051533]153typedef Thread ( *Thread_Entry_pointer )( void * );
[baff4da]154
[6a07436]155/** This type corresponds to a thread entry point which takes a single
156 *  untyped pointer and an unsigned thirty-two bit integer as arguments.
[baff4da]157 */
[3b14b7ad]158typedef Thread ( *Thread_Entry_both_pointer_first )( void *, Thread_Entry_numeric_type );
[baff4da]159
[6a07436]160/** This type corresponds to a thread entry point which takes a single
161 *  unsigned thirty-two bit integer and an untyped pointer and an
162 *  as arguments.
[baff4da]163 */
[3b14b7ad]164typedef Thread ( *Thread_Entry_both_numeric_first )( Thread_Entry_numeric_type, void * );
[ac7d5ef0]165
[baff4da]166/**
[2f200c7]167 *  The following lists the algorithms used to manage the thread cpu budget.
168 *
169 *  Reset Timeslice:   At each context switch, reset the time quantum.
170 *  Exhaust Timeslice: Only reset the quantum once it is consumed.
171 *  Callout:           Execute routine when budget is consumed.
172 */
173typedef enum {
174  THREAD_CPU_BUDGET_ALGORITHM_NONE,
175  THREAD_CPU_BUDGET_ALGORITHM_RESET_TIMESLICE,
[442eac69]176  #if defined(RTEMS_SCORE_THREAD_ENABLE_EXHAUST_TIMESLICE)
177    THREAD_CPU_BUDGET_ALGORITHM_EXHAUST_TIMESLICE,
178  #endif
179  #if defined(RTEMS_SCORE_THREAD_ENABLE_SCHEDULER_CALLOUT)
180    THREAD_CPU_BUDGET_ALGORITHM_CALLOUT
181  #endif
[2f200c7]182}  Thread_CPU_budget_algorithms;
183
[6a07436]184/**  This defines thes the entry point for the thread specific timeslice
185 *   budget management algorithm.
[baff4da]186 */
[2f200c7]187typedef void (*Thread_CPU_budget_algorithm_callout )( Thread_Control * );
188
[4b72da4]189/**
[319cb20]190 *  @brief Forward reference to the per task variable structure..
[baff4da]191 *
192 *  Forward reference to the per task variable structure.
[aad726e]193 */
194struct rtems_task_variable_tt;
195
[4b72da4]196/**
[319cb20]197 *  @brief Internal structure used to manager per task variables.
[baff4da]198 *
199 *  This is the internal structure used to manager per Task Variables.
200 */
[6a07436]201typedef struct {
[baff4da]202  /** This field points to the next per task variable for this task. */
[aad726e]203  struct rtems_task_variable_tt  *next;
[baff4da]204  /** This field points to the physical memory location of this per
205   *  task variable.
206   */
[c941a98]207  void                          **ptr;
[baff4da]208  /** This field is to the global value for this per task variable. */
[df49c60]209  void                           *gval;
[baff4da]210  /** This field is to this thread's value for this per task variable. */
[df49c60]211  void                           *tval;
[baff4da]212  /** This field points to the destructor for this per task variable. */
[c941a98]213  void                          (*dtor)(void *);
[6a07436]214} rtems_task_variable_t;
[aad726e]215
[baff4da]216/**
[ac7d5ef0]217 *  The following structure contains the information which defines
218 *  the starting state of a thread.
219 */
220typedef struct {
[6a07436]221  /** This field is the starting address for the thread. */
[3b14b7ad]222  Thread_Entry                         entry_point;
[6cd8bbe]223  /** This field indicates the how task is invoked. */
[3b14b7ad]224  Thread_Start_types                   prototype;
[6a07436]225  /** This field is the pointer argument passed at thread start. */
[3b14b7ad]226  void                                *pointer_argument;
[6a07436]227  /** This field is the numeric argument passed at thread start. */
[3b14b7ad]228  Thread_Entry_numeric_type            numeric_argument;
[6a07436]229  /*-------------- initial execution modes ----------------- */
230  /** This field indicates whether the thread was preemptible when
231    * it started.
232    */
[484a769]233  bool                                 is_preemptible;
[6a07436]234  /** This field indicates the CPU budget algorith. */
[3b14b7ad]235  Thread_CPU_budget_algorithms         budget_algorithm;
[6a07436]236  /** This field is the routine to invoke when the CPU allotment is
237   *  consumed.
238   */
[3b14b7ad]239  Thread_CPU_budget_algorithm_callout  budget_callout;
[6a07436]240  /** This field is the initial ISR disable level of this thread. */
[3b14b7ad]241  uint32_t                             isr_level;
[6a07436]242  /** This field is the initial priority. */
[3b14b7ad]243  Priority_Control                     initial_priority;
[bacf79e]244  #if defined(RTEMS_SCORE_THREAD_ENABLE_USER_PROVIDED_STACK_VIA_API)
245    /** This field indicates whether the SuperCore allocated the stack. */
246    bool                                 core_allocated_stack;
247  #endif
[6a07436]248  /** This field is the stack information. */
[3b14b7ad]249  Stack_Control                        Initial_stack;
[bacf79e]250  #if ( CPU_HARDWARE_FP == TRUE ) || ( CPU_SOFTWARE_FP == TRUE )
251    /** This field is the initial FP context area address. */
252    Context_Control_fp                  *fp_context;
253  #endif
[6a07436]254  /** This field is the initial stack area address. */
[3b14b7ad]255  void                                *stack;
256} Thread_Start_information;
[ac7d5ef0]257
[baff4da]258/**
[ac7d5ef0]259 *  The following structure contains the information necessary to manage
260 *  a thread which it is  waiting for a resource.
261 */
[3a4ae6c]262#define THREAD_STATUS_PROXY_BLOCKING 0x1111111
263
[f773c012]264/**
265 *  @brief Union type to hold a pointer to an immutable or a mutable object.
266 *
267 *  The main purpose is to enable passing of pointers to read-only send buffers
268 *  in the message passing subsystem.  This approach is somewhat fragile since
269 *  it prevents the compiler to check if the operations on objects are valid
270 *  with respect to the constant qualifier.  An alternative would be to add a
271 *  third pointer argument for immutable objects, but this would increase the
272 *  structure size.
273 */
274typedef union {
275  void       *mutable_object;
276  const void *immutable_object;
277} Thread_Wait_information_Object_argument_type;
278
[4b72da4]279/**
[319cb20]280 *  @brief Information required to manage a thread while it is blocked.
[baff4da]281 *
282 *  This contains the information required to manage a thread while it is
283 *  blocked and to return information to it.
284 */
[ac7d5ef0]285typedef struct {
[baff4da]286  /** This field is the Id of the object this thread is waiting upon. */
287  Objects_Id            id;
288  /** This field is used to return an integer while when blocked. */
289  uint32_t              count;
[f773c012]290  /** This field is for a pointer to a user return argument. */
[baff4da]291  void                 *return_argument;
[f773c012]292  /** This field is for a pointer to a second user return argument. */
293  Thread_Wait_information_Object_argument_type
294                        return_argument_second;
[baff4da]295  /** This field contains any options in effect on this blocking operation. */
[d6154c7]296  uint32_t              option;
[baff4da]297  /** This field will contain the return status from a blocking operation.
[20f02c6]298   *
[baff4da]299   *  @note The following assumes that all API return codes can be
300   *        treated as an uint32_t.
[3a4ae6c]301   */
[baff4da]302  uint32_t              return_code;
[3a4ae6c]303
[20f02c6]304  /** This field is the chain header for the second through Nth tasks
[baff4da]305   *  of the same priority blocked waiting on the same object.
306   */
307  Chain_Control         Block2n;
308  /** This field points to the thread queue on which this thread is blocked. */
309  Thread_queue_Control *queue;
[ac7d5ef0]310}   Thread_Wait_information;
311
[baff4da]312/**
[ac7d5ef0]313 *  The following defines the control block used to manage
314 *  each thread proxy.
315 *
[baff4da]316 *  @note It is critical that proxies and threads have identical
[ac7d5ef0]317 *        memory images for the shared part.
318 */
319typedef struct {
[6a07436]320  /** This field is the object management structure for each proxy. */
[ac7d5ef0]321  Objects_Control          Object;
[6a07436]322  /** This field is the current execution state of this proxy. */
[ac7d5ef0]323  States_Control           current_state;
[6a07436]324  /** This field is the current priority state of this proxy. */
[7f6a24ab]325  Priority_Control         current_priority;
[6a07436]326  /** This field is the base priority of this proxy. */
[7f6a24ab]327  Priority_Control         real_priority;
[6a07436]328  /** This field is the number of mutexes currently held by this proxy. */
[d6154c7]329  uint32_t                 resource_count;
[fd84982]330
[6a07436]331  /** This field is the blocking information for this proxy. */
[ac7d5ef0]332  Thread_Wait_information  Wait;
[6a07436]333  /** This field is the Watchdog used to manage proxy delays and timeouts. */
[ac7d5ef0]334  Watchdog_Control         Timer;
[97e2729d]335#if defined(RTEMS_MULTIPROCESSING)
[6a07436]336  /** This field is the received response packet in an MP system. */
[3a4ae6c]337  MP_packet_Prefix        *receive_packet;
[97e2729d]338#endif
[ac7d5ef0]339     /****************** end of common block ********************/
[6a07436]340  /** This field is used to manage the set of proxies in the system. */
[ac7d5ef0]341  Chain_Node               Active;
342}   Thread_Proxy_control;
343
[baff4da]344/**
[ac7d5ef0]345 *  The following record defines the control block used
346 *  to manage each thread.
347 *
[baff4da]348 *  @note It is critical that proxies and threads have identical
[ac7d5ef0]349 *        memory images for the shared part.
350 */
[3a4ae6c]351typedef enum {
[6a07436]352  /** This value is for the Classic RTEMS API. */
[5e9b32b]353  THREAD_API_RTEMS,
[6a07436]354  /** This value is for the POSIX API. */
[f0caa05]355  THREAD_API_POSIX
[3a4ae6c]356}  Thread_APIs;
[7f6a24ab]357
[6a07436]358/** This macro defines the first API which has threads. */
[3a4ae6c]359#define THREAD_API_FIRST THREAD_API_RTEMS
[baff4da]360
[6a07436]361/** This macro defines the last API which has threads. */
[f0caa05]362#define THREAD_API_LAST  THREAD_API_POSIX
[7f6a24ab]363
[baff4da]364/**
[6a07436]365 *  This structure defines the Thread Control Block (TCB).
[baff4da]366 */
[2f200c7]367struct Thread_Control_struct {
[6a07436]368  /** This field is the object management structure for each thread. */
369  Objects_Control          Object;
370  /** This field is the current execution state of this thread. */
371  States_Control           current_state;
372  /** This field is the current priority state of this thread. */
373  Priority_Control         current_priority;
374  /** This field is the base priority of this thread. */
375  Priority_Control         real_priority;
376  /** This field is the number of mutexes currently held by this thread. */
377  uint32_t                 resource_count;
378  /** This field is the blocking information for this thread. */
379  Thread_Wait_information  Wait;
380  /** This field is the Watchdog used to manage thread delays and timeouts. */
381  Watchdog_Control         Timer;
[97e2729d]382#if defined(RTEMS_MULTIPROCESSING)
[6a07436]383  /** This field is the received response packet in an MP system. */
384  MP_packet_Prefix        *receive_packet;
[fd84982]385#endif
[66a9239a]386#ifdef __RTEMS_STRICT_ORDER_MUTEX__
[931dd97]387  /** This field is the head of queue of priority inheritance mutex
388   *  held by the thread.
389   */
[fd84982]390  Chain_Control            lock_mutex;
[97e2729d]391#endif
[6a07436]392     /*================= end of common block =================*/
[931dd97]393#if defined(RTEMS_MULTIPROCESSING)
[6a07436]394  /** This field is true if the thread is offered globally */
[484a769]395  bool                                  is_global;
[931dd97]396#endif
[6a07436]397  /** This field is true if the thread is preemptible. */
[484a769]398  bool                                  is_preemptible;
[81b329a]399#if __RTEMS_ADA__
[6a07436]400  /** This field is the GNAT self context pointer. */
[847375f]401  void                                 *rtems_ada_self;
[81b329a]402#endif
[6a07436]403  /** This field is the length of the time quantum that this thread is
404   *  allowed to consume.  The algorithm used to manage limits on CPU usage
405   *  is specified by budget_algorithm.
406   */
[d6154c7]407  uint32_t                              cpu_time_budget;
[6a07436]408  /** This field is the algorithm used to manage this thread's time
409   *  quantum.  The algorithm may be specified as none which case,
410   *  no limit is in place.
411   */
[2f200c7]412  Thread_CPU_budget_algorithms          budget_algorithm;
[6a07436]413  /** This field is the method invoked with the budgeted time is consumed. */
[2f200c7]414  Thread_CPU_budget_algorithm_callout   budget_callout;
[c3330a8]415  /** This field is the amount of CPU time consumed by this thread
[6a07436]416   *  since it was created.
417   */
[9dc2c8d]418  Thread_CPU_usage_t                    cpu_time_used;
[108c4b0]419
420  /** This pointer holds per-thread data for the scheduler and ready queue. */
421  void                                 *scheduler_info;
422
[6a07436]423  /** This field contains information about the starting state of
424   *  this thread.
425   */
[2f200c7]426  Thread_Start_information              Start;
[6a07436]427  /** This field contains the context of this thread. */
[2f200c7]428  Context_Control                       Registers;
[499d443]429#if ( CPU_HARDWARE_FP == TRUE ) || ( CPU_SOFTWARE_FP == TRUE )
[6a07436]430  /** This field points to the floating point context for this thread.
431   *  If NULL, the thread is integer only.
432   */
[3c86f88]433  Context_Control_fp                   *fp_context;
[17508d02]434#endif
[6a07436]435  /** This field points to the newlib reentrancy structure for this thread. */
[d36b3152]436  struct _reent                        *libc_reent;
[6a07436]437  /** This array contains the API extension area pointers. */
[2f200c7]438  void                                 *API_Extensions[ THREAD_API_LAST + 1 ];
[6a07436]439  /** This field points to the user extension pointers. */
[2f200c7]440  void                                **extensions;
[6a07436]441  /** This field points to the set of per task variables. */
[aad726e]442  rtems_task_variable_t                *task_variables;
[2f200c7]443};
[ac7d5ef0]444
[baff4da]445/**
[847375f]446 *  Self for the GNU Ada Run-Time
447 */
448SCORE_EXTERN void *rtems_ada_self;
[05279b84]449
[baff4da]450/**
[adf98bd]451 *  The following defines the information control block used to
452 *  manage this class of objects.
453 */
[c627b2a3]454SCORE_EXTERN Objects_Information _Thread_Internal_information;
[05279b84]455
[baff4da]456/**
[3a4ae6c]457 *  The following context area contains the context of the "thread"
[a0ed4ed]458 *  which invoked the start multitasking routine.  This context is
[3a4ae6c]459 *  restored as the last action of the stop multitasking routine.  Thus
460 *  control of the processor can be returned to the environment
461 *  which initiated the system.
[ac7d5ef0]462 */
[c627b2a3]463SCORE_EXTERN Context_Control _Thread_BSP_context;
[05279b84]464
[6a07436]465/**
[ac7d5ef0]466 *  The following declares the dispatch critical section nesting
467 *  counter which is used to prevent context switches at inopportune
468 *  moments.
469 */
[d6154c7]470SCORE_EXTERN volatile uint32_t   _Thread_Dispatch_disable_level;
[ac7d5ef0]471
[3a8a999]472#if defined(RTEMS_SMP)
[e358088]473  typedef struct {
474    SMP_lock_Control lock;
475    int owner_cpu;
476    int nest_level;
477  } Thread_Dispatch_disable_level_lock_control;
478
[3a8a999]479  /**
480   * The following declares the smp spinlock to be used to control
481   * the dispatch critical section accesses across cpus.
482   */
[e358088]483  SCORE_EXTERN Thread_Dispatch_disable_level_lock_control
484    _Thread_Dispatch_disable_level_lock;
[3a8a999]485#endif
486
[baff4da]487/**
[3a4ae6c]488 *  The following holds how many user extensions are in the system.  This
489 *  is used to determine how many user extension data areas to allocate
490 *  per thread.
491 */
[d6154c7]492SCORE_EXTERN uint32_t   _Thread_Maximum_extensions;
[3a4ae6c]493
[baff4da]494/**
[7aa4671]495 *  The following is used to manage the length of a timeslice quantum.
[ac7d5ef0]496 */
[d6154c7]497SCORE_EXTERN uint32_t   _Thread_Ticks_per_timeslice;
[ac7d5ef0]498
[baff4da]499/**
[ac7d5ef0]500 *  The following points to the thread whose floating point
501 *  context is currently loaded.
502 */
[499d443]503#if ( CPU_HARDWARE_FP == TRUE ) || ( CPU_SOFTWARE_FP == TRUE )
[c627b2a3]504SCORE_EXTERN Thread_Control *_Thread_Allocated_fp;
[17508d02]505#endif
[ac7d5ef0]506
[baff4da]507/**
[0df8293e]508 * The C library re-enter-rant global pointer. Some C library implementations
509 * such as newlib have a single global pointer that changed during a context
510 * switch. The pointer points to that global pointer. The Thread control block
511 * holds a pointer to the task specific data.
512 */
[d36b3152]513SCORE_EXTERN struct _reent **_Thread_libc_reent;
[baff4da]514/**
[319cb20]515 *  @brief Initialize thread handler.
[e0f91da]516 *
[ac7d5ef0]517 *  This routine performs the initialization necessary for this handler.
518 */
[790b50b]519void _Thread_Handler_initialization(void);
[ac7d5ef0]520
[baff4da]521/**
[319cb20]522 *  @brief Create idle thread.
[e655f7e]523 *
[adf98bd]524 *  This routine creates the idle thread.
525 *
[baff4da]526 *  @warning No thread should be created before this one.
[adf98bd]527 */
[790b50b]528void _Thread_Create_idle(void);
[adf98bd]529
[baff4da]530/**
[319cb20]531 *  @brief Start thread multitasking.
[e655f7e]532 *
[ac7d5ef0]533 *  This routine initiates multitasking.  It is invoked only as
534 *  part of initialization and its invocation is the last act of
[3a4ae6c]535 *  the non-multitasking part of the system initialization.
[e0f91da]536 *
537 *
[e655f7e]538 *  - INTERRUPT LATENCY:
539 *    + ready chain
540 *    + select heir
[ac7d5ef0]541 */
[b2b52cbc]542void _Thread_Start_multitasking( void );
[ac7d5ef0]543
[baff4da]544/**
[319cb20]545 *  @brief Dispatch thread.
[e0f91da]546 *
[ac7d5ef0]547 *  This routine is responsible for transferring control of the
[e0f91da]548 *  processor from the executing thread to the heir thread. Once the
[bf54252]549 *  heir is running an attempt is made to dispatch any ASRs.
550 *  As part of this process, it is responsible for the following actions:
[ac7d5ef0]551 *     + saving the context of the executing thread
552 *     + restoring the context of the heir thread
553 *     + dispatching any signals for the resulting executing thread
[e0f91da]554
[bf54252]555 *  ALTERNATE ENTRY POINTS:
556 *    void _Thread_Enable_dispatch();
557 *
[1b475860]558 *  - INTERRUPT LATENCY:
559 *    + dispatch thread
560 *    + no dispatch thread
[ac7d5ef0]561 */
562void _Thread_Dispatch( void );
563
[baff4da]564/**
[319cb20]565 *  @brief Allocate the requested stack space for the thread.
[bf54252]566 *
[1178b8c]567 *  Allocate the requested stack space for the thread.
[bf54252]568 *  Set the Start.stack field to the address of the stack.
569 *
570 *  @param[in] the_thread is the thread where the stack space is requested
[e0f91da]571 *
[bf54252]572 *  @retval actual size allocated after any adjustment
573 *  @retval zero if the allocation failed
[1178b8c]574 */
[728a0bd3]575size_t _Thread_Stack_Allocate(
[1178b8c]576  Thread_Control *the_thread,
[728a0bd3]577  size_t          stack_size
[1178b8c]578);
579
[baff4da]580/**
[319cb20]581 *  @brief Deallocate thread stack.
[e0f91da]582 *
[1178b8c]583 *  Deallocate the Thread's stack.
584 */
585void _Thread_Stack_Free(
586  Thread_Control *the_thread
587);
588
[baff4da]589/**
[319cb20]590 *  @brief Initialize thread.
591 *
[f6d0821]592 *  This routine initializes the specified the thread.  It allocates
593 *  all memory associated with this thread.  It completes by adding
594 *  the thread to the local object table so operations on this
595 *  thread id are allowed.
[2f200c7]596 *
[baff4da]597 *  @note If stack_area is NULL, it is allocated from the workspace.
[2f200c7]598 *
[baff4da]599 *  @note If the stack is allocated from the workspace, then it is
600 *        guaranteed to be of at least minimum size.
[7f6a24ab]601 */
[484a769]602bool _Thread_Initialize(
[2f200c7]603  Objects_Information                  *information,
604  Thread_Control                       *the_thread,
605  void                                 *stack_area,
[728a0bd3]606  size_t                                stack_size,
[484a769]607  bool                                  is_fp,
[2f200c7]608  Priority_Control                      priority,
[484a769]609  bool                                  is_preemptible,
[2f200c7]610  Thread_CPU_budget_algorithms          budget_algorithm,
611  Thread_CPU_budget_algorithm_callout   budget_callout,
[d6154c7]612  uint32_t                              isr_level,
[2f200c7]613  Objects_Name                          name
[7f6a24ab]614);
615
[baff4da]616/**
[319cb20]617 *  @brief Initializes thread and executes it.
[f839bf5a]618 *
[f6d0821]619 *  This routine initializes the executable information for a thread
620 *  and makes it ready to execute.  After this routine executes, the
621 *  thread competes with all other threads for CPU time.
[f839bf5a]622 *
623 *  @param the_thread is the thread to be initialized
[319cb20]624 *  @param the_prototype
[f839bf5a]625 *  @param entry_point
626 *  @param pointer_argument
627 *  @param numeric_argument
[7f6a24ab]628 */
[484a769]629bool _Thread_Start(
[3b14b7ad]630  Thread_Control            *the_thread,
631  Thread_Start_types         the_prototype,
632  void                      *entry_point,
633  void                      *pointer_argument,
634  Thread_Entry_numeric_type  numeric_argument
[7f6a24ab]635);
636
[baff4da]637/**
[319cb20]638 *  @brief Restarts the specified thread.
639 *
[f6d0821]640 *  This support routine restarts the specified task in a way that the
641 *  next time this thread executes, it will begin execution at its
642 *  original starting point.
[baff4da]643 *
644 *  TODO:  multiple task arg profiles
[7f6a24ab]645 */
[484a769]646bool _Thread_Restart(
[3b14b7ad]647  Thread_Control            *the_thread,
648  void                      *pointer_argument,
649  Thread_Entry_numeric_type  numeric_argument
[7f6a24ab]650);
651
[baff4da]652/**
[319cb20]653 *  @brief Resets a thread to its initial state.
[bf54252]654 *
[f6d0821]655 *  This routine resets a thread to its initial state but does
[bf54252]656 *  not restart it. Some APIs do this in separate
657 *  operations and this division helps support this.
658 *
659 *  @param[in] the_thread is the thread to resets
660 *  @param[in] pointer_argument
661 *  @param[in] numeric_argument
[f6d0821]662 */
663void _Thread_Reset(
[3b14b7ad]664  Thread_Control            *the_thread,
665  void                      *pointer_argument,
666  Thread_Entry_numeric_type  numeric_argument
[f6d0821]667);
668
[baff4da]669/**
[319cb20]670 *  @brief Frees all memory associated with the specified thread.
[f2f63d1]671 *
[f6d0821]672 *  This routine frees all memory associated with the specified
673 *  thread and removes it from the local object table so no further
674 *  operations on this thread are allowed.
[7f6a24ab]675 */
676void _Thread_Close(
677  Objects_Information  *information,
678  Thread_Control       *the_thread
679);
680
[baff4da]681/**
[319cb20]682 *  @brief Removes any set states for @a the_thread.
[f2f63d1]683 *
[d4d7899]684 *  This routine removes any set states for @a the_thread.  It performs
[ac7d5ef0]685 *  any necessary scheduling operations including the selection of
686 *  a new heir thread.
[e0f91da]687 *
[f2f63d1]688 *  - INTERRUPT LATENCY:
689 *    + ready chain
690 *    + select heir
[ac7d5ef0]691 */
692void _Thread_Ready(
693  Thread_Control *the_thread
694);
695
[baff4da]696/**
[319cb20]697 *  @brief Clears the indicated STATES for @a the_thread.
[e655f7e]698 *
[d4d7899]699 *  This routine clears the indicated STATES for @a the_thread.  It performs
[ac7d5ef0]700 *  any necessary scheduling operations including the selection of
701 *  a new heir thread.
[e0f91da]702 *
[e655f7e]703 *  - INTERRUPT LATENCY:
704 *    + priority map
705 *    + select heir
[ac7d5ef0]706 */
707void _Thread_Clear_state(
708  Thread_Control *the_thread,
709  States_Control  state
710);
711
[baff4da]712/**
[319cb20]713 *  @brief Sets the indicated @a state for @a the_thread.
[f839bf5a]714 *
715 *  This routine sets the indicated @a state for @a the_thread.  It performs
[ac7d5ef0]716 *  any necessary scheduling operations including the selection of
717 *  a new heir thread.
[f839bf5a]718 *
[319cb20]719 *  @param[in] the_thread is the thread to set the state for.
[f839bf5a]720 *  @param[in] state is the state to set the_thread to.
721 *
722 *  - INTERRUPT LATENCY:
723 *   + ready chain
724 *   + select map
[ac7d5ef0]725 */
726void _Thread_Set_state(
727  Thread_Control *the_thread,
728  States_Control  state
729);
730
[baff4da]731/**
[319cb20]732 *  @brief Sets the transient state for a thread.
[d4d7899]733 *
734 *  This routine sets the Transient state for @a the_thread.  It performs
[ac7d5ef0]735 *  any necessary scheduling operations including the selection of
736 *  a new heir thread.
[d4d7899]737 *
738 *  @param[in] the_thread is the thread to preform the action upon.
739 *
740 *  - INTERRUPT LATENCY:
741 *    + single case
[ac7d5ef0]742 */
743void _Thread_Set_transient(
744  Thread_Control *the_thread
745);
746
[baff4da]747/**
[319cb20]748 *  @brief Initializes enviroment for a thread.
[f839bf5a]749 *
750 *  This routine initializes the context of @a the_thread to its
[ac7d5ef0]751 *  appropriate starting state.
[319cb20]752 *
[f839bf5a]753 *  @param[in] the_thread is the pointer to the thread control block.
[ac7d5ef0]754 */
755void _Thread_Load_environment(
756  Thread_Control *the_thread
757);
758
[baff4da]759/**
[319cb20]760 *  @brief Wrapper function for all threads.
761 *
[ac7d5ef0]762 *  This routine is the wrapper function for all threads.  It is
763 *  the starting point for all threads.  The user provided thread
764 *  entry point is invoked by this routine.  Operations
765 *  which must be performed immediately before and after the user's
766 *  thread executes are found here.
[5a58b1e]767 *
[e858f70]768 *  @note On entry, it is assumed all interrupts are blocked and that this
[5a58b1e]769 *  routine needs to set the initial isr level.  This may or may not
770 *  actually be needed by the context switch routine and as a result
771 *  interrupts may already be at there proper level.  Either way,
772 *  setting the initial isr level properly here is safe.
[ac7d5ef0]773 */
774void _Thread_Handler( void );
775
[baff4da]776/**
[319cb20]777 *  @brief Ended the delay of a thread.
[e0f91da]778 *
[ac7d5ef0]779 *  This routine is invoked when a thread must be unblocked at the
[3a4ae6c]780 *  end of a time based delay (i.e. wake after or wake when).
[bf54252]781 *  It is called by the watchdog handler.
782 *
783 *  @param[in] id is the thread id
[ac7d5ef0]784 */
785void _Thread_Delay_ended(
786  Objects_Id  id,
787  void       *ignored
788);
789
[baff4da]790/**
[319cb20]791 *  @brief Change the priority of a thread.
[e0f91da]792 *
[1b475860]793 *  This routine changes the current priority of @a the_thread to
794 *  @a new_priority.  It performs any necessary scheduling operations
[ac7d5ef0]795 *  including the selection of a new heir thread.
[1b475860]796 *
797 *  @param[in] the_thread is the thread to change
798 *  @param[in] new_priority is the priority to set @a the_thread to
799 *  @param[in] prepend_it is a switch to prepend the thread
[ac7d5ef0]800 */
801void _Thread_Change_priority (
802  Thread_Control   *the_thread,
[f926b34]803  Priority_Control  new_priority,
[484a769]804  bool              prepend_it
[ac7d5ef0]805);
806
[baff4da]807/**
[319cb20]808 *  @brief Set thread priority.
[e0f91da]809 *
[ac7d5ef0]810 *  This routine updates the priority related fields in the_thread
811 *  control block to indicate the current priority is now new_priority.
812 */
813void _Thread_Set_priority(
814  Thread_Control   *the_thread,
[7f6a24ab]815  Priority_Control  new_priority
[ac7d5ef0]816);
817
[baff4da]818/**
[eb02f47]819 *  This routine updates the related suspend fields in the_thread
820 *  control block to indicate the current nested level.
821 */
[59eb125]822#define _Thread_Suspend( _the_thread ) \
823        _Thread_Set_state( _the_thread, STATES_SUSPENDED )
[eb02f47]824
[baff4da]825/**
[eb02f47]826 *  This routine updates the related suspend fields in the_thread
827 *  control block to indicate the current nested level.  A force
[c6b3719]828 *  parameter of true will force a resume and clear the suspend count.
[eb02f47]829 */
[59eb125]830#define _Thread_Resume( _the_thread ) \
831        _Thread_Clear_state( _the_thread, STATES_SUSPENDED )
[eb02f47]832
[baff4da]833#if (CPU_PROVIDES_IDLE_THREAD_BODY == FALSE)
834/**
[adf98bd]835 *  This routine is the body of the system idle thread.
[93f7ea15]836 *
837 *  NOTE: This routine is actually instantiated by confdefs.h when needed.
[adf98bd]838 */
[3aaf479]839void *_Thread_Idle_body(
840  uintptr_t  ignored
[adf98bd]841);
842#endif
843
[6a07436]844/**  This defines the type for a method which operates on a single thread.
[17c66867]845 */
846typedef void (*rtems_per_thread_routine)( Thread_Control * );
847
[baff4da]848/**
[319cb20]849 *  @brief Iterates over all threads.
[baff4da]850 *  This routine iterates over all threads regardless of API and
851 *  invokes the specified routine.
852 */
[17c66867]853void rtems_iterate_over_all_threads(
854  rtems_per_thread_routine routine
855);
856
[78dabb69]857/**
[319cb20]858 *  @brief Maps thread Id to a TCB pointer.
[e0f91da]859 *
[78dabb69]860 *  This function maps thread IDs to thread control
861 *  blocks.  If ID corresponds to a local thread, then it
862 *  returns the_thread control pointer which maps to ID
[d4d7899]863 *  and @a location is set to OBJECTS_LOCAL.  If the thread ID is
[78dabb69]864 *  global and resides on a remote node, then location is set
865 *  to OBJECTS_REMOTE, and the_thread is undefined.
866 *  Otherwise, location is set to OBJECTS_ERROR and
867 *  the_thread is undefined.
[e0f91da]868 *
[d4d7899]869 *  @param[in] id is the id of the thread.
870 *  @param[in] location is the location of the block.
[78dabb69]871 *
872 *  @note  The performance of many RTEMS services depends upon
873 *         the quick execution of the "good object" path in this
874 *         routine.  If there is a possibility of saving a few
875 *         cycles off the execution time, this routine is worth
876 *         further optimization attention.
877 */
878Thread_Control *_Thread_Get (
879  Objects_Id         id,
880  Objects_Locations *location
881);
882
[3168deaa]883/**
[319cb20]884 *  @brief Cancel a blocking operation due to ISR.
[3168deaa]885 *
886 *  This method is used to cancel a blocking operation that was
887 *  satisfied from an ISR while the thread executing was in the
888 *  process of blocking.
889 *
[4012792]890 *  This method will restore the previous ISR disable level during the cancel
891 *  operation.  Thus it is an implicit _ISR_Enable().
892 *
[3168deaa]893 *  @param[in] sync_state is the synchronization state
894 *  @param[in] the_thread is the thread whose blocking is canceled
895 *  @param[in] level is the previous ISR disable level
896 *
897 *  @note This is a rare routine in RTEMS.  It is called with
898 *        interrupts disabled and only when an ISR completed
899 *        a blocking condition in process.
900 */
901void _Thread_blocking_operation_Cancel(
902  Thread_blocking_operation_States  sync_state,
903  Thread_Control                   *the_thread,
904  ISR_Level                         level
905);
[3a8a999]906#if defined(RTEMS_SMP)
907
[4b72da4]908  /**
[319cb20]909   *  @brief Initializes the thread dispatching subsystem.
[e0f91da]910   *
[3a8a999]911   *  This routine initializes the thread dispatching subsystem.
912   */
913  void _Thread_Dispatch_initialization(void);
914
[4b72da4]915  /**
[319cb20]916   *  @brief Checks if thread dispatch says that we are in a critical section.
[e0f91da]917   *
[3a8a999]918   * This routine returns true if thread dispatch indicates
919   * that we are in a critical section.
920   */
921  bool _Thread_Dispatch_in_critical_section(void);
922
[4b72da4]923  /**
[319cb20]924   *  @brief Returns value of the the thread dispatch level.
[e0f91da]925   *
[3a8a999]926   * This routine returns value of the the thread dispatch level.
927   */
928  uint32_t _Thread_Dispatch_get_disable_level(void);
929
[4b72da4]930  /**
[319cb20]931   *  @brief Sets thread dispatch level to the value passed in.
[e0f91da]932   *
933   * This routine sets thread dispatch level to the
[3a8a999]934   * value passed in.
935   */
936  uint32_t _Thread_Dispatch_set_disable_level(uint32_t value);
937
[4b72da4]938  /**
[319cb20]939   *  @brief Increments the thread dispatch level.
[3a8a999]940   *
941   * This rountine increments the thread dispatch level
942   */
943  uint32_t _Thread_Dispatch_increment_disable_level(void);
944
[4b72da4]945  /**
[319cb20]946   *  @brief Decrements the thread dispatch level.
[e0f91da]947   *
[3a8a999]948   * This routine decrements the thread dispatch level.
949   */
950  uint32_t _Thread_Dispatch_decrement_disable_level(void);
951
952#else
953  /*
954   * The _Thread_Dispatch_... functions are in thread.inl
955   */
956#endif
957
[1a8fde6c]958#ifndef __RTEMS_APPLICATION__
[5e9b32b]959#include <rtems/score/thread.inl>
[1a8fde6c]960#endif
[97e2729d]961#if defined(RTEMS_MULTIPROCESSING)
[5e9b32b]962#include <rtems/score/threadmp.h>
[97e2729d]963#endif
[ac7d5ef0]964
965#ifdef __cplusplus
966}
967#endif
968
[baff4da]969/**@}*/
970
[ac7d5ef0]971#endif
[b10825c]972/* end of include file */
Note: See TracBrowser for help on using the repository browser.