@@ -48,7 +48,6 @@ rt_uint8_t rt_thread_ready_table[32];
4848
4949extern volatile rt_uint8_t rt_interrupt_nest ;
5050static rt_int16_t rt_scheduler_lock_nest ;
51- struct rt_thread * rt_current_thread = RT_NULL ;
5251rt_uint8_t rt_current_priority ;
5352
5453#if defined(RT_USING_HOOK ) && defined(RT_HOOK_USING_FUNC_PTR )
@@ -175,7 +174,7 @@ void rt_system_scheduler_start(void)
175174
176175 to_thread = _scheduler_get_highest_priority_thread (& highest_ready_priority );
177176
178- rt_current_thread = to_thread ;
177+ rt_cpu_self () -> current_thread = to_thread ;
179178
180179 rt_sched_remove_thread (to_thread );
181180 RT_SCHED_CTX (to_thread ).stat = RT_THREAD_RUNNING ;
@@ -203,6 +202,8 @@ void rt_schedule(void)
203202 rt_base_t level ;
204203 struct rt_thread * to_thread ;
205204 struct rt_thread * from_thread ;
205+ /* using local variable to avoid unecessary function call */
206+ struct rt_thread * curr_thread = rt_thread_self ();
206207
207208 /* disable interrupt */
208209 level = rt_hw_interrupt_disable ();
@@ -219,28 +220,29 @@ void rt_schedule(void)
219220
220221 to_thread = _scheduler_get_highest_priority_thread (& highest_ready_priority );
221222
222- if ((RT_SCHED_CTX (rt_current_thread ).stat & RT_THREAD_STAT_MASK ) == RT_THREAD_RUNNING )
223+ if ((RT_SCHED_CTX (curr_thread ).stat & RT_THREAD_STAT_MASK ) == RT_THREAD_RUNNING )
223224 {
224- if (RT_SCHED_PRIV (rt_current_thread ).current_priority < highest_ready_priority )
225+ if (RT_SCHED_PRIV (curr_thread ).current_priority < highest_ready_priority )
225226 {
226- to_thread = rt_current_thread ;
227+ to_thread = curr_thread ;
227228 }
228- else if (RT_SCHED_PRIV (rt_current_thread ).current_priority == highest_ready_priority && (RT_SCHED_CTX (rt_current_thread ).stat & RT_THREAD_STAT_YIELD_MASK ) == 0 )
229+ else if (RT_SCHED_PRIV (curr_thread ).current_priority == highest_ready_priority
230+ && (RT_SCHED_CTX (curr_thread ).stat & RT_THREAD_STAT_YIELD_MASK ) == 0 )
229231 {
230- to_thread = rt_current_thread ;
232+ to_thread = curr_thread ;
231233 }
232234 else
233235 {
234236 need_insert_from_thread = 1 ;
235237 }
236238 }
237239
238- if (to_thread != rt_current_thread )
240+ if (to_thread != curr_thread )
239241 {
240242 /* if the destination thread is not the same as current thread */
241243 rt_current_priority = (rt_uint8_t )highest_ready_priority ;
242- from_thread = rt_current_thread ;
243- rt_current_thread = to_thread ;
244+ from_thread = curr_thread ;
245+ rt_cpu_self () -> current_thread = to_thread ;
244246
245247 RT_OBJECT_HOOK_CALL (rt_scheduler_hook , (from_thread , to_thread ));
246248
@@ -282,11 +284,11 @@ void rt_schedule(void)
282284#ifdef RT_USING_SIGNALS
283285 /* check stat of thread for signal */
284286 level = rt_hw_interrupt_disable ();
285- if (RT_SCHED_CTX (rt_current_thread ).stat & RT_THREAD_STAT_SIGNAL_PENDING )
287+ if (RT_SCHED_CTX (curr_thread ).stat & RT_THREAD_STAT_SIGNAL_PENDING )
286288 {
287289 extern void rt_thread_handle_sig (rt_bool_t clean_state );
288290
289- RT_SCHED_CTX (rt_current_thread ).stat &= ~RT_THREAD_STAT_SIGNAL_PENDING ;
291+ RT_SCHED_CTX (curr_thread ).stat &= ~RT_THREAD_STAT_SIGNAL_PENDING ;
290292
291293 rt_hw_interrupt_enable (level );
292294
@@ -310,8 +312,8 @@ void rt_schedule(void)
310312 }
311313 else
312314 {
313- rt_sched_remove_thread (rt_current_thread );
314- RT_SCHED_CTX (rt_current_thread ).stat = RT_THREAD_RUNNING | (RT_SCHED_CTX (rt_current_thread ).stat & ~RT_THREAD_STAT_MASK );
315+ rt_sched_remove_thread (curr_thread );
316+ RT_SCHED_CTX (curr_thread ).stat = RT_THREAD_RUNNING | (RT_SCHED_CTX (curr_thread ).stat & ~RT_THREAD_STAT_MASK );
315317 }
316318 }
317319 }
@@ -564,10 +566,5 @@ rt_err_t rt_sched_thread_bind_cpu(struct rt_thread *thread, int cpu)
564566 return - RT_EINVAL ;
565567}
566568
567- rt_thread_t rt_sched_thread_self (void )
568- {
569- return rt_current_thread ;
570- }
571-
572569/**@}*/
573570/**@endcond*/
0 commit comments