source: rtems/cpukit/score/include/rtems/score/thread.h @ 4fc370e

4.115
Last change on this file since 4fc370e was 4fc370e, checked in by Sebastian Huber <sebastian.huber@…>, on Jun 5, 2013 at 10:08:23 AM

score: Move thread dispatch content to new file

Move thread dispatch declarations and inline functions to new header
<rtems/score/threaddispatch.h> to make it independent of the
Thread_Control structure. This avoids a cyclic dependency in case
thread dispatch functions are used for the object implementation.

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