Skip to content

Commit 735b65a

Browse files
committed
rt_tick_get_delta 替代 rt_tick_get() - tick_delta 获取增量
1 parent 8525e08 commit 735b65a

File tree

2 files changed

+22
-26
lines changed

2 files changed

+22
-26
lines changed

src/ipc.c

Lines changed: 21 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
* 2022-10-15 Bernard add nested mutex feature
4646
* 2022-10-16 Bernard add prioceiling feature in mutex
4747
* 2023-04-16 Xin-zheqi redesigen queue recv and send function return real message size
48-
* 2023-09-15 xqyjlj perf rt_hw_interrupt_disable/enable
48+
* 2023-09-15 xqyjlj perf rt_hw_interrupt_disable/enable
4949
*/
5050

5151
#include <rtthread.h>
@@ -2567,7 +2567,7 @@ static rt_err_t _rt_mb_send_wait(rt_mailbox_t mb,
25672567
{
25682568
struct rt_thread *thread;
25692569
rt_base_t level;
2570-
rt_uint32_t tick_delta;
2570+
rt_uint32_t tick_stamp;
25712571
rt_err_t ret;
25722572

25732573
/* parameter check */
@@ -2577,8 +2577,8 @@ static rt_err_t _rt_mb_send_wait(rt_mailbox_t mb,
25772577
/* current context checking */
25782578
RT_DEBUG_SCHEDULER_AVAILABLE(timeout != 0);
25792579

2580-
/* initialize delta tick */
2581-
tick_delta = 0;
2580+
/* initialize tick_stamp tick */
2581+
tick_stamp = 0;
25822582
/* get current thread */
25832583
thread = rt_thread_self();
25842584

@@ -2622,7 +2622,7 @@ static rt_err_t _rt_mb_send_wait(rt_mailbox_t mb,
26222622
if (timeout > 0)
26232623
{
26242624
/* get the start tick of timer */
2625-
tick_delta = rt_tick_get();
2625+
tick_stamp = rt_tick_get();
26262626

26272627
LOG_D("mb_send_wait: start timer of thread:%s",
26282628
thread->parent.name);
@@ -2650,8 +2650,7 @@ static rt_err_t _rt_mb_send_wait(rt_mailbox_t mb,
26502650
/* if it's not waiting forever and then re-calculate timeout tick */
26512651
if (timeout > 0)
26522652
{
2653-
tick_delta = rt_tick_get() - tick_delta;
2654-
timeout -= tick_delta;
2653+
timeout -= rt_tick_get_delta(tick_stamp);
26552654
if (timeout < 0)
26562655
timeout = 0;
26572656
}
@@ -2846,7 +2845,7 @@ static rt_err_t _rt_mb_recv(rt_mailbox_t mb, rt_ubase_t *value, rt_int32_t timeo
28462845
{
28472846
struct rt_thread *thread;
28482847
rt_base_t level;
2849-
rt_uint32_t tick_delta;
2848+
rt_uint32_t tick_stamp;
28502849
rt_err_t ret;
28512850

28522851
/* parameter check */
@@ -2856,8 +2855,8 @@ static rt_err_t _rt_mb_recv(rt_mailbox_t mb, rt_ubase_t *value, rt_int32_t timeo
28562855
/* current context checking */
28572856
RT_DEBUG_SCHEDULER_AVAILABLE(timeout != 0);
28582857

2859-
/* initialize delta tick */
2860-
tick_delta = 0;
2858+
/* initialize tick_stamp tick */
2859+
tick_stamp = 0;
28612860
/* get current thread */
28622861
thread = rt_thread_self();
28632862

@@ -2902,7 +2901,7 @@ static rt_err_t _rt_mb_recv(rt_mailbox_t mb, rt_ubase_t *value, rt_int32_t timeo
29022901
if (timeout > 0)
29032902
{
29042903
/* get the start tick of timer */
2905-
tick_delta = rt_tick_get();
2904+
tick_stamp = rt_tick_get();
29062905

29072906
LOG_D("mb_recv: start timer of thread:%s",
29082907
thread->parent.name);
@@ -2930,8 +2929,7 @@ static rt_err_t _rt_mb_recv(rt_mailbox_t mb, rt_ubase_t *value, rt_int32_t timeo
29302929
/* if it's not waiting forever and then re-calculate timeout tick */
29312930
if (timeout > 0)
29322931
{
2933-
tick_delta = rt_tick_get() - tick_delta;
2934-
timeout -= tick_delta;
2932+
timeout -= rt_tick_get_delta(tick_stamp);
29352933
if (timeout < 0)
29362934
timeout = 0;
29372935
}
@@ -3382,7 +3380,7 @@ static rt_err_t _rt_mq_send_wait(rt_mq_t mq,
33823380
{
33833381
rt_base_t level;
33843382
struct rt_mq_message *msg;
3385-
rt_uint32_t tick_delta;
3383+
rt_uint32_t tick_stamp;
33863384
struct rt_thread *thread;
33873385
rt_err_t ret;
33883386

@@ -3401,8 +3399,8 @@ static rt_err_t _rt_mq_send_wait(rt_mq_t mq,
34013399
if (size > mq->msg_size)
34023400
return -RT_ERROR;
34033401

3404-
/* initialize delta tick */
3405-
tick_delta = 0;
3402+
/* initialize tick_stamp tick */
3403+
tick_stamp = 0;
34063404
/* get current thread */
34073405
thread = rt_thread_self();
34083406

@@ -3447,7 +3445,7 @@ static rt_err_t _rt_mq_send_wait(rt_mq_t mq,
34473445
if (timeout > 0)
34483446
{
34493447
/* get the start tick of timer */
3450-
tick_delta = rt_tick_get();
3448+
tick_stamp = rt_tick_get();
34513449

34523450
LOG_D("mq_send_wait: start timer of thread:%s",
34533451
thread->parent.name);
@@ -3475,8 +3473,7 @@ static rt_err_t _rt_mq_send_wait(rt_mq_t mq,
34753473
/* if it's not waiting forever and then re-calculate timeout tick */
34763474
if (timeout > 0)
34773475
{
3478-
tick_delta = rt_tick_get() - tick_delta;
3479-
timeout -= tick_delta;
3476+
timeout -= rt_tick_get_delta(tick_stamp);
34803477
if (timeout < 0)
34813478
timeout = 0;
34823479
}
@@ -3765,7 +3762,7 @@ static rt_ssize_t _rt_mq_recv(rt_mq_t mq,
37653762
struct rt_thread *thread;
37663763
rt_base_t level;
37673764
struct rt_mq_message *msg;
3768-
rt_uint32_t tick_delta;
3765+
rt_uint32_t tick_stamp;
37693766
rt_err_t ret;
37703767
rt_size_t len;
37713768

@@ -3780,8 +3777,8 @@ static rt_ssize_t _rt_mq_recv(rt_mq_t mq,
37803777
/* current context checking */
37813778
RT_DEBUG_SCHEDULER_AVAILABLE(timeout != 0);
37823779

3783-
/* initialize delta tick */
3784-
tick_delta = 0;
3780+
/* initialize tick_stamp tick */
3781+
tick_stamp = 0;
37853782
/* get current thread */
37863783
thread = rt_thread_self();
37873784
RT_OBJECT_HOOK_CALL(rt_object_trytake_hook, (&(mq->parent.parent)));
@@ -3826,7 +3823,7 @@ static rt_ssize_t _rt_mq_recv(rt_mq_t mq,
38263823
if (timeout > 0)
38273824
{
38283825
/* get the start tick of timer */
3829-
tick_delta = rt_tick_get();
3826+
tick_stamp = rt_tick_get();
38303827

38313828
LOG_D("set thread:%s to timer list",
38323829
thread->parent.name);
@@ -3855,8 +3852,7 @@ static rt_ssize_t _rt_mq_recv(rt_mq_t mq,
38553852
/* if it's not waiting forever and then re-calculate timeout tick */
38563853
if (timeout > 0)
38573854
{
3858-
tick_delta = rt_tick_get() - tick_delta;
3859-
timeout -= tick_delta;
3855+
timeout -= rt_tick_get_delta(tick_stamp);
38603856
if (timeout < 0)
38613857
timeout = 0;
38623858
}

src/mempool.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ void *rt_mp_alloc(rt_mp_t mp, rt_int32_t time)
335335

336336
if (time > 0)
337337
{
338-
time -= rt_tick_get() - before_sleep;
338+
time -= rt_tick_get_delta(before_sleep);
339339
if (time < 0)
340340
time = 0;
341341
}

0 commit comments

Comments
 (0)