source: rtems/cpukit/score/src/threaddispatch.c @ 3bc12a8f

5
Last change on this file since 3bc12a8f was 3bc12a8f, checked in by Sebastian Huber <sebastian.huber@…>, on 01/26/16 at 10:16:56

Delete unused API extensions

  • Property mode set to 100644
File size: 4.1 KB
Line 
1/**
2 * @file
3 *
4 * @brief Dispatch Thread
5 * @ingroup ScoreThread
6 */
7
8/*
9 *  COPYRIGHT (c) 1989-2009.
10 *  On-Line Applications Research Corporation (OAR).
11 *
12 *  Copyright (c) 2014 embedded brains GmbH.
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.org/license/LICENSE.
17 */
18
19#if HAVE_CONFIG_H
20#include "config.h"
21#endif
22
23#include <rtems/score/threaddispatch.h>
24#include <rtems/score/assert.h>
25#include <rtems/score/isr.h>
26#include <rtems/score/threadimpl.h>
27#include <rtems/score/todimpl.h>
28#include <rtems/score/userextimpl.h>
29#include <rtems/score/wkspace.h>
30#include <rtems/config.h>
31
32CHAIN_DEFINE_EMPTY( _User_extensions_Switches_list );
33
34static Thread_Action *_Thread_Get_post_switch_action(
35  Thread_Control *executing
36)
37{
38  Chain_Control *chain = &executing->Post_switch_actions.Chain;
39
40  return (Thread_Action *) _Chain_Get_unprotected( chain );
41}
42
43static void _Thread_Run_post_switch_actions( Thread_Control *executing )
44{
45  ISR_Level        level;
46  Per_CPU_Control *cpu_self;
47  Thread_Action   *action;
48
49  cpu_self = _Thread_Action_ISR_disable_and_acquire( executing, &level );
50  action = _Thread_Get_post_switch_action( executing );
51
52  while ( action != NULL ) {
53    _Chain_Set_off_chain( &action->Node );
54
55    ( *action->handler )( executing, action, cpu_self, level );
56
57    cpu_self = _Thread_Action_ISR_disable_and_acquire( executing, &level );
58    action = _Thread_Get_post_switch_action( executing );
59  }
60
61  _Thread_Action_release_and_ISR_enable( cpu_self, level );
62}
63
64void _Thread_Do_dispatch( Per_CPU_Control *cpu_self, ISR_Level level )
65{
66  Thread_Control *executing;
67
68  _Assert( cpu_self->thread_dispatch_disable_level == 1 );
69
70  executing = cpu_self->executing;
71
72  do {
73    Thread_Control *heir = _Thread_Get_heir_and_make_it_executing( cpu_self );
74
75    /*
76     *  When the heir and executing are the same, then we are being
77     *  requested to do the post switch dispatching.  This is normally
78     *  done to dispatch signals.
79     */
80    if ( heir == executing )
81      goto post_switch;
82
83    /*
84     *  Since heir and executing are not the same, we need to do a real
85     *  context switch.
86     */
87#if __RTEMS_ADA__
88    executing->rtems_ada_self = rtems_ada_self;
89    rtems_ada_self = heir->rtems_ada_self;
90#endif
91    if ( heir->budget_algorithm == THREAD_CPU_BUDGET_ALGORITHM_RESET_TIMESLICE )
92      heir->cpu_time_budget = rtems_configuration_get_ticks_per_timeslice();
93
94    /*
95     * On SMP the complete context switch must be atomic with respect to one
96     * processor.  See also _Thread_Handler() since _Context_switch() may branch
97     * to this function.
98     */
99#if !defined( RTEMS_SMP )
100    _ISR_Enable( level );
101#endif
102
103    _Thread_Update_cpu_time_used(
104      executing,
105      &cpu_self->time_of_last_context_switch
106    );
107
108    _User_extensions_Thread_switch( executing, heir );
109    _Thread_Save_fp( executing );
110    _Context_Switch( &executing->Registers, &heir->Registers );
111    _Thread_Restore_fp( executing );
112
113    /*
114     * We have to obtain this value again after the context switch since the
115     * heir thread may have migrated from another processor.  Values from the
116     * stack or non-volatile registers reflect the old execution environment.
117     */
118    cpu_self = _Per_CPU_Get();
119
120    _Thread_Debug_set_real_processor( executing, cpu_self );
121
122#if !defined( RTEMS_SMP )
123    _ISR_Disable( level );
124#endif
125  } while (
126#if defined( RTEMS_SMP )
127    false
128#else
129    cpu_self->dispatch_necessary
130#endif
131  );
132
133post_switch:
134  _Assert( cpu_self->thread_dispatch_disable_level == 1 );
135  cpu_self->thread_dispatch_disable_level = 0;
136  _Profiling_Thread_dispatch_enable( cpu_self, 0 );
137
138  _ISR_Enable_without_giant( level );
139
140  _Thread_Run_post_switch_actions( executing );
141}
142
143void _Thread_Dispatch( void )
144{
145  ISR_Level        level;
146  Per_CPU_Control *cpu_self;
147
148  _ISR_Disable_without_giant( level );
149
150  cpu_self = _Per_CPU_Get();
151
152  if ( cpu_self->dispatch_necessary ) {
153    _Profiling_Thread_dispatch_disable( cpu_self, 0 );
154    cpu_self->thread_dispatch_disable_level = 1;
155    _Thread_Do_dispatch( cpu_self, level );
156  } else {
157    _ISR_Enable_without_giant( level );
158  }
159}
Note: See TracBrowser for help on using the repository browser.