From 302f179c851d3a8c953400ca0d2789546c50491c Mon Sep 17 00:00:00 2001 From: liruncong Date: Tue, 9 Feb 2021 23:18:45 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E4=BF=AE=E6=AD=A3rt=5Fthread=5Fdelay=5Funt?= =?UTF-8?q?il=E6=97=B6=E9=97=B4=E4=B8=8D=E5=87=86=E9=97=AE=E9=A2=98?= =?UTF-8?q?=EF=BC=8C=E5=8F=8A=E9=94=99=E8=AF=AF=E4=BD=BF=E7=94=A8=E6=97=A0?= =?UTF-8?q?=E7=AC=A6=E5=8F=B7=E6=AF=94=E8=BE=83=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/thread.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/thread.c b/src/thread.c index 0db9dd8e4d..627b7e898e 100644 --- a/src/thread.c +++ b/src/thread.c @@ -585,6 +585,7 @@ rt_err_t rt_thread_delay_until(rt_tick_t *tick, rt_tick_t inc_tick) { register rt_base_t level; struct rt_thread *thread; + rt_tick_t cur_tick; RT_ASSERT(tick != RT_NULL); @@ -596,15 +597,19 @@ rt_err_t rt_thread_delay_until(rt_tick_t *tick, rt_tick_t inc_tick) /* disable interrupt */ level = rt_hw_interrupt_disable(); - if (rt_tick_get() - *tick < inc_tick) + cur_tick = rt_tick_get(); + if ((rt_int32_t)(cur_tick - *tick) < (rt_int32_t)inc_tick) { - *tick = *tick + inc_tick - rt_tick_get(); + rt_tick_t left_tick; + + *tick += inc_tick; + left_tick = *tick - cur_tick; /* suspend thread */ rt_thread_suspend(thread); /* reset the timeout of thread timer and start it */ - rt_timer_control(&(thread->thread_timer), RT_TIMER_CTRL_SET_TIME, tick); + rt_timer_control(&(thread->thread_timer), RT_TIMER_CTRL_SET_TIME, &left_tick); rt_timer_start(&(thread->thread_timer)); /* enable interrupt */ @@ -620,12 +625,10 @@ rt_err_t rt_thread_delay_until(rt_tick_t *tick, rt_tick_t inc_tick) } else { + *tick = cur_tick; rt_hw_interrupt_enable(level); } - /* get the wakeup tick */ - *tick = rt_tick_get(); - return RT_EOK; } RTM_EXPORT(rt_thread_delay_until); From 5ce889ea820e1c5bbadc41a0464b2dcdf3e607fc Mon Sep 17 00:00:00 2001 From: liruncong Date: Thu, 4 Mar 2021 19:33:28 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E6=92=A4=E9=94=80=E6=9C=89=E7=AC=A6?= =?UTF-8?q?=E5=8F=B7=E6=AF=94=E8=BE=83=EF=BC=8C=E4=BB=8D=E5=BA=94=E4=BD=BF?= =?UTF-8?q?=E7=94=A8=E6=97=A0=E7=AC=A6=E5=8F=B7=E6=AF=94=E8=BE=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/thread.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/thread.c b/src/thread.c index 627b7e898e..c2a3e2e797 100644 --- a/src/thread.c +++ b/src/thread.c @@ -598,7 +598,7 @@ rt_err_t rt_thread_delay_until(rt_tick_t *tick, rt_tick_t inc_tick) level = rt_hw_interrupt_disable(); cur_tick = rt_tick_get(); - if ((rt_int32_t)(cur_tick - *tick) < (rt_int32_t)inc_tick) + if (cur_tick - *tick < inc_tick) { rt_tick_t left_tick;