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

4.104.114.9
Last change on this file since ebfd9ea was ebfd9ea, checked in by Joel Sherrill <joel.sherrill@…>, on Jun 6, 2008 at 4:34:43 PM

2008-06-06 Joel Sherrill <joel.sherrill@…>

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