source: rtems/cpukit/score/include/rtems/score/thread.h @ 94d9bee

4.104.115
Last change on this file since 94d9bee was 94d9bee, checked in by Joel Sherrill <joel.sherrill@…>, on 10/30/09 at 17:54:29

2009-10-30 Glenn Humphrey <glenn.humphrey@…>

PR pr1462/cpukit

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