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 b43f7365a45d34829326d54d81f1efc69d848437 Mon Sep 17 00:00:00 2001 From: mysterywolf <920369182@qq.com> Date: Thu, 22 Oct 2020 07:13:49 +0800 Subject: [bug fixed] add mb mq value overflow-check code --- src/ipc.c | 78 +++++++++++++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 63 insertions(+), 15 deletions(-) (limited to 'src') diff --git a/src/ipc.c b/src/ipc.c index 129d3eea44..9cd2b8846d 100644 --- a/src/ipc.c +++ b/src/ipc.c @@ -36,8 +36,7 @@ * 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 - * 2020-10-11 Meco Man add semaphore values' overflow-check code - * 2020-10-21 Meco Man add mutex values' overflow-check code + * 2020-10-11 Meco Man add value overflow-check code */ #include @@ -724,7 +723,15 @@ __again: /* set mutex owner and original priority */ mutex->owner = thread; mutex->original_priority = thread->current_priority; - mutex->hold ++; + if(mutex->hold < 255u) + { + mutex->hold ++; + } + else + { + rt_hw_interrupt_enable(temp); /* enable interrupt */ + return -RT_EFULL; /* value overflowed */ + } } else { @@ -881,7 +888,15 @@ rt_err_t rt_mutex_release(rt_mutex_t mutex) /* set new owner and priority */ mutex->owner = thread; mutex->original_priority = thread->current_priority; - mutex->hold ++; + if(mutex->hold < 255u) + { + mutex->hold ++; + } + else + { + rt_hw_interrupt_enable(temp); /* enable interrupt */ + return -RT_EFULL; /* value overflowed */ + } /* resume thread */ rt_ipc_list_resume(&(mutex->parent.suspend_thread)); @@ -890,9 +905,17 @@ rt_err_t rt_mutex_release(rt_mutex_t mutex) } else { - /* increase value */ - mutex->value ++; - + if(mutex->value < 65535u) + { + /* increase value */ + mutex->value ++; + } + else + { + rt_hw_interrupt_enable(temp); /* enable interrupt */ + return -RT_EFULL; /* value overflowed */ + } + /* clear owner */ mutex->owner = RT_NULL; mutex->original_priority = 0xff; @@ -1583,9 +1606,18 @@ rt_err_t rt_mb_send_wait(rt_mailbox_t mb, ++ mb->in_offset; if (mb->in_offset >= mb->size) mb->in_offset = 0; - /* increase message entry */ - mb->entry ++; - + + if(mb->entry < 65535u) + { + /* increase message entry */ + mb->entry ++; + } + else + { + rt_hw_interrupt_enable(temp); /* enable interrupt */ + return -RT_EFULL; /* value overflowed */ + } + /* resume suspended thread */ if (!rt_list_isempty(&mb->parent.suspend_thread)) { @@ -2147,8 +2179,16 @@ rt_err_t rt_mq_send_wait(rt_mq_t mq, if (mq->msg_queue_head == RT_NULL) mq->msg_queue_head = msg; - /* increase message entry */ - mq->entry ++; + if(mq->entry < 65535u) + { + /* increase message entry */ + mq->entry ++; + } + else + { + rt_hw_interrupt_enable(temp); /* enable interrupt */ + return -RT_EFULL; /* value overflowed */ + } /* resume suspended thread */ if (!rt_list_isempty(&mq->parent.suspend_thread)) @@ -2247,9 +2287,17 @@ rt_err_t rt_mq_urgent(rt_mq_t mq, const void *buffer, rt_size_t size) if (mq->msg_queue_tail == RT_NULL) mq->msg_queue_tail = msg; - /* increase message entry */ - mq->entry ++; - + if(mq->entry < 65535u) + { + /* increase message entry */ + mq->entry ++; + } + else + { + rt_hw_interrupt_enable(temp); /* enable interrupt */ + return -RT_EFULL; /* value overflowed */ + } + /* resume suspended thread */ if (!rt_list_isempty(&mq->parent.suspend_thread)) { -- 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 From 98f0cfbf6e37a072ddf3aa2ae6a600c5dee964aa Mon Sep 17 00:00:00 2001 From: mysterywolf <920369182@qq.com> Date: Fri, 23 Oct 2020 01:04:06 +0800 Subject: define maximum value of ipc type --- include/rtdef.h | 8 ++++++++ src/ipc.c | 16 ++++++++-------- 2 files changed, 16 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/include/rtdef.h b/include/rtdef.h index 5543b80ab7..0690371c6d 100644 --- a/include/rtdef.h +++ b/include/rtdef.h @@ -33,6 +33,7 @@ * 2019-05-17 Bernard change version number to v4.0.2 * 2019-12-20 Bernard change version number to v4.0.3 * 2020-08-10 Meco Man add macro for struct rt_device_ops + * 2020-10-23 Meco Man define maximum value of ipc type */ #ifndef __RT_DEF_H__ @@ -102,6 +103,13 @@ typedef rt_base_t rt_off_t; /**< Type for offset */ #define RT_UINT32_MAX 0xffffffff /**< Maxium number of UINT32 */ #define RT_TICK_MAX RT_UINT32_MAX /**< Maxium number of tick */ +/* maximum value of ipc type */ +#define RT_SEM_VALUE_MAX RT_UINT16_MAX /**< Maxium number of semaphore .value */ +#define RT_MUTEX_VALUE_MAX RT_UINT16_MAX /**< Maxium number of mutex .value */ +#define RT_MUTEX_HOLD_MAX RT_UINT8_MAX /**< Maxium number of mutex .hold */ +#define RT_MB_ENTRY_MAX RT_UINT16_MAX /**< Maxium number of mailbox .entry */ +#define RT_MQ_ENTRY_MAX RT_UINT16_MAX /**< Maxium number of message queue .entry */ + #if defined (__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050) #define __CLANG_ARM #endif diff --git a/src/ipc.c b/src/ipc.c index 9cd2b8846d..454fcb5439 100644 --- a/src/ipc.c +++ b/src/ipc.c @@ -465,7 +465,7 @@ rt_err_t rt_sem_release(rt_sem_t sem) } else { - if(sem->value < 65535u) + if(sem->value < RT_SEM_VALUE_MAX) { sem->value ++; /* increase value */ } @@ -696,7 +696,7 @@ rt_err_t rt_mutex_take(rt_mutex_t mutex, rt_int32_t time) if (mutex->owner == thread) { - if(mutex->hold < 255u) + if(mutex->hold < RT_MUTEX_HOLD_MAX) { /* it's the same thread */ mutex->hold ++; @@ -723,7 +723,7 @@ __again: /* set mutex owner and original priority */ mutex->owner = thread; mutex->original_priority = thread->current_priority; - if(mutex->hold < 255u) + if(mutex->hold < RT_MUTEX_HOLD_MAX) { mutex->hold ++; } @@ -888,7 +888,7 @@ rt_err_t rt_mutex_release(rt_mutex_t mutex) /* set new owner and priority */ mutex->owner = thread; mutex->original_priority = thread->current_priority; - if(mutex->hold < 255u) + if(mutex->hold < RT_MUTEX_HOLD_MAX) { mutex->hold ++; } @@ -905,7 +905,7 @@ rt_err_t rt_mutex_release(rt_mutex_t mutex) } else { - if(mutex->value < 65535u) + if(mutex->value < RT_MUTEX_VALUE_MAX) { /* increase value */ mutex->value ++; @@ -1607,7 +1607,7 @@ rt_err_t rt_mb_send_wait(rt_mailbox_t mb, if (mb->in_offset >= mb->size) mb->in_offset = 0; - if(mb->entry < 65535u) + if(mb->entry < RT_MB_ENTRY_MAX) { /* increase message entry */ mb->entry ++; @@ -2179,7 +2179,7 @@ rt_err_t rt_mq_send_wait(rt_mq_t mq, if (mq->msg_queue_head == RT_NULL) mq->msg_queue_head = msg; - if(mq->entry < 65535u) + if(mq->entry < RT_MQ_ENTRY_MAX) { /* increase message entry */ mq->entry ++; @@ -2287,7 +2287,7 @@ rt_err_t rt_mq_urgent(rt_mq_t mq, const void *buffer, rt_size_t size) if (mq->msg_queue_tail == RT_NULL) mq->msg_queue_tail = msg; - if(mq->entry < 65535u) + if(mq->entry < RT_MQ_ENTRY_MAX) { /* increase message entry */ mq->entry ++; -- cgit v1.3.1 From ea89767f2ce50078f6dc161189c4a15720ccee7f Mon Sep 17 00:00:00 2001 From: thread-liu Date: Fri, 30 Oct 2020 10:32:44 +0800 Subject: [update] check whether it's a same console device. --- src/kservice.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/kservice.c b/src/kservice.c index 7caf43ce28..0a74f05268 100644 --- a/src/kservice.c +++ b/src/kservice.c @@ -1116,7 +1116,7 @@ RTM_EXPORT(rt_console_get_device); * * @param name the name of new console device * - * @return the old console device handler + * @return the old console device handler on successful, or RT_NULL on failure. */ rt_device_t rt_console_set_device(const char *name) { @@ -1127,6 +1127,10 @@ rt_device_t rt_console_set_device(const char *name) /* find new console device */ new_device = rt_device_find(name); + + /* check whether it's a same device */ + if (new_device == old_device) return RT_NULL; + if (new_device != RT_NULL) { if (_console_device != RT_NULL) -- cgit v1.3.1