From 618eb1c0168b709395df439da165c6eceb3b7a73 Mon Sep 17 00:00:00 2001 From: xieyangrun Date: Wed, 15 Jan 2020 09:14:58 +0800 Subject: fixed whitespace character --- src/components.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/components.c b/src/components.c index 362cf3203f..e7824b65ef 100644 --- a/src/components.c +++ b/src/components.c @@ -174,11 +174,11 @@ void main_thread_entry(void *parameter) { extern int main(void); extern int $Super$$main(void); - + #ifdef RT_USING_COMPONENTS_INIT /* RT-Thread components initialization */ rt_components_init(); -#endif +#endif #ifdef RT_USING_SMP rt_hw_secondary_cpu_up(); #endif -- cgit v1.3.1 From 3b87cb8ded4437316b74d220217c4440fdda249f Mon Sep 17 00:00:00 2001 From: xieyangrun Date: Wed, 15 Jan 2020 09:34:47 +0800 Subject: [src/timer.c]fixed rt_timer_list_next_timeout multi-task safe --- src/timer.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/timer.c b/src/timer.c index 3992cf6ff4..d85ee080b5 100644 --- a/src/timer.c +++ b/src/timer.c @@ -108,14 +108,23 @@ static void _rt_timer_init(rt_timer_t timer, static rt_tick_t rt_timer_list_next_timeout(rt_list_t timer_list[]) { struct rt_timer *timer; + register rt_base_t level; + rt_tick_t timeout_tick = RT_TICK_MAX; - if (rt_list_isempty(&timer_list[RT_TIMER_SKIP_LIST_LEVEL - 1])) - return RT_TICK_MAX; + /* disable interrupt */ + level = rt_hw_interrupt_disable(); - timer = rt_list_entry(timer_list[RT_TIMER_SKIP_LIST_LEVEL - 1].next, - struct rt_timer, row[RT_TIMER_SKIP_LIST_LEVEL - 1]); + if (!rt_list_isempty(&timer_list[RT_TIMER_SKIP_LIST_LEVEL - 1])) + { + timer = rt_list_entry(timer_list[RT_TIMER_SKIP_LIST_LEVEL - 1].next, + struct rt_timer, row[RT_TIMER_SKIP_LIST_LEVEL - 1]); + timeout_tick = timer->timeout_tick; + } + + /* enable interrupt */ + rt_hw_interrupt_enable(level); - return timer->timeout_tick; + return timeout_tick; } rt_inline void _rt_timer_remove(rt_timer_t timer) -- cgit v1.3.1 From a7c590773e1be14e163ca67260c8927024c985dd Mon Sep 17 00:00:00 2001 From: "朱天龙 (Armink)" Date: Fri, 7 Feb 2020 13:08:04 +0800 Subject: Update show version info. --- src/kservice.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/kservice.c b/src/kservice.c index 58f04330f1..0a8786e17a 100644 --- a/src/kservice.c +++ b/src/kservice.c @@ -538,7 +538,7 @@ void rt_show_version(void) rt_kprintf("- RT - Thread Operating System\n"); rt_kprintf(" / | \\ %d.%d.%d build %s\n", RT_VERSION, RT_SUBVERSION, RT_REVISION, __DATE__); - rt_kprintf(" 2006 - 2019 Copyright by rt-thread team\n"); + rt_kprintf(" 2006 - 2020 Copyright by rt-thread team\n"); } RTM_EXPORT(rt_show_version); -- cgit v1.3.1 From 720d8479a574746020747ef36bc33a8159206289 Mon Sep 17 00:00:00 2001 From: longtengmcu Date: Fri, 7 Feb 2020 16:43:39 +0800 Subject: 给软件定时器增加定时器工作状态查询的功能 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/rtdef.h | 1 + src/timer.c | 13 +++++++++++++ 2 files changed, 14 insertions(+) (limited to 'src') diff --git a/include/rtdef.h b/include/rtdef.h index c8184a5a4b..8b86213082 100644 --- a/include/rtdef.h +++ b/include/rtdef.h @@ -431,6 +431,7 @@ struct rt_object_information #define RT_TIMER_CTRL_GET_TIME 0x1 /**< get timer control command */ #define RT_TIMER_CTRL_SET_ONESHOT 0x2 /**< change timer to one shot */ #define RT_TIMER_CTRL_SET_PERIODIC 0x3 /**< change timer to periodic */ +#define RT_TIMER_CTRL_GET_STATE 0x4 /**< get timer run state active or deactive*/ #ifndef RT_TIMER_SKIP_LIST_LEVEL #define RT_TIMER_SKIP_LIST_LEVEL 1 diff --git a/src/timer.c b/src/timer.c index d85ee080b5..0034f0246c 100644 --- a/src/timer.c +++ b/src/timer.c @@ -488,6 +488,19 @@ rt_err_t rt_timer_control(rt_timer_t timer, int cmd, void *arg) case RT_TIMER_CTRL_SET_PERIODIC: timer->parent.flag |= RT_TIMER_FLAG_PERIODIC; break; + /* zhaoshimin 20191204 add query the timer state */ + case RT_TIMER_CTRL_GET_STATE: + if(timer->parent.flag & RT_TIMER_FLAG_ACTIVATED) + { + /*timer is start and run*/ + *(rt_tick_t *)arg = RT_TIMER_FLAG_ACTIVATED; + } + else + { + /*timer is stop*/ + *(rt_tick_t *)arg = RT_TIMER_FLAG_DEACTIVATED; + } + break; } return RT_EOK; -- cgit v1.3.1 From d6d690da1a4987df13268aaf91d1c05337afb5c4 Mon Sep 17 00:00:00 2001 From: suhui <3164683437@qq.com> Date: Fri, 21 Feb 2020 19:46:59 +0800 Subject: fix the comment Signed-off-by: suhui <3164683437@qq.com> --- src/thread.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/thread.c b/src/thread.c index 74a573b78f..19ab5549c8 100644 --- a/src/thread.c +++ b/src/thread.c @@ -590,7 +590,7 @@ RTM_EXPORT(rt_thread_delay_until); /** * This function will let current thread delay for some milliseconds. * - * @param tick the delay time + * @param ms the delay ms time * * @return RT_EOK */ -- cgit v1.3.1 From d0ebdc54d42f9985e2316f8db58b3e6c65582f66 Mon Sep 17 00:00:00 2001 From: lihui Date: Tue, 24 Mar 2020 18:59:31 +0800 Subject: fix return type error of rt_strcasecmp: rt_uint32_t to rt_int32_t Signed-off-by: lihui --- include/rtthread.h | 2 +- src/kservice.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/include/rtthread.h b/include/rtthread.h index 92cdf012b2..70d4f38896 100644 --- a/include/rtthread.h +++ b/include/rtthread.h @@ -554,7 +554,7 @@ rt_int32_t rt_sscanf(const char *buf, const char *fmt, ...); char *rt_strncpy(char *dest, const char *src, rt_ubase_t n); void *rt_memmove(void *dest, const void *src, rt_ubase_t n); rt_int32_t rt_memcmp(const void *cs, const void *ct, rt_ubase_t count); -rt_uint32_t rt_strcasecmp(const char *a, const char *b); +rt_int32_t rt_strcasecmp(const char *a, const char *b); void rt_show_version(void); diff --git a/src/kservice.c b/src/kservice.c index 0a8786e17a..1705ce5283 100644 --- a/src/kservice.c +++ b/src/kservice.c @@ -370,7 +370,7 @@ RTM_EXPORT(rt_strstr); * * @return the result */ -rt_uint32_t rt_strcasecmp(const char *a, const char *b) +rt_int32_t rt_strcasecmp(const char *a, const char *b) { int ca, cb; -- cgit v1.3.1 From b082876c9b06d8a883726e6ddec50c2b49b6c4da Mon Sep 17 00:00:00 2001 From: greed-island <62747314+greed-island@users.noreply.github.com> Date: Fri, 27 Mar 2020 18:57:29 +0800 Subject: Update mem.c rt_realloc may cause change, if we don't change timely, it may cause memory leakage --- src/mem.c | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'src') diff --git a/src/mem.c b/src/mem.c index 8099b6bb7e..c03c8b3452 100644 --- a/src/mem.c +++ b/src/mem.c @@ -489,6 +489,12 @@ void *rt_realloc(void *rmem, rt_size_t newsize) { ((struct heap_mem *)&heap_ptr[mem2->next])->prev = ptr2; } + + if (mem2 < lfree) + { + /* the splited struct is now the lowest */ + lfree = mem2; + } plug_holes(mem2); -- cgit v1.3.1 From 08c15f1b118e1c75f4adbbe983077cb034009fdd Mon Sep 17 00:00:00 2001 From: greed-island <62747314+greed-island@users.noreply.github.com> Date: Tue, 31 Mar 2020 23:54:41 +0800 Subject: Update ipc.c MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 程序的分支逻辑出错。 详见修改。 --- src/ipc.c | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'src') diff --git a/src/ipc.c b/src/ipc.c index e6955bae37..8e8c4db842 100644 --- a/src/ipc.c +++ b/src/ipc.c @@ -1186,6 +1186,11 @@ rt_err_t rt_event_recv(rt_event_t event, { /* no waiting */ thread->error = -RT_ETIMEOUT; + + /* enable interrupt */ + rt_hw_interrupt_enable(level); + + return -RT_ETIMEOUT; } else { -- cgit v1.3.1 From b1eb3943a3ab1e4b39574d01eb98480afabb29d1 Mon Sep 17 00:00:00 2001 From: Bernard Xiong Date: Fri, 10 Apr 2020 00:01:58 +0800 Subject: [Kernel] Add rt_object_get_length/rt_object_get_pointers APIs. --- include/rtthread.h | 3 ++ src/object.c | 87 +++++++++++++++++++++++++++++++++++++++++++++++------- 2 files changed, 79 insertions(+), 11 deletions(-) (limited to 'src') diff --git a/include/rtthread.h b/include/rtthread.h index 70d4f38896..a76601a3bf 100644 --- a/include/rtthread.h +++ b/include/rtthread.h @@ -41,6 +41,9 @@ extern "C" { void rt_system_object_init(void); struct rt_object_information * rt_object_get_information(enum rt_object_class_type type); +int rt_object_get_length(enum rt_object_class_type type); +int rt_object_get_pointers(enum rt_object_class_type type, rt_object_t *pointers, int maxlen); + void rt_object_init(struct rt_object *object, enum rt_object_class_type type, const char *name); diff --git a/src/object.c b/src/object.c index 4ee2f6a1a1..62d70816dc 100644 --- a/src/object.c +++ b/src/object.c @@ -212,7 +212,9 @@ void rt_system_object_init(void) /** * This function will return the specified type of object information. * - * @param type the type of object + * @param type the type of object, which can be + * RT_Object_Class_Thread/Semaphore/Mutex... etc + * * @return the object type information or RT_NULL */ struct rt_object_information * @@ -227,6 +229,75 @@ rt_object_get_information(enum rt_object_class_type type) } RTM_EXPORT(rt_object_get_information); +/** + * This function will return the length of object list in object container. + * + * @param type the type of object, which can be + * RT_Object_Class_Thread/Semaphore/Mutex... etc + * @return the length of object list + */ +int rt_object_get_length(enum rt_object_class_type type) +{ + int count = 0; + rt_ubase_t level; + struct rt_list_node *node = RT_NULL; + struct rt_object_information *information = RT_NULL; + + information = rt_object_get_information((enum rt_object_class_type)type); + if (information == RT_NULL) return 0; + + level = rt_hw_interrupt_disable(); + /* get the count of objects */ + rt_list_for_each(node, &(information->object_list)) + { + count ++; + } + rt_hw_interrupt_enable(level); + + return count; +} +RTM_EXPORT(rt_object_get_length); + +/** + * This function will copy the object pointer of the specified type, + * with the maximum size specified by maxlen. + * + * @param type the type of object, which can be + * RT_Object_Class_Thread/Semaphore/Mutex... etc + * @param pointers the pointers will be saved to + * @param maxlen the maximum number of pointers can be saved + * + * @return the copied number of object pointers + */ +int rt_object_get_pointers(enum rt_object_class_type type, rt_object_t *pointers, int maxlen) +{ + int index = 0; + rt_ubase_t level; + + struct rt_object *object; + struct rt_list_node *node = RT_NULL; + struct rt_object_information *information = RT_NULL; + + if (maxlen <= 0) return 0; + + information = rt_object_get_information((enum rt_object_class_type)type); + if (information == RT_NULL) return 0; + + level = rt_hw_interrupt_disable(); + /* retrieve pointer of object */ + rt_list_for_each(node, &(information->object_list)) + { + object = rt_list_entry(node, struct rt_object, list); + + pointers[index] = object; + index ++; + } + rt_hw_interrupt_enable(level); + + return index; +} +RTM_EXPORT(rt_object_get_pointers); + /** * This function will initialize an object and add it to object system * management. @@ -482,9 +553,10 @@ rt_object_t rt_object_find(const char *name, rt_uint8_t type) struct rt_list_node *node = RT_NULL; struct rt_object_information *information = RT_NULL; + information = rt_object_get_information((enum rt_object_class_type)type); + /* parameter check */ - if ((name == RT_NULL) || (type > RT_Object_Class_Unknown)) - return RT_NULL; + if ((name == RT_NULL) || (information == RT_NULL)) return RT_NULL; /* which is invoke in interrupt status */ RT_DEBUG_NOT_IN_INTERRUPT; @@ -493,14 +565,7 @@ rt_object_t rt_object_find(const char *name, rt_uint8_t type) rt_enter_critical(); /* try to find object */ - if (information == RT_NULL) - { - information = rt_object_get_information((enum rt_object_class_type)type); - RT_ASSERT(information != RT_NULL); - } - for (node = information->object_list.next; - node != &(information->object_list); - node = node->next) + rt_list_for_each(node, &(information->object_list)) { object = rt_list_entry(node, struct rt_object, list); if (rt_strncmp(object->name, name, RT_NAME_MAX) == 0) -- cgit v1.3.1 From e0bc6b86ea2588ab4b6b7c1fd1c9386a3a86c080 Mon Sep 17 00:00:00 2001 From: Bernard Xiong Date: Fri, 10 Apr 2020 00:02:24 +0800 Subject: [kernel] Remove named comments. --- src/timer.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/timer.c b/src/timer.c index 0034f0246c..28a5a9e494 100644 --- a/src/timer.c +++ b/src/timer.c @@ -488,7 +488,7 @@ rt_err_t rt_timer_control(rt_timer_t timer, int cmd, void *arg) case RT_TIMER_CTRL_SET_PERIODIC: timer->parent.flag |= RT_TIMER_FLAG_PERIODIC; break; - /* zhaoshimin 20191204 add query the timer state */ + case RT_TIMER_CTRL_GET_STATE: if(timer->parent.flag & RT_TIMER_FLAG_ACTIVATED) { -- cgit v1.3.1 From 240961e8e88a3b3fb6624dcd89599511149f7e5c Mon Sep 17 00:00:00 2001 From: Cliff Chen Date: Fri, 15 May 2020 18:15:43 +0800 Subject: [Kernel] Fix double release for thread Signed-off-by: Cliff Chen --- src/thread.c | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'src') diff --git a/src/thread.c b/src/thread.c index 19ab5549c8..2b2fb1922c 100644 --- a/src/thread.c +++ b/src/thread.c @@ -338,6 +338,9 @@ rt_err_t rt_thread_detach(rt_thread_t thread) RT_ASSERT(rt_object_get_type((rt_object_t)thread) == RT_Object_Class_Thread); RT_ASSERT(rt_object_is_systemobject((rt_object_t)thread)); + if (thread->stat == RT_THREAD_CLOSE) + return RT_EOK; + if ((thread->stat & RT_THREAD_STAT_MASK) != RT_THREAD_INIT) { /* remove from schedule */ @@ -437,6 +440,9 @@ rt_err_t rt_thread_delete(rt_thread_t thread) RT_ASSERT(rt_object_get_type((rt_object_t)thread) == RT_Object_Class_Thread); RT_ASSERT(rt_object_is_systemobject((rt_object_t)thread) == RT_FALSE); + if (thread->stat == RT_THREAD_CLOSE) + return RT_EOK; + if ((thread->stat & RT_THREAD_STAT_MASK) != RT_THREAD_INIT) { /* remove from schedule */ -- cgit v1.3.1 From b98690e2110a9ddf083004340b5170715c84996e Mon Sep 17 00:00:00 2001 From: Bernard Xiong Date: Sun, 17 May 2020 23:14:24 +0800 Subject: [Kernel] Fix the maxlen issue in rt_object_get_pointers --- src/object.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src') diff --git a/src/object.c b/src/object.c index 62d70816dc..6866d805ca 100644 --- a/src/object.c +++ b/src/object.c @@ -291,6 +291,8 @@ int rt_object_get_pointers(enum rt_object_class_type type, rt_object_t *pointers pointers[index] = object; index ++; + + if (index >= maxlen) break; } rt_hw_interrupt_enable(level); -- cgit v1.3.1 From 7471a665db9f5a474a066cd0f59132dac656c7e7 Mon Sep 17 00:00:00 2001 From: cliff-cmc <62226047+cliff-cmc@users.noreply.github.com> Date: Mon, 25 May 2020 08:43:13 +0800 Subject: Update thread.c --- src/thread.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/thread.c b/src/thread.c index 2b2fb1922c..715596b132 100644 --- a/src/thread.c +++ b/src/thread.c @@ -338,7 +338,7 @@ rt_err_t rt_thread_detach(rt_thread_t thread) RT_ASSERT(rt_object_get_type((rt_object_t)thread) == RT_Object_Class_Thread); RT_ASSERT(rt_object_is_systemobject((rt_object_t)thread)); - if (thread->stat == RT_THREAD_CLOSE) + if ((thread->stat & RT_THREAD_STAT_MASK) == RT_THREAD_CLOSE) return RT_EOK; if ((thread->stat & RT_THREAD_STAT_MASK) != RT_THREAD_INIT) @@ -440,7 +440,7 @@ rt_err_t rt_thread_delete(rt_thread_t thread) RT_ASSERT(rt_object_get_type((rt_object_t)thread) == RT_Object_Class_Thread); RT_ASSERT(rt_object_is_systemobject((rt_object_t)thread) == RT_FALSE); - if (thread->stat == RT_THREAD_CLOSE) + if ((thread->stat & RT_THREAD_STAT_MASK) == RT_THREAD_CLOSE) return RT_EOK; if ((thread->stat & RT_THREAD_STAT_MASK) != RT_THREAD_INIT) -- cgit v1.3.1 From 160811b77a26ff6324adc46fbfdec38901f68adc Mon Sep 17 00:00:00 2001 From: David Lin Date: Thu, 23 Jul 2020 19:35:31 +0800 Subject: Minor optimization for mempool.c 1. Improve code readability, unify the variable name in functions "rt_hw_interrupt_enable(level);" and "rt_hw_interrupt_enable(level);", so changed variable "temp" to "level"; --- src/mempool.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/mempool.c b/src/mempool.c index 00471efb35..db614032aa 100644 --- a/src/mempool.c +++ b/src/mempool.c @@ -134,7 +134,7 @@ RTM_EXPORT(rt_mp_init); rt_err_t rt_mp_detach(struct rt_mempool *mp) { struct rt_thread *thread; - register rt_ubase_t temp; + register rt_ubase_t level; /* parameter check */ RT_ASSERT(mp != RT_NULL); @@ -145,7 +145,7 @@ rt_err_t rt_mp_detach(struct rt_mempool *mp) while (!rt_list_isempty(&(mp->suspend_thread))) { /* disable interrupt */ - temp = rt_hw_interrupt_disable(); + level = rt_hw_interrupt_disable(); /* get next suspend thread */ thread = rt_list_entry(mp->suspend_thread.next, struct rt_thread, tlist); @@ -160,7 +160,7 @@ rt_err_t rt_mp_detach(struct rt_mempool *mp) rt_thread_resume(thread); /* enable interrupt */ - rt_hw_interrupt_enable(temp); + rt_hw_interrupt_enable(level); } /* detach object */ @@ -250,7 +250,7 @@ RTM_EXPORT(rt_mp_create); rt_err_t rt_mp_delete(rt_mp_t mp) { struct rt_thread *thread; - register rt_ubase_t temp; + register rt_ubase_t level; RT_DEBUG_NOT_IN_INTERRUPT; @@ -263,7 +263,7 @@ rt_err_t rt_mp_delete(rt_mp_t mp) while (!rt_list_isempty(&(mp->suspend_thread))) { /* disable interrupt */ - temp = rt_hw_interrupt_disable(); + level = rt_hw_interrupt_disable(); /* get next suspend thread */ thread = rt_list_entry(mp->suspend_thread.next, struct rt_thread, tlist); @@ -278,7 +278,7 @@ rt_err_t rt_mp_delete(rt_mp_t mp) rt_thread_resume(thread); /* enable interrupt */ - rt_hw_interrupt_enable(temp); + rt_hw_interrupt_enable(level); } /* release allocated room */ -- cgit v1.3.1 From 3ed84b8d03dc9778f1c262278e2b8653de834408 Mon Sep 17 00:00:00 2001 From: shaojinchun Date: Fri, 24 Jul 2020 21:13:56 +0800 Subject: 解决yield操作不能及时释放cpu的问题 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/clock.c | 3 +-- src/scheduler.c | 6 +++--- src/thread.c | 8 ++++++++ 3 files changed, 12 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/clock.c b/src/clock.c index 97a09ddeaf..a91cd829b6 100644 --- a/src/clock.c +++ b/src/clock.c @@ -91,8 +91,7 @@ void rt_tick_increase(void) thread->stat |= RT_THREAD_STAT_YIELD; - /* yield */ - rt_thread_yield(); + rt_schedule(); } /* check timer */ diff --git a/src/scheduler.c b/src/scheduler.c index 6baaa9627a..d0859e745a 100644 --- a/src/scheduler.c +++ b/src/scheduler.c @@ -350,9 +350,9 @@ void rt_schedule(void) } else { - current_thread->stat &= ~RT_THREAD_STAT_YIELD_MASK; rt_schedule_insert_thread(current_thread); } + current_thread->stat &= ~RT_THREAD_STAT_YIELD_MASK; } to_thread->oncpu = cpu_id; if (to_thread != current_thread) @@ -448,9 +448,9 @@ void rt_schedule(void) } else { - rt_current_thread->stat &= ~RT_THREAD_STAT_YIELD_MASK; need_insert_from_thread = 1; } + rt_current_thread->stat &= ~RT_THREAD_STAT_YIELD_MASK; } if (to_thread != rt_current_thread) @@ -599,9 +599,9 @@ void rt_scheduler_do_irq_switch(void *context) } else { - current_thread->stat &= ~RT_THREAD_STAT_YIELD_MASK; rt_schedule_insert_thread(current_thread); } + current_thread->stat &= ~RT_THREAD_STAT_YIELD_MASK; } to_thread->oncpu = cpu_id; if (to_thread != current_thread) diff --git a/src/thread.c b/src/thread.c index 715596b132..60aa17f381 100644 --- a/src/thread.c +++ b/src/thread.c @@ -478,7 +478,15 @@ RTM_EXPORT(rt_thread_delete); */ rt_err_t rt_thread_yield(void) { + struct rt_thread *thread; + rt_base_t lock; + + thread = rt_thread_self(); + lock = rt_hw_interrupt_disable(); + thread->remaining_tick = thread->init_tick; + thread->stat |= RT_THREAD_STAT_YIELD; rt_schedule(); + rt_hw_interrupt_enable(lock); return RT_EOK; } -- cgit v1.3.1 From b328c1cbac55d6ed9ab4708611e20961a28f27f1 Mon Sep 17 00:00:00 2001 From: chenchaoqun Date: Mon, 27 Jul 2020 11:36:57 +0800 Subject: [modify] if ... else if constructs to be terminated with an else clause, which other option is invalid and delete surplus space. --- src/ipc.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/ipc.c b/src/ipc.c index 8e8c4db842..876d8df3a1 100644 --- a/src/ipc.c +++ b/src/ipc.c @@ -1080,6 +1080,13 @@ rt_err_t rt_event_send(rt_event_t event, rt_uint32_t set) status = RT_EOK; } } + else + { + /* enable interrupt */ + rt_hw_interrupt_enable(level); + + return -RT_EINVAL; + } /* move node to the next */ n = n->next; @@ -1186,10 +1193,10 @@ rt_err_t rt_event_recv(rt_event_t event, { /* no waiting */ thread->error = -RT_ETIMEOUT; - + /* enable interrupt */ rt_hw_interrupt_enable(level); - + return -RT_ETIMEOUT; } else -- cgit v1.3.1 From 55cfefd90a58e7e0d33e13714f21fb75a9718010 Mon Sep 17 00:00:00 2001 From: chenchaoqun Date: Mon, 27 Jul 2020 11:49:52 +0800 Subject: [add] switch default clause --- src/ipc.c | 3 +++ src/timer.c | 5 ++++- 2 files changed, 7 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/ipc.c b/src/ipc.c index 8e8c4db842..dd681f2892 100644 --- a/src/ipc.c +++ b/src/ipc.c @@ -117,6 +117,9 @@ rt_inline rt_err_t rt_ipc_list_suspend(rt_list_t *list, rt_list_insert_before(list, &(thread->tlist)); } break; + + default: + break; } return RT_EOK; diff --git a/src/timer.c b/src/timer.c index 28a5a9e494..4d12c7ec78 100644 --- a/src/timer.c +++ b/src/timer.c @@ -500,7 +500,10 @@ rt_err_t rt_timer_control(rt_timer_t timer, int cmd, void *arg) /*timer is stop*/ *(rt_tick_t *)arg = RT_TIMER_FLAG_DEACTIVATED; } - break; + break; + + default: + break; } return RT_EOK; -- cgit v1.3.1 From a78c6bedea2bb4e9833fdb2cc22f3af813724609 Mon Sep 17 00:00:00 2001 From: chenchaoqun Date: Mon, 27 Jul 2020 14:01:30 +0800 Subject: [add] a macro to be isolated while using signals in rt_mutex_take function. --- src/ipc.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src') diff --git a/src/ipc.c b/src/ipc.c index 8e8c4db842..b0efdd1320 100644 --- a/src/ipc.c +++ b/src/ipc.c @@ -685,7 +685,9 @@ rt_err_t rt_mutex_take(rt_mutex_t mutex, rt_int32_t time) } else { +#ifdef RT_USING_SIGNALS __again: +#endif /* end of RT_USING_SIGNALS */ /* The value of mutex is 1 in initial status. Therefore, if the * value is great than 0, it indicates the mutex is avaible. */ @@ -754,8 +756,10 @@ __again: if (thread->error != RT_EOK) { +#ifdef RT_USING_SIGNALS /* interrupt by signal, try it again */ if (thread->error == -RT_EINTR) goto __again; +#endif /* end of RT_USING_SIGNALS */ /* return error */ return thread->error; -- cgit v1.3.1 From 9f41cbced8058faf40b54353b1d9d981650b1b3e Mon Sep 17 00:00:00 2001 From: chenchaoqun Date: Mon, 27 Jul 2020 14:18:16 +0800 Subject: [format] code style of rt_strcmp function --- src/kservice.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/kservice.c b/src/kservice.c index 1705ce5283..dd7458f106 100644 --- a/src/kservice.c +++ b/src/kservice.c @@ -456,7 +456,10 @@ RTM_EXPORT(rt_strncmp); rt_int32_t rt_strcmp(const char *cs, const char *ct) { while (*cs && *cs == *ct) - cs++, ct++; + { + cs++; + ct++; + } return (*cs - *ct); } -- cgit v1.3.1 From 984e8e5651d98be190c4607b087ca6907026e96a Mon Sep 17 00:00:00 2001 From: chenchaoqun Date: Fri, 24 Jul 2020 11:53:57 +0800 Subject: [modify] internal function 'isdigit' name to '_ISDIGIT' --- src/kservice.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/kservice.c b/src/kservice.c index 1705ce5283..cf03fb59b1 100644 --- a/src/kservice.c +++ b/src/kservice.c @@ -543,7 +543,7 @@ void rt_show_version(void) RTM_EXPORT(rt_show_version); /* private function */ -#define isdigit(c) ((unsigned)((c) - '0') < 10) +#define _ISDIGIT(c) ((unsigned)((c) - '0') < 10) #ifdef RT_PRINTF_LONGLONG rt_inline int divide(long long *n, int base) @@ -588,7 +588,7 @@ rt_inline int divide(long *n, int base) rt_inline int skip_atoi(const char **s) { register int i = 0; - while (isdigit(**s)) + while (_ISDIGIT(**s)) i = i * 10 + *((*s)++) - '0'; return i; @@ -834,7 +834,7 @@ rt_int32_t rt_vsnprintf(char *buf, /* get field width */ field_width = -1; - if (isdigit(*fmt)) field_width = skip_atoi(&fmt); + if (_ISDIGIT(*fmt)) field_width = skip_atoi(&fmt); else if (*fmt == '*') { ++ fmt; @@ -853,7 +853,7 @@ rt_int32_t rt_vsnprintf(char *buf, if (*fmt == '.') { ++ fmt; - if (isdigit(*fmt)) precision = skip_atoi(&fmt); + if (_ISDIGIT(*fmt)) precision = skip_atoi(&fmt); else if (*fmt == '*') { ++ fmt; -- cgit v1.3.1 From 0e619491163d2e2b4c1cc262f0faee3b1ced55b7 Mon Sep 17 00:00:00 2001 From: shaojinchun Date: Tue, 28 Jul 2020 09:55:01 +0800 Subject: avoid deadlock (rt_hw_interrupt_disable and rt_enter_critical when enable smp) --- src/scheduler.c | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) (limited to 'src') diff --git a/src/scheduler.c b/src/scheduler.c index 6baaa9627a..0c1bf1e506 100644 --- a/src/scheduler.c +++ b/src/scheduler.c @@ -33,10 +33,6 @@ #include #include -#ifdef RT_USING_SMP -rt_hw_spinlock_t _rt_critical_lock; -#endif /*RT_USING_SMP*/ - rt_list_t rt_thread_priority_table[RT_THREAD_PRIORITY_MAX]; rt_uint32_t rt_thread_ready_priority_group; #if RT_THREAD_PRIORITY_MAX > 32 @@ -851,7 +847,7 @@ void rt_enter_critical(void) if (!current_thread) { rt_hw_local_irq_enable(level); - return ; + return; } /* @@ -859,12 +855,15 @@ void rt_enter_critical(void) * enough and does not check here */ - /* lock scheduler for all cpus */ - if (current_thread->critical_lock_nest == 0) { - rt_hw_spin_lock(&_rt_critical_lock); + register rt_uint16_t lock_nest = current_thread->cpus_lock_nest; + current_thread->cpus_lock_nest++; + if (lock_nest == 0) + { + current_thread->scheduler_lock_nest ++; + rt_hw_spin_lock(&_cpus_lock); + } } - /* critical for local cpu */ current_thread->critical_lock_nest ++; @@ -910,16 +909,18 @@ void rt_exit_critical(void) if (!current_thread) { rt_hw_local_irq_enable(level); - return ; + return; } current_thread->scheduler_lock_nest --; current_thread->critical_lock_nest --; - if (current_thread->critical_lock_nest == 0) + current_thread->cpus_lock_nest--; + if (current_thread->cpus_lock_nest == 0) { - rt_hw_spin_unlock(&_rt_critical_lock); + current_thread->scheduler_lock_nest --; + rt_hw_spin_unlock(&_cpus_lock); } if (current_thread->scheduler_lock_nest <= 0) -- cgit v1.3.1 From 1fe077a0be8636a3aeb39b897373f493da06f9c6 Mon Sep 17 00:00:00 2001 From: Meco <920369182@qq.com> Date: Wed, 29 Jul 2020 09:57:32 +0800 Subject: fix在rt_event_recv函数中,如果事件已经满足无需阻塞的情况下,没有给thread->event_set/event_info赋值的问题 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/ipc.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/ipc.c b/src/ipc.c index 8e8c4db842..c67909cfe0 100644 --- a/src/ipc.c +++ b/src/ipc.c @@ -34,6 +34,8 @@ * 2013-09-14 Grissiom add an option check in rt_event_recv * 2018-10-02 Bernard add 64bit support for mailbox * 2019-09-16 tyx add send wait support for message queue + * 2020-07-29 Meco Man fix thread->event_set/event_info when received an + event without pending */ #include @@ -1177,7 +1179,11 @@ rt_err_t rt_event_recv(rt_event_t event, /* set received event */ if (recved) *recved = (event->set & set); - + + /* fill thread event info */ + thread->event_set = (event->set & set); + thread->event_info = option; + /* received event */ if (option & RT_EVENT_FLAG_CLEAR) event->set &= ~set; -- cgit v1.3.1 From 76d1651a7463eb4bdf1215bd28dd289647fd11eb Mon Sep 17 00:00:00 2001 From: xieyangrun Date: Sat, 15 Aug 2020 20:15:29 +0800 Subject: fixed the iterator failure for softtimer list timeout check. --- src/timer.c | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) (limited to 'src') diff --git a/src/timer.c b/src/timer.c index 4d12c7ec78..52707f2306 100644 --- a/src/timer.c +++ b/src/timer.c @@ -595,20 +595,19 @@ rt_tick_t rt_timer_next_timeout_tick(void) void rt_soft_timer_check(void) { rt_tick_t current_tick; - rt_list_t *n; struct rt_timer *t; RT_DEBUG_LOG(RT_DEBUG_TIMER, ("software timer check enter\n")); - current_tick = rt_tick_get(); - /* lock scheduler */ rt_enter_critical(); - for (n = rt_soft_timer_list[RT_TIMER_SKIP_LIST_LEVEL - 1].next; - n != &(rt_soft_timer_list[RT_TIMER_SKIP_LIST_LEVEL - 1]);) + while (!rt_list_isempty(&rt_soft_timer_list[RT_TIMER_SKIP_LIST_LEVEL - 1])) { - t = rt_list_entry(n, struct rt_timer, row[RT_TIMER_SKIP_LIST_LEVEL - 1]); + t = rt_list_entry(rt_soft_timer_list[RT_TIMER_SKIP_LIST_LEVEL - 1].next, + struct rt_timer, row[RT_TIMER_SKIP_LIST_LEVEL - 1]); + + current_tick = rt_tick_get(); /* * It supposes that the new tick shall less than the half duration of @@ -618,9 +617,6 @@ void rt_soft_timer_check(void) { RT_OBJECT_HOOK_CALL(rt_timer_enter_hook, (t)); - /* move node to the next */ - n = n->next; - /* remove timer from timer list firstly */ _rt_timer_remove(t); @@ -629,9 +625,6 @@ void rt_soft_timer_check(void) /* call timeout function */ t->timeout_func(t->parameter); - /* re-get tick */ - current_tick = rt_tick_get(); - RT_OBJECT_HOOK_CALL(rt_timer_exit_hook, (t)); RT_DEBUG_LOG(RT_DEBUG_TIMER, ("current tick: %d\n", current_tick)); -- cgit v1.3.1 From c15a7858c9a7bc1f978faa5f0ea3f618fbd3bc03 Mon Sep 17 00:00:00 2001 From: chenchaoqun Date: Fri, 14 Aug 2020 15:52:35 +0800 Subject: [fix] thread control bug about RT_THREAD_CTRL_CLOSE command --- src/thread.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/thread.c b/src/thread.c index 715596b132..9f80482b20 100644 --- a/src/thread.c +++ b/src/thread.c @@ -679,9 +679,17 @@ rt_err_t rt_thread_control(rt_thread_t thread, int cmd, void *arg) case RT_THREAD_CTRL_STARTUP: return rt_thread_startup(thread); -#ifdef RT_USING_HEAP case RT_THREAD_CTRL_CLOSE: - return rt_thread_delete(thread); + + if (rt_object_is_systemobject((rt_object_t)thread) == RT_TRUE) + { + return rt_thread_detach(thread); + } +#ifdef RT_USING_HEAP + else + { + return rt_thread_delete(thread); + } #endif #ifdef RT_USING_SMP -- cgit v1.3.1 From 731e64f0c5e451f9408ad94da5de64f74bf4639b Mon Sep 17 00:00:00 2001 From: shaojinchun Date: Fri, 4 Sep 2020 12:12:01 +0800 Subject: 修正多核rt_schedule_remove_thread时pcpu的ready_table判断问题 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/scheduler.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/scheduler.c b/src/scheduler.c index 0c1bf1e506..699c817270 100644 --- a/src/scheduler.c +++ b/src/scheduler.c @@ -784,7 +784,7 @@ void rt_schedule_remove_thread(struct rt_thread *thread) { #if RT_THREAD_PRIORITY_MAX > 32 pcpu->ready_table[thread->number] &= ~thread->high_mask; - if (rt_thread_ready_table[thread->number] == 0) + if (pcpu->ready_table[thread->number] == 0) { pcpu->priority_group &= ~thread->number_mask; } -- cgit v1.3.1 From 1c6700acfdc6df71e14361d1c586ca32bb731e44 Mon Sep 17 00:00:00 2001 From: Bernard Xiong Date: Wed, 30 Sep 2020 23:50:18 +0800 Subject: [kernel] fix the timer issue --- src/timer.c | 85 +++++++++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 58 insertions(+), 27 deletions(-) (limited to 'src') diff --git a/src/timer.c b/src/timer.c index 52707f2306..4b9003794c 100644 --- a/src/timer.c +++ b/src/timer.c @@ -25,6 +25,10 @@ static rt_list_t rt_timer_list[RT_TIMER_SKIP_LIST_LEVEL]; #ifdef RT_USING_TIMER_SOFT + +#define RT_SOFT_TIMER_IDLE 1 +#define RT_SOFT_TIMER_BUSY 0 + #ifndef RT_TIMER_THREAD_STACK_SIZE #define RT_TIMER_THREAD_STACK_SIZE 512 #endif @@ -33,6 +37,8 @@ static rt_list_t rt_timer_list[RT_TIMER_SKIP_LIST_LEVEL]; #define RT_TIMER_THREAD_PRIO 0 #endif +/* soft timer status */ +static rt_uint8_t soft_timer_status = RT_SOFT_TIMER_IDLE; /* soft timer list */ static rt_list_t rt_soft_timer_list[RT_TIMER_SKIP_LIST_LEVEL]; static struct rt_thread timer_thread; @@ -221,6 +227,8 @@ rt_err_t rt_timer_detach(rt_timer_t timer) level = rt_hw_interrupt_disable(); _rt_timer_remove(timer); + /* stop timer */ + timer->parent.flag &= ~RT_TIMER_FLAG_ACTIVATED; /* enable interrupt */ rt_hw_interrupt_enable(level); @@ -284,6 +292,8 @@ rt_err_t rt_timer_delete(rt_timer_t timer) level = rt_hw_interrupt_disable(); _rt_timer_remove(timer); + /* stop timer */ + timer->parent.flag &= ~RT_TIMER_FLAG_ACTIVATED; /* enable interrupt */ rt_hw_interrupt_enable(level); @@ -408,7 +418,8 @@ rt_err_t rt_timer_start(rt_timer_t timer) if (timer->parent.flag & RT_TIMER_FLAG_SOFT_TIMER) { /* check whether timer thread is ready */ - if ((timer_thread.stat & RT_THREAD_STAT_MASK) == RT_THREAD_SUSPEND) + if ((soft_timer_status == RT_SOFT_TIMER_IDLE) && + ((timer_thread.stat & RT_THREAD_STAT_MASK) == RT_THREAD_SUSPEND)) { /* resume timer thread to check soft timer */ rt_thread_resume(&timer_thread); @@ -445,13 +456,12 @@ rt_err_t rt_timer_stop(rt_timer_t timer) level = rt_hw_interrupt_disable(); _rt_timer_remove(timer); + /* change status */ + timer->parent.flag &= ~RT_TIMER_FLAG_ACTIVATED; /* enable interrupt */ rt_hw_interrupt_enable(level); - /* change stat */ - timer->parent.flag &= ~RT_TIMER_FLAG_ACTIVATED; - return RT_EOK; } RTM_EXPORT(rt_timer_stop); @@ -467,10 +477,13 @@ RTM_EXPORT(rt_timer_stop); */ rt_err_t rt_timer_control(rt_timer_t timer, int cmd, void *arg) { + register rt_base_t level; + /* timer check */ RT_ASSERT(timer != RT_NULL); RT_ASSERT(rt_object_get_type(&timer->parent) == RT_Object_Class_Timer); + level = rt_hw_interrupt_disable(); switch (cmd) { case RT_TIMER_CTRL_GET_TIME: @@ -505,6 +518,7 @@ rt_err_t rt_timer_control(rt_timer_t timer, int cmd, void *arg) default: break; } + rt_hw_interrupt_enable(level); return RT_EOK; } @@ -521,6 +535,7 @@ void rt_timer_check(void) struct rt_timer *t; rt_tick_t current_tick; register rt_base_t level; + rt_list_t list = RT_LIST_OBJECT_INIT(list); RT_DEBUG_LOG(RT_DEBUG_TIMER, ("timer check enter\n")); @@ -544,7 +559,12 @@ void rt_timer_check(void) /* remove timer from timer list firstly */ _rt_timer_remove(t); - + if (!(t->parent.flag & RT_TIMER_FLAG_PERIODIC)) + { + t->parent.flag &= ~RT_TIMER_FLAG_ACTIVATED; + } + /* add timer to temporary list */ + rt_list_insert_after(&list, &(t->row[RT_TIMER_SKIP_LIST_LEVEL - 1])); /* call timeout function */ t->timeout_func(t->parameter); @@ -554,6 +574,12 @@ void rt_timer_check(void) RT_OBJECT_HOOK_CALL(rt_timer_exit_hook, (t)); RT_DEBUG_LOG(RT_DEBUG_TIMER, ("current tick: %d\n", current_tick)); + /* Check whether the timer object is detached or started again */ + if (rt_list_isempty(&list)) + { + continue; + } + if ((t->parent.flag & RT_TIMER_FLAG_PERIODIC) && (t->parent.flag & RT_TIMER_FLAG_ACTIVATED)) { @@ -561,14 +587,8 @@ void rt_timer_check(void) t->parent.flag &= ~RT_TIMER_FLAG_ACTIVATED; rt_timer_start(t); } - else - { - /* stop timer */ - t->parent.flag &= ~RT_TIMER_FLAG_ACTIVATED; - } } - else - break; + else break; } /* enable interrupt */ @@ -589,18 +609,20 @@ rt_tick_t rt_timer_next_timeout_tick(void) #ifdef RT_USING_TIMER_SOFT /** - * This function will check timer list, if a timeout event happens, the + * This function will check software-timer list, if a timeout event happens, the * corresponding timeout function will be invoked. */ void rt_soft_timer_check(void) { rt_tick_t current_tick; struct rt_timer *t; + register rt_base_t level; + rt_list_t list = RT_LIST_OBJECT_INIT(list); RT_DEBUG_LOG(RT_DEBUG_TIMER, ("software timer check enter\n")); - /* lock scheduler */ - rt_enter_critical(); + /* disable interrupt */ + level = rt_hw_interrupt_disable(); while (!rt_list_isempty(&rt_soft_timer_list[RT_TIMER_SKIP_LIST_LEVEL - 1])) { @@ -619,17 +641,32 @@ void rt_soft_timer_check(void) /* remove timer from timer list firstly */ _rt_timer_remove(t); + if (!(t->parent.flag & RT_TIMER_FLAG_PERIODIC)) + { + t->parent.flag &= ~RT_TIMER_FLAG_ACTIVATED; + } + /* add timer to temporary list */ + rt_list_insert_after(&list, &(t->row[RT_TIMER_SKIP_LIST_LEVEL - 1])); + + soft_timer_status = RT_SOFT_TIMER_BUSY; + /* enable interrupt */ + rt_hw_interrupt_enable(level); - /* not lock scheduler when performing timeout function */ - rt_exit_critical(); /* call timeout function */ t->timeout_func(t->parameter); RT_OBJECT_HOOK_CALL(rt_timer_exit_hook, (t)); RT_DEBUG_LOG(RT_DEBUG_TIMER, ("current tick: %d\n", current_tick)); - /* lock scheduler */ - rt_enter_critical(); + /* disable interrupt */ + level = rt_hw_interrupt_disable(); + + soft_timer_status = RT_SOFT_TIMER_IDLE; + /* Check whether the timer object is detached or started again */ + if (rt_list_isempty(&list)) + { + continue; + } if ((t->parent.flag & RT_TIMER_FLAG_PERIODIC) && (t->parent.flag & RT_TIMER_FLAG_ACTIVATED)) @@ -638,17 +675,11 @@ void rt_soft_timer_check(void) t->parent.flag &= ~RT_TIMER_FLAG_ACTIVATED; rt_timer_start(t); } - else - { - /* stop timer */ - t->parent.flag &= ~RT_TIMER_FLAG_ACTIVATED; - } } else break; /* not check anymore */ } - - /* unlock scheduler */ - rt_exit_critical(); + /* enable interrupt */ + rt_hw_interrupt_enable(level); RT_DEBUG_LOG(RT_DEBUG_TIMER, ("software timer check leave\n")); } -- cgit v1.3.1 From 2469335e213d6f2875d0b61575ceebd1f2a26509 Mon Sep 17 00:00:00 2001 From: mysterywolf <920369182@qq.com> Date: Sun, 11 Oct 2020 17:54:39 +0800 Subject: [fix bug] #3951 --- src/ipc.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/ipc.c b/src/ipc.c index 5646fc7f40..dc347119ae 100644 --- a/src/ipc.c +++ b/src/ipc.c @@ -35,7 +35,9 @@ * 2018-10-02 Bernard add 64bit support for mailbox * 2019-09-16 tyx add send wait support for message queue * 2020-07-29 Meco Man fix thread->event_set/event_info when received an - event without pending + * event without pending + * 2020-10-11 Meco Man add semaphore values' overflow-check code + * in the function of rt_sem_release */ #include @@ -463,7 +465,17 @@ rt_err_t rt_sem_release(rt_sem_t sem) need_schedule = RT_TRUE; } else - sem->value ++; /* increase value */ + { + if(sem->value < 65535u) + { + sem->value ++; /* increase value */ + } + else + { + rt_hw_interrupt_enable(temp); /* enable interrupt */ + return -RT_EFULL; /* value overflowed */ + } + } /* enable interrupt */ rt_hw_interrupt_enable(temp); -- cgit v1.3.1 From b93b4942390dbcf0834f762145c7784d6b32075c Mon Sep 17 00:00:00 2001 From: mysterywolf <920369182@qq.com> Date: Wed, 21 Oct 2020 17:15:43 +0800 Subject: [bug fixed] add mutex values' overflow-check code --- src/ipc.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/ipc.c b/src/ipc.c index dc347119ae..129d3eea44 100644 --- a/src/ipc.c +++ b/src/ipc.c @@ -37,7 +37,7 @@ * 2020-07-29 Meco Man fix thread->event_set/event_info when received an * event without pending * 2020-10-11 Meco Man add semaphore values' overflow-check code - * in the function of rt_sem_release + * 2020-10-21 Meco Man add mutex values' overflow-check code */ #include @@ -697,8 +697,16 @@ rt_err_t rt_mutex_take(rt_mutex_t mutex, rt_int32_t time) if (mutex->owner == thread) { - /* it's the same thread */ - mutex->hold ++; + if(mutex->hold < 255u) + { + /* it's the same thread */ + mutex->hold ++; + } + else + { + rt_hw_interrupt_enable(temp); /* enable interrupt */ + return -RT_EFULL; /* value overflowed */ + } } else { -- cgit v1.3.1 From 0776b36a4f17239740c0a4d0254330c0e5ff9824 Mon Sep 17 00:00:00 2001 From: Bernard Xiong Date: Thu, 22 Oct 2020 22:44:58 +0800 Subject: [Kernel] fix the delay_until issue --- src/thread.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/thread.c b/src/thread.c index 7a90e57f25..49e2022bf7 100644 --- a/src/thread.c +++ b/src/thread.c @@ -569,7 +569,7 @@ rt_err_t rt_thread_delay_until(rt_tick_t *tick, rt_tick_t inc_tick) if (rt_tick_get() - *tick < inc_tick) { - *tick = rt_tick_get() - *tick + inc_tick; + *tick = *tick + inc_tick - rt_tick_get(); /* suspend thread */ rt_thread_suspend(thread); -- cgit v1.3.1