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

4.115
Last change on this file since a55e305 was a55e305, checked in by Joel Sherrill <joel.sherrill@…>, on 07/29/10 at 17:52:10

2010-07-29 Gedare Bloom <giddyup44@…>

PR 1635/cpukit

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