soft timer 疑问

15 views
Skip to first unread message

Lost Temple

unread,
Sep 24, 2014, 11:21:34 PM9/24/14
to rt-threa...@googlegroups.com
393 rt_hw_interrupt_enable(level);     
394    
395 #ifdef RT_USING_TIMER_SOFT
396     if (timer->parent.flag & RT_TIMER_FLAG_SOFT_TIMER)
397     {
398         /* check whether timer thread is ready */
399         if (timer_thread.stat != RT_THREAD_READY)
400         {
401             /* resume timer thread to check soft timer */
402             rt_thread_resume(&timer_thread);
403             rt_schedule();
404         }
405     }
406 #endif




如果当前是rt_thread_timer_entry在执行,当运行到394行被抢占并且被添加了一个新的soft timer,会不会出现bug?

Lost Temple

unread,
Sep 25, 2014, 12:46:23 AM9/25/14
to rt-threa...@googlegroups.com
文件名是 src/timer.c,不是太熟悉这个论坛的使用,sorry.

Lost Temple於 2014年9月25日星期四UTC+8上午11時21分34秒寫道:

Grissiom

unread,
Sep 25, 2014, 1:18:25 AM9/25/14
to rt-threa...@googlegroups.com
Hi,
这个没关系的~ 最多就是调用两次 resume 和 schedule。软定时器线程会被多唤醒一次。这多唤醒的一次不会引起问题的~

--
Cheers,
Grissiom

leslie

unread,
Sep 25, 2014, 2:32:37 AM9/25/14
to rt-threa...@googlegroups.com

timer thread本来就在运行,resume和schedule是什么效果?

--
You received this message because you are subscribed to a topic in the Google Groups "rt-thread用户组" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/rt-thread-cnusers/-bREUCrAnuA/unsubscribe.
To unsubscribe from this group and all its topics, send an email to rt-thread-cnus...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Grissiom

unread,
Sep 25, 2014, 5:53:30 AM9/25/14
to rt-threa...@googlegroups.com
On Thu, Sep 25, 2014 at 2:32 PM, leslie <lesli...@gmail.com> wrote:

timer thread本来就在运行,resume和schedule是什么效果?


如果是本来就在运行的话,resume 没有效果。schedule 的作用是选择最高优先级线程跳过去。因为之前本来就应该是最高优先级的线程在跑,所以这样也没有效果……

--
Cheers,
Grissiom

leslie

unread,
Sep 25, 2014, 6:50:18 AM9/25/14
to rt-threa...@googlegroups.com

所以我觉得这里有问题,被抢占后加的timer不会被timer thread察觉。

--

Grissiom

unread,
Sep 25, 2014, 7:00:08 AM9/25/14
to rt-threa...@googlegroups.com
On Thu, Sep 25, 2014 at 6:50 PM, leslie <lesli...@gmail.com> wrote:

所以我觉得这里有问题,被抢占后加的timer不会被timer thread察觉。


嗯,挺好的点~ 那么出了小问题:“是那块代码没有保护好,导致的‘后加的timer不会被timer thread察觉’呢?”

--
Cheers,
Grissiom

leslie

unread,
Sep 25, 2014, 7:11:56 AM9/25/14
to rt-threa...@googlegroups.com

393行使能了中断

--

Grissiom

unread,
Sep 25, 2014, 7:22:17 AM9/25/14
to rt-threa...@googlegroups.com
On Thu, Sep 25, 2014 at 7:11 PM, leslie <lesli...@gmail.com> wrote:

393行使能了中断


为什么这里使能了中断就丢掉了呢?

软定时器线程里可是循环查找的,嘿嘿嘿……

--
Cheers,
Grissiom

leslie

unread,
Sep 25, 2014, 7:56:17 AM9/25/14
to rt-threa...@googlegroups.com

timer thread是因为调用了delay到这个函数的,这之后应该会suspend,suspend的时间是根据之前加的timer的timeout时间,而在这里中断使能后加的timer得等这个time out之后才会被check,你可以看一下timer thread跑到这里的callstack,我手边现在没电脑,应该没记错。

--

Grissiom

unread,
Sep 27, 2014, 10:18:24 PM9/27/14
to rt-threa...@googlegroups.com
On Thu, Sep 25, 2014 at 7:56 PM, leslie <lesli...@gmail.com> wrote:

timer thread是因为调用了delay到这个函数的,这之后应该会suspend,suspend的时间是根据之前加的timer的timeout时间,而在这里中断使能后加的timer得等这个time out之后才会被check,你可以看一下timer thread跑到这里的callstack,我手边现在没电脑,应该没记错。


那么,在加入 timer 的时候多关中断就可以避免这个问题了么?

还有,你有没有兴趣去 fix 这个问题呢?这样在历史记录中就会有你的名字了,嘿嘿嘿……

--
Cheers,
Grissiom
Reply all
Reply to author
Forward
0 new messages