source: rtems/cpukit/score/src/threaddispatch.c @ 8896c97

4.115
Last change on this file since 8896c97 was 8896c97, checked in by Joel Sherrill <joel.sherrill@…>, on 10/02/12 at 18:28:08

threaddispatch.c: Fix typo

  • Property mode set to 100644
File size: 4.7 KB
Line 
1/*
2 *  Thread Handler
3 *
4 *  COPYRIGHT (c) 1989-2009.
5 *  On-Line Applications Research Corporation (OAR).
6 *
7 *  The license and distribution terms for this file may be
8 *  found in the file LICENSE in this distribution or at
9 *  http://www.rtems.com/license/LICENSE.
10 */
11
12#if HAVE_CONFIG_H
13#include "config.h"
14#endif
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#ifndef __RTEMS_USE_TICKS_FOR_STATISTICS__
31  #include <rtems/score/timestamp.h>
32#endif
33
34#if defined(RTEMS_SMP)
35  #include <rtems/score/smp.h>
36#endif
37
38/**
39 *  _Thread_Dispatch
40 *
41 *  This kernel routine determines if a dispatch is needed, and if so
42 *  dispatches to the heir thread.  Once the heir is running an attempt
43 *  is made to dispatch any ASRs.
44 *
45 *  ALTERNATE ENTRY POINTS:
46 *    void _Thread_Enable_dispatch();
47 *
48 *  INTERRUPT LATENCY:
49 *    dispatch thread
50 *    no dispatch thread
51 */
52void _Thread_Dispatch( void )
53{
54  Thread_Control   *executing;
55  Thread_Control   *heir;
56  ISR_Level         level;
57
58  _Thread_Disable_dispatch();
59  #if defined(RTEMS_SMP)
60    /*
61     *  If necessary, send dispatch request to other cores.
62     */
63    _SMP_Request_other_cores_to_dispatch();
64  #endif
65
66  /*
67   *  Now determine if we need to perform a dispatch on the current CPU.
68   */
69  executing   = _Thread_Executing;
70  _ISR_Disable( level );
71  while ( _Thread_Dispatch_necessary == true ) {
72
73    heir = _Thread_Heir;
74    _Thread_Dispatch_necessary = false;
75    _Thread_Executing = heir;
76
77    /*
78     *  When the heir and executing are the same, then we are being
79     *  requested to do the post switch dispatching.  This is normally
80     *  done to dispatch signals.
81     */
82    if ( heir == executing )
83      goto post_switch;
84
85    /*
86     *  Since heir and executing are not the same, we need to do a real
87     *  context switch.
88     */
89#if __RTEMS_ADA__
90    executing->rtems_ada_self = rtems_ada_self;
91    rtems_ada_self = heir->rtems_ada_self;
92#endif
93    if ( heir->budget_algorithm == THREAD_CPU_BUDGET_ALGORITHM_RESET_TIMESLICE )
94      heir->cpu_time_budget = _Thread_Ticks_per_timeslice;
95
96    _ISR_Enable( level );
97
98    #ifndef __RTEMS_USE_TICKS_FOR_STATISTICS__
99      {
100        Timestamp_Control uptime, ran;
101        _TOD_Get_uptime( &uptime );
102        _Timestamp_Subtract(
103          &_Thread_Time_of_last_context_switch,
104          &uptime,
105          &ran
106        );
107        _Timestamp_Add_to( &executing->cpu_time_used, &ran );
108        _Thread_Time_of_last_context_switch = uptime;
109      }
110    #else
111      {
112        _TOD_Get_uptime( &_Thread_Time_of_last_context_switch );
113        heir->cpu_time_used++;
114      }
115    #endif
116
117    /*
118     * Switch libc's task specific data.
119     */
120    if ( _Thread_libc_reent ) {
121      executing->libc_reent = *_Thread_libc_reent;
122      *_Thread_libc_reent = heir->libc_reent;
123    }
124
125    _User_extensions_Thread_switch( executing, heir );
126
127    /*
128     *  If the CPU has hardware floating point, then we must address saving
129     *  and restoring it as part of the context switch.
130     *
131     *  The second conditional compilation section selects the algorithm used
132     *  to context switch between floating point tasks.  The deferred algorithm
133     *  can be significantly better in a system with few floating point tasks
134     *  because it reduces the total number of save and restore FP context
135     *  operations.  However, this algorithm can not be used on all CPUs due
136     *  to unpredictable use of FP registers by some compilers for integer
137     *  operations.
138     */
139
140#if ( CPU_HARDWARE_FP == TRUE ) || ( CPU_SOFTWARE_FP == TRUE )
141#if ( CPU_USE_DEFERRED_FP_SWITCH != TRUE )
142    if ( executing->fp_context != NULL )
143      _Context_Save_fp( &executing->fp_context );
144#endif
145#endif
146
147    _Context_Switch( &executing->Registers, &heir->Registers );
148
149#if ( CPU_HARDWARE_FP == TRUE ) || ( CPU_SOFTWARE_FP == TRUE )
150#if ( CPU_USE_DEFERRED_FP_SWITCH == TRUE )
151    if ( (executing->fp_context != NULL) &&
152         !_Thread_Is_allocated_fp( executing ) ) {
153      if ( _Thread_Allocated_fp != NULL )
154        _Context_Save_fp( &_Thread_Allocated_fp->fp_context );
155      _Context_Restore_fp( &executing->fp_context );
156      _Thread_Allocated_fp = executing;
157    }
158#else
159    if ( executing->fp_context != NULL )
160      _Context_Restore_fp( &executing->fp_context );
161#endif
162#endif
163
164    executing = _Thread_Executing;
165
166    _ISR_Disable( level );
167  }
168
169post_switch:
170
171  _ISR_Enable( level );
172
173  _Thread_Unnest_dispatch();
174 
175  _API_extensions_Run_postswitch();
176}
Note: See TracBrowser for help on using the repository browser.