/*
|
/*
|
* Thread Handler
|
* Thread Handler
|
*
|
*
|
*
|
*
|
* COPYRIGHT (c) 1989-1999.
|
* COPYRIGHT (c) 1989-1999.
|
* On-Line Applications Research Corporation (OAR).
|
* On-Line Applications Research Corporation (OAR).
|
*
|
*
|
* The license and distribution terms for this file may be
|
* The license and distribution terms for this file may be
|
* found in found in the file LICENSE in this distribution or at
|
* found in found in the file LICENSE in this distribution or at
|
* http://www.OARcorp.com/rtems/license.html.
|
* http://www.OARcorp.com/rtems/license.html.
|
*
|
*
|
* threaddispatch.c,v 1.5 2002/05/15 15:14:58 joel Exp
|
* threaddispatch.c,v 1.5 2002/05/15 15:14:58 joel Exp
|
*/
|
*/
|
|
|
#include <rtems/system.h>
|
#include <rtems/system.h>
|
#include <rtems/score/apiext.h>
|
#include <rtems/score/apiext.h>
|
#include <rtems/score/context.h>
|
#include <rtems/score/context.h>
|
#include <rtems/score/interr.h>
|
#include <rtems/score/interr.h>
|
#include <rtems/score/isr.h>
|
#include <rtems/score/isr.h>
|
#include <rtems/score/object.h>
|
#include <rtems/score/object.h>
|
#include <rtems/score/priority.h>
|
#include <rtems/score/priority.h>
|
#include <rtems/score/states.h>
|
#include <rtems/score/states.h>
|
#include <rtems/score/sysstate.h>
|
#include <rtems/score/sysstate.h>
|
#include <rtems/score/thread.h>
|
#include <rtems/score/thread.h>
|
#include <rtems/score/threadq.h>
|
#include <rtems/score/threadq.h>
|
#include <rtems/score/userext.h>
|
#include <rtems/score/userext.h>
|
#include <rtems/score/wkspace.h>
|
#include <rtems/score/wkspace.h>
|
|
|
/*PAGE
|
/*PAGE
|
*
|
*
|
* _Thread_Dispatch
|
* _Thread_Dispatch
|
*
|
*
|
* This kernel routine determines if a dispatch is needed, and if so
|
* This kernel routine determines if a dispatch is needed, and if so
|
* dispatches to the heir thread. Once the heir is running an attempt
|
* dispatches to the heir thread. Once the heir is running an attempt
|
* is made to dispatch any ASRs.
|
* is made to dispatch any ASRs.
|
*
|
*
|
* ALTERNATE ENTRY POINTS:
|
* ALTERNATE ENTRY POINTS:
|
* void _Thread_Enable_dispatch();
|
* void _Thread_Enable_dispatch();
|
*
|
*
|
* Input parameters: NONE
|
* Input parameters: NONE
|
*
|
*
|
* Output parameters: NONE
|
* Output parameters: NONE
|
*
|
*
|
* INTERRUPT LATENCY:
|
* INTERRUPT LATENCY:
|
* dispatch thread
|
* dispatch thread
|
* no dispatch thread
|
* no dispatch thread
|
*/
|
*/
|
|
|
#if ( CPU_INLINE_ENABLE_DISPATCH == FALSE )
|
#if ( CPU_INLINE_ENABLE_DISPATCH == FALSE )
|
void _Thread_Enable_dispatch( void )
|
void _Thread_Enable_dispatch( void )
|
{
|
{
|
if ( --_Thread_Dispatch_disable_level )
|
if ( --_Thread_Dispatch_disable_level )
|
return;
|
return;
|
_Thread_Dispatch();
|
_Thread_Dispatch();
|
}
|
}
|
#endif
|
#endif
|
|
|
void _Thread_Dispatch( void )
|
void _Thread_Dispatch( void )
|
{
|
{
|
Thread_Control *executing;
|
Thread_Control *executing;
|
Thread_Control *heir;
|
Thread_Control *heir;
|
ISR_Level level;
|
ISR_Level level;
|
|
|
executing = _Thread_Executing;
|
executing = _Thread_Executing;
|
_ISR_Disable( level );
|
_ISR_Disable( level );
|
while ( _Context_Switch_necessary == TRUE ) {
|
while ( _Context_Switch_necessary == TRUE ) {
|
heir = _Thread_Heir;
|
heir = _Thread_Heir;
|
_Thread_Dispatch_disable_level = 1;
|
_Thread_Dispatch_disable_level = 1;
|
_Context_Switch_necessary = FALSE;
|
_Context_Switch_necessary = FALSE;
|
_Thread_Executing = heir;
|
_Thread_Executing = heir;
|
executing->rtems_ada_self = rtems_ada_self;
|
executing->rtems_ada_self = rtems_ada_self;
|
rtems_ada_self = heir->rtems_ada_self;
|
rtems_ada_self = heir->rtems_ada_self;
|
_ISR_Enable( level );
|
_ISR_Enable( level );
|
|
|
heir->ticks_executed++;
|
heir->ticks_executed++;
|
|
|
/*
|
/*
|
* Switch libc's task specific data.
|
* Switch libc's task specific data.
|
*/
|
*/
|
if ( _Thread_libc_reent ) {
|
if ( _Thread_libc_reent ) {
|
executing->libc_reent = *_Thread_libc_reent;
|
executing->libc_reent = *_Thread_libc_reent;
|
*_Thread_libc_reent = heir->libc_reent;
|
*_Thread_libc_reent = heir->libc_reent;
|
}
|
}
|
|
|
_User_extensions_Thread_switch( executing, heir );
|
_User_extensions_Thread_switch( executing, heir );
|
|
|
if ( heir->budget_algorithm == THREAD_CPU_BUDGET_ALGORITHM_RESET_TIMESLICE )
|
if ( heir->budget_algorithm == THREAD_CPU_BUDGET_ALGORITHM_RESET_TIMESLICE )
|
heir->cpu_time_budget = _Thread_Ticks_per_timeslice;
|
heir->cpu_time_budget = _Thread_Ticks_per_timeslice;
|
|
|
/*
|
/*
|
* If the CPU has hardware floating point, then we must address saving
|
* If the CPU has hardware floating point, then we must address saving
|
* and restoring it as part of the context switch.
|
* and restoring it as part of the context switch.
|
*
|
*
|
* The second conditional compilation section selects the algorithm used
|
* The second conditional compilation section selects the algorithm used
|
* to context switch between floating point tasks. The deferred algorithm
|
* to context switch between floating point tasks. The deferred algorithm
|
* can be significantly better in a system with few floating point tasks
|
* can be significantly better in a system with few floating point tasks
|
* because it reduces the total number of save and restore FP context
|
* because it reduces the total number of save and restore FP context
|
* operations. However, this algorithm can not be used on all CPUs due
|
* operations. However, this algorithm can not be used on all CPUs due
|
* to unpredictable use of FP registers by some compilers for integer
|
* to unpredictable use of FP registers by some compilers for integer
|
* operations.
|
* operations.
|
*/
|
*/
|
|
|
#if ( CPU_HARDWARE_FP == TRUE ) || ( CPU_SOFTWARE_FP == TRUE )
|
#if ( CPU_HARDWARE_FP == TRUE ) || ( CPU_SOFTWARE_FP == TRUE )
|
#if ( CPU_USE_DEFERRED_FP_SWITCH != TRUE )
|
#if ( CPU_USE_DEFERRED_FP_SWITCH != TRUE )
|
if ( executing->fp_context != NULL )
|
if ( executing->fp_context != NULL )
|
_Context_Save_fp( &executing->fp_context );
|
_Context_Save_fp( &executing->fp_context );
|
#endif
|
#endif
|
#endif
|
#endif
|
|
|
_Context_Switch( &executing->Registers, &heir->Registers );
|
_Context_Switch( &executing->Registers, &heir->Registers );
|
|
|
#if ( CPU_HARDWARE_FP == TRUE ) || ( CPU_SOFTWARE_FP == TRUE )
|
#if ( CPU_HARDWARE_FP == TRUE ) || ( CPU_SOFTWARE_FP == TRUE )
|
#if ( CPU_USE_DEFERRED_FP_SWITCH == TRUE )
|
#if ( CPU_USE_DEFERRED_FP_SWITCH == TRUE )
|
if ( (executing->fp_context != NULL) && !_Thread_Is_allocated_fp( executing ) ) {
|
if ( (executing->fp_context != NULL) && !_Thread_Is_allocated_fp( executing ) ) {
|
if ( _Thread_Allocated_fp != NULL )
|
if ( _Thread_Allocated_fp != NULL )
|
_Context_Save_fp( &_Thread_Allocated_fp->fp_context );
|
_Context_Save_fp( &_Thread_Allocated_fp->fp_context );
|
_Context_Restore_fp( &executing->fp_context );
|
_Context_Restore_fp( &executing->fp_context );
|
_Thread_Allocated_fp = executing;
|
_Thread_Allocated_fp = executing;
|
}
|
}
|
#else
|
#else
|
if ( executing->fp_context != NULL )
|
if ( executing->fp_context != NULL )
|
_Context_Restore_fp( &executing->fp_context );
|
_Context_Restore_fp( &executing->fp_context );
|
#endif
|
#endif
|
#endif
|
#endif
|
|
|
executing = _Thread_Executing;
|
executing = _Thread_Executing;
|
|
|
_ISR_Disable( level );
|
_ISR_Disable( level );
|
}
|
}
|
|
|
_Thread_Dispatch_disable_level = 0;
|
_Thread_Dispatch_disable_level = 0;
|
|
|
_ISR_Enable( level );
|
_ISR_Enable( level );
|
|
|
if ( _Thread_Do_post_task_switch_extension ||
|
if ( _Thread_Do_post_task_switch_extension ||
|
executing->do_post_task_switch_extension ) {
|
executing->do_post_task_switch_extension ) {
|
executing->do_post_task_switch_extension = FALSE;
|
executing->do_post_task_switch_extension = FALSE;
|
_API_extensions_Run_postswitch();
|
_API_extensions_Run_postswitch();
|
}
|
}
|
|
|
}
|
}
|
|
|