source: rtems/cpukit/score/src/threaddispatch.c @ 8f0529f

4.104.114.84.95
Last change on this file since 8f0529f was 05df0a8, checked in by Joel Sherrill <joel.sherrill@…>, on 05/17/99 at 20:41:13

Thread Handler split into multiple files. Eventually, as RTEMS is
split into one function per file, this will decrease the size of executables.

  • Property mode set to 100644
File size: 3.6 KB
Line 
1/*
2 *  Thread Handler
3 *
4 *
5 *  COPYRIGHT (c) 1989-1998.
6 *  On-Line Applications Research Corporation (OAR).
7 *  Copyright assigned to U.S. Government, 1994.
8 *
9 *  The license and distribution terms for this file may be
10 *  found in found in the file LICENSE in this distribution or at
11 *  http://www.OARcorp.com/rtems/license.html.
12 *
13 *  $Id$
14 */
15
16#include <rtems/system.h>
17#include <rtems/score/apiext.h>
18#include <rtems/score/context.h>
19#include <rtems/score/interr.h>
20#include <rtems/score/isr.h>
21#include <rtems/score/object.h>
22#include <rtems/score/priority.h>
23#include <rtems/score/states.h>
24#include <rtems/score/sysstate.h>
25#include <rtems/score/thread.h>
26#include <rtems/score/threadq.h>
27#include <rtems/score/userext.h>
28#include <rtems/score/wkspace.h>
29
30/*PAGE
31 *
32 *  _Thread_Dispatch
33 *
34 *  This kernel routine determines if a dispatch is needed, and if so
35 *  dispatches to the heir thread.  Once the heir is running an attempt
36 *  is made to dispatch any ASRs.
37 *
38 *  ALTERNATE ENTRY POINTS:
39 *    void _Thread_Enable_dispatch();
40 *
41 *  Input parameters:  NONE
42 *
43 *  Output parameters:  NONE
44 *
45 *  INTERRUPT LATENCY:
46 *    dispatch thread
47 *    no dispatch thread
48 */
49
50#if ( CPU_INLINE_ENABLE_DISPATCH == FALSE )
51void _Thread_Enable_dispatch( void )
52{
53  if ( --_Thread_Dispatch_disable_level )
54    return;
55  _Thread_Dispatch();
56}
57#endif
58
59void _Thread_Dispatch( void )
60{
61  Thread_Control   *executing;
62  Thread_Control   *heir;
63  ISR_Level         level;
64
65  executing   = _Thread_Executing;
66  _ISR_Disable( level );
67  while ( _Context_Switch_necessary == TRUE ) {
68    heir = _Thread_Heir;
69    _Thread_Dispatch_disable_level = 1;
70    _Context_Switch_necessary = FALSE;
71    _Thread_Executing = heir;
72    executing->rtems_ada_self = rtems_ada_self;
73    rtems_ada_self = heir->rtems_ada_self;
74    _ISR_Enable( level );
75
76    heir->ticks_executed++;
77
78    _User_extensions_Thread_switch( executing, heir );
79
80    if ( heir->budget_algorithm == THREAD_CPU_BUDGET_ALGORITHM_RESET_TIMESLICE )
81      heir->cpu_time_budget = _Thread_Ticks_per_timeslice;
82
83    /*
84     *  If the CPU has hardware floating point, then we must address saving
85     *  and restoring it as part of the context switch.
86     *
87     *  The second conditional compilation section selects the algorithm used
88     *  to context switch between floating point tasks.  The deferred algorithm
89     *  can be significantly better in a system with few floating point tasks
90     *  because it reduces the total number of save and restore FP context
91     *  operations.  However, this algorithm can not be used on all CPUs due
92     *  to unpredictable use of FP registers by some compilers for integer
93     *  operations.
94     */
95
96#if ( CPU_HARDWARE_FP == TRUE )
97#if ( CPU_USE_DEFERRED_FP_SWITCH == TRUE )
98    if ( (heir->fp_context != NULL) && !_Thread_Is_allocated_fp( heir ) ) {
99      if ( _Thread_Allocated_fp != NULL )
100        _Context_Save_fp( &_Thread_Allocated_fp->fp_context );
101      _Context_Restore_fp( &heir->fp_context );
102      _Thread_Allocated_fp = heir;
103    }
104#else
105    if ( executing->fp_context != NULL )
106      _Context_Save_fp( &executing->fp_context );
107
108    if ( heir->fp_context != NULL )
109      _Context_Restore_fp( &heir->fp_context );
110#endif
111#endif
112
113    _Context_Switch( &executing->Registers, &heir->Registers );
114
115    executing = _Thread_Executing;
116
117    _ISR_Disable( level );
118  }
119
120  _Thread_Dispatch_disable_level = 0;
121
122  _ISR_Enable( level );
123
124  if ( _Thread_Do_post_task_switch_extension ||
125       executing->do_post_task_switch_extension ) {
126    executing->do_post_task_switch_extension = FALSE;
127    _API_extensions_Run_postswitch();
128  }
129 
130}
Note: See TracBrowser for help on using the repository browser.