From 3f2c97dae8bf1bcd94ba1cdcc01736ca90f2aa71 Mon Sep 17 00:00:00 2001 From: Kurngsy Date: Wed, 19 Nov 2025 17:31:39 +0800 Subject: [PATCH 01/12] Additional details --- src/thread.c | 33 +++++++++++++++++++++------------ 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/src/thread.c b/src/thread.c index 481dfebeef2..11ce21f08d9 100644 --- a/src/thread.c +++ b/src/thread.c @@ -942,31 +942,40 @@ rt_err_t rt_thread_suspend_to_list(rt_thread_t thread, rt_list_t *susp_list, int /* parameter check */ RT_ASSERT(thread != RT_NULL); RT_ASSERT(rt_object_get_type((rt_object_t)thread) == RT_Object_Class_Thread); - + LOG_D("thread suspend: %s", thread->parent.name); + RT_ASSERT(thread == rt_thread_self()); rt_sched_lock(&slvl); stat = rt_sched_thread_get_stat(thread); - if (stat == RT_THREAD_SUSPEND) + if (stat & RT_THREAD_SUSPEND_MASK) { - rt_sched_unlock(slvl); - /* Already suspended, just set status to success. */ - return RT_EOK; + /* Already manually suspended, just set the status to success. */ + if (RT_SCHED_CTX(thread).sched_flag_ttmr_set == 0) + { + /* Update if a pending flag needs */ + if ((stat & RT_THREAD_STAT_MASK) < suspend_flag) + { + _thread_set_suspend_state(thread, suspend_flag); + } + + rt_sched_unlock(slvl); + return RT_EOK; + } + /* Manual suspension overrides delayed suspension. */ + else + { + LOG_D("thread suspend: converting delay suspend to manual suspend"); + } } else if ((stat != RT_THREAD_READY) && (stat != RT_THREAD_RUNNING)) { - LOG_D("thread suspend: thread disorder, 0x%2x", RT_SCHED_CTX(thread).stat); + LOG_W("thread suspend: thread disorder, 0x%02x", RT_SCHED_CTX(thread).stat); rt_sched_unlock(slvl); return -RT_ERROR; } - if (stat == RT_THREAD_RUNNING) - { - /* not suspend running status thread on other core */ - RT_ASSERT(thread == rt_thread_self()); - } - #ifdef RT_USING_SMART if (thread->lwp) { From 01415b8803d3a930101cc264c2c73a0952049367 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Wed, 19 Nov 2025 10:34:59 +0000 Subject: [PATCH 02/12] style: format code with clang-format [skip ci] --- src/thread.c | 136 +++++++++++++++++++++++++-------------------------- 1 file changed, 68 insertions(+), 68 deletions(-) diff --git a/src/thread.c b/src/thread.c index 11ce21f08d9..9782ec0c212 100644 --- a/src/thread.c +++ b/src/thread.c @@ -41,13 +41,13 @@ #include #include -#define DBG_TAG "kernel.thread" -#define DBG_LVL DBG_INFO +#define DBG_TAG "kernel.thread" +#define DBG_LVL DBG_INFO #include #if defined(RT_USING_HOOK) && defined(RT_HOOK_USING_FUNC_PTR) static void (*rt_thread_suspend_hook)(rt_thread_t thread); -static void (*rt_thread_resume_hook) (rt_thread_t thread); +static void (*rt_thread_resume_hook)(rt_thread_t thread); /** * @brief This function sets a hook function when the system suspend a thread. @@ -91,7 +91,7 @@ static void _thread_detach_from_mutex(rt_thread_t thread) (rt_object_get_type(thread->pending_object) == RT_Object_Class_Mutex)) { /* remove it from its waiting list */ - struct rt_mutex *mutex = (struct rt_mutex*)thread->pending_object; + struct rt_mutex *mutex = (struct rt_mutex *)thread->pending_object; rt_mutex_drop_thread(mutex, thread); thread->pending_object = RT_NULL; } @@ -174,13 +174,13 @@ static void _thread_timeout(void *parameter) } static rt_err_t _thread_init(struct rt_thread *thread, - const char *name, + const char *name, void (*entry)(void *parameter), - void *parameter, - void *stack_start, - rt_uint32_t stack_size, - rt_uint8_t priority, - rt_uint32_t tick) + void *parameter, + void *stack_start, + rt_uint32_t stack_size, + rt_uint8_t priority, + rt_uint32_t tick) { RT_UNUSED(name); @@ -235,7 +235,7 @@ static rt_err_t _thread_init(struct rt_thread *thread, #endif /* initialize cleanup function and user data */ - thread->cleanup = 0; + thread->cleanup = 0; thread->user_data = 0; /* initialize thread timer */ @@ -248,14 +248,14 @@ static rt_err_t _thread_init(struct rt_thread *thread, /* initialize signal */ #ifdef RT_USING_SIGNALS - thread->sig_mask = 0x00; + thread->sig_mask = 0x00; thread->sig_pending = 0x00; #ifndef RT_USING_SMP - thread->sig_ret = RT_NULL; + thread->sig_ret = RT_NULL; #endif /* RT_USING_SMP */ thread->sig_vectors = RT_NULL; - thread->si_list = RT_NULL; + thread->si_list = RT_NULL; #endif /* RT_USING_SIGNALS */ #ifdef RT_USING_SMART @@ -337,13 +337,13 @@ static rt_err_t _thread_init(struct rt_thread *thread, * If the return value is any other values, it means this operation failed. */ rt_err_t rt_thread_init(struct rt_thread *thread, - const char *name, + const char *name, void (*entry)(void *parameter), - void *parameter, - void *stack_start, - rt_uint32_t stack_size, - rt_uint8_t priority, - rt_uint32_t tick) + void *parameter, + void *stack_start, + rt_uint32_t stack_size, + rt_uint8_t priority, + rt_uint32_t tick) { /* parameter check */ RT_ASSERT(thread != RT_NULL); @@ -378,7 +378,7 @@ rt_thread_t rt_thread_self(void) #ifndef RT_USING_SMP return rt_cpu_self()->current_thread; -#elif defined (ARCH_USING_HW_THREAD_SELF) +#elif defined(ARCH_USING_HW_THREAD_SELF) return rt_hw_thread_self(); #else /* !ARCH_USING_HW_THREAD_SELF */ @@ -549,9 +549,9 @@ static rt_err_t _thread_detach(rt_thread_t thread) */ rt_thread_t rt_thread_create(const char *name, void (*entry)(void *parameter), - void *parameter, + void *parameter, rt_uint32_t stack_size, - rt_uint8_t priority, + rt_uint8_t priority, rt_uint32_t tick) { /* parameter check */ @@ -822,56 +822,56 @@ rt_err_t rt_thread_control(rt_thread_t thread, int cmd, void *arg) switch (cmd) { - case RT_THREAD_CTRL_CHANGE_PRIORITY: - { - rt_err_t error; - rt_sched_lock_level_t slvl; - rt_sched_lock(&slvl); - error = rt_sched_thread_change_priority(thread, *(rt_uint8_t *)arg); - rt_sched_unlock(slvl); - return error; - } + case RT_THREAD_CTRL_CHANGE_PRIORITY: + { + rt_err_t error; + rt_sched_lock_level_t slvl; + rt_sched_lock(&slvl); + error = rt_sched_thread_change_priority(thread, *(rt_uint8_t *)arg); + rt_sched_unlock(slvl); + return error; + } - case RT_THREAD_CTRL_RESET_PRIORITY: - { - rt_err_t error; - rt_sched_lock_level_t slvl; - rt_sched_lock(&slvl); - error = rt_sched_thread_reset_priority(thread, *(rt_uint8_t *)arg); - rt_sched_unlock(slvl); - return error; - } + case RT_THREAD_CTRL_RESET_PRIORITY: + { + rt_err_t error; + rt_sched_lock_level_t slvl; + rt_sched_lock(&slvl); + error = rt_sched_thread_reset_priority(thread, *(rt_uint8_t *)arg); + rt_sched_unlock(slvl); + return error; + } + + case RT_THREAD_CTRL_STARTUP: + { + return rt_thread_startup(thread); + } - case RT_THREAD_CTRL_STARTUP: + case RT_THREAD_CTRL_CLOSE: + { + rt_err_t rt_err = -RT_EINVAL; + + if (rt_object_is_systemobject((rt_object_t)thread) == RT_TRUE) { - return rt_thread_startup(thread); + rt_err = rt_thread_detach(thread); } - - case RT_THREAD_CTRL_CLOSE: +#ifdef RT_USING_HEAP + else { - rt_err_t rt_err = -RT_EINVAL; - - if (rt_object_is_systemobject((rt_object_t)thread) == RT_TRUE) - { - rt_err = rt_thread_detach(thread); - } - #ifdef RT_USING_HEAP - else - { - rt_err = rt_thread_delete(thread); - } - #endif /* RT_USING_HEAP */ - rt_schedule(); - return rt_err; + rt_err = rt_thread_delete(thread); } +#endif /* RT_USING_HEAP */ + rt_schedule(); + return rt_err; + } - case RT_THREAD_CTRL_BIND_CPU: - { - rt_uint8_t cpu; + case RT_THREAD_CTRL_BIND_CPU: + { + rt_uint8_t cpu; - cpu = (rt_uint8_t)(rt_size_t)arg; - return rt_sched_thread_bind_cpu(thread, cpu); - } + cpu = (rt_uint8_t)(rt_size_t)arg; + return rt_sched_thread_bind_cpu(thread, cpu); + } default: break; @@ -942,7 +942,7 @@ rt_err_t rt_thread_suspend_to_list(rt_thread_t thread, rt_list_t *susp_list, int /* parameter check */ RT_ASSERT(thread != RT_NULL); RT_ASSERT(rt_object_get_type((rt_object_t)thread) == RT_Object_Class_Thread); - + LOG_D("thread suspend: %s", thread->parent.name); RT_ASSERT(thread == rt_thread_self()); @@ -959,7 +959,7 @@ rt_err_t rt_thread_suspend_to_list(rt_thread_t thread, rt_list_t *susp_list, int { _thread_set_suspend_state(thread, suspend_flag); } - + rt_sched_unlock(slvl); return RT_EOK; } @@ -1168,7 +1168,7 @@ rt_err_t rt_thread_wakeup(rt_thread_t thread) } RTM_EXPORT(rt_thread_wakeup); -void rt_thread_wakeup_set(struct rt_thread *thread, rt_wakeup_func_t func, void* user_data) +void rt_thread_wakeup_set(struct rt_thread *thread, rt_wakeup_func_t func, void *user_data) { rt_sched_lock_level_t slvl; From bf41b81e3007c20bbe1c0b9f043f4f5737a1e54a Mon Sep 17 00:00:00 2001 From: Kurngsy <154585910+Kurngsy@users.noreply.github.com> Date: Thu, 20 Nov 2025 13:42:07 +0800 Subject: [PATCH 03/12] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=BA=86=E9=83=A8?= =?UTF-8?q?=E5=88=86=E9=94=99=E8=AF=AF=E9=80=BB=E8=BE=91=EF=BC=8C=E5=B9=B6?= =?UTF-8?q?=E4=BD=BF=E5=87=BD=E6=95=B0=E6=9C=89=E6=9B=B4=E9=AB=98=E6=9D=83?= =?UTF-8?q?=E9=99=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/thread.c | 35 +++++++++++++++++++---------------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/src/thread.c b/src/thread.c index 9782ec0c212..7845b6f5c12 100644 --- a/src/thread.c +++ b/src/thread.c @@ -942,39 +942,42 @@ rt_err_t rt_thread_suspend_to_list(rt_thread_t thread, rt_list_t *susp_list, int /* parameter check */ RT_ASSERT(thread != RT_NULL); RT_ASSERT(rt_object_get_type((rt_object_t)thread) == RT_Object_Class_Thread); - + LOG_D("thread suspend: %s", thread->parent.name); - RT_ASSERT(thread == rt_thread_self()); rt_sched_lock(&slvl); stat = rt_sched_thread_get_stat(thread); + /* Already suspended, just set the status to success. */ if (stat & RT_THREAD_SUSPEND_MASK) { - /* Already manually suspended, just set the status to success. */ - if (RT_SCHED_CTX(thread).sched_flag_ttmr_set == 0) + if (RT_SCHED_CTX(thread).sched_flag_ttmr_set == 1) { - /* Update if a pending flag needs */ - if ((stat & RT_THREAD_STAT_MASK) < suspend_flag) - { - _thread_set_suspend_state(thread, suspend_flag); - } - - rt_sched_unlock(slvl); - return RT_EOK; + /* The new suspend operation will halt the tick timer. */ + LOG_D("Thread [%s]'s timer has been halted.\n", thread->parent.name); + rt_sched_thread_timer_stop(thread); + } - /* Manual suspension overrides delayed suspension. */ - else + if (stat < suspend_flag) { - LOG_D("thread suspend: converting delay suspend to manual suspend"); + /* Update if a suspend_flag flag stricter */ + _thread_set_suspend_state(thread, suspend_flag); } + + rt_sched_unlock(slvl); + return RT_EOK; } else if ((stat != RT_THREAD_READY) && (stat != RT_THREAD_RUNNING)) { - LOG_W("thread suspend: thread disorder, 0x%02x", RT_SCHED_CTX(thread).stat); + LOG_W("thread suspend: thread disorder, 0x%02x", RT_SCHED_CTX(thread).stat); rt_sched_unlock(slvl); return -RT_ERROR; } + + if(stat == RT_THREAD_RUNNING) + { + RT_ASSERT(thread == rt_thread_self()); +} #ifdef RT_USING_SMART if (thread->lwp) From daf3b4e9ca3559574fa3ac8d23ee53ce717870ec Mon Sep 17 00:00:00 2001 From: Kurngsy <154585910+Kurngsy@users.noreply.github.com> Date: Thu, 20 Nov 2025 17:52:12 +0800 Subject: [PATCH 04/12] Update src/thread.c Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- src/thread.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/thread.c b/src/thread.c index 7845b6f5c12..c77ccbf88d0 100644 --- a/src/thread.c +++ b/src/thread.c @@ -969,7 +969,7 @@ rt_err_t rt_thread_suspend_to_list(rt_thread_t thread, rt_list_t *susp_list, int } else if ((stat != RT_THREAD_READY) && (stat != RT_THREAD_RUNNING)) { - LOG_W("thread suspend: thread disorder, 0x%02x", RT_SCHED_CTX(thread).stat); + LOG_W("thread suspend: thread disorder, 0x%02x", RT_SCHED_CTX(thread).stat); rt_sched_unlock(slvl); return -RT_ERROR; } From 0d6232fad305ae7a7dfc48aadf7547355d4d10a3 Mon Sep 17 00:00:00 2001 From: Kurngsy <154585910+Kurngsy@users.noreply.github.com> Date: Thu, 20 Nov 2025 17:52:30 +0800 Subject: [PATCH 05/12] Update src/thread.c Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- src/thread.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/thread.c b/src/thread.c index c77ccbf88d0..f48ec59d70d 100644 --- a/src/thread.c +++ b/src/thread.c @@ -974,7 +974,7 @@ rt_err_t rt_thread_suspend_to_list(rt_thread_t thread, rt_list_t *susp_list, int return -RT_ERROR; } - if(stat == RT_THREAD_RUNNING) + if (stat == RT_THREAD_RUNNING) { RT_ASSERT(thread == rt_thread_self()); } From c2fc9a7a0c204ce449d7687b1f11794acd3e88ac Mon Sep 17 00:00:00 2001 From: Kurngsy <154585910+Kurngsy@users.noreply.github.com> Date: Thu, 20 Nov 2025 17:56:03 +0800 Subject: [PATCH 06/12] Update src/thread.c Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- src/thread.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/thread.c b/src/thread.c index f48ec59d70d..1bf8f40614a 100644 --- a/src/thread.c +++ b/src/thread.c @@ -943,7 +943,7 @@ rt_err_t rt_thread_suspend_to_list(rt_thread_t thread, rt_list_t *susp_list, int RT_ASSERT(thread != RT_NULL); RT_ASSERT(rt_object_get_type((rt_object_t)thread) == RT_Object_Class_Thread); - LOG_D("thread suspend: %s", thread->parent.name); + LOG_D("thread suspend: %s", thread->parent.name); rt_sched_lock(&slvl); From 4a6b1ce80667474d4335fc7b94183683258eda91 Mon Sep 17 00:00:00 2001 From: Kurngsy <154585910+Kurngsy@users.noreply.github.com> Date: Thu, 20 Nov 2025 17:57:36 +0800 Subject: [PATCH 07/12] Update src/thread.c Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- src/thread.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/thread.c b/src/thread.c index 1bf8f40614a..18853a32c56 100644 --- a/src/thread.c +++ b/src/thread.c @@ -954,7 +954,7 @@ rt_err_t rt_thread_suspend_to_list(rt_thread_t thread, rt_list_t *susp_list, int if (RT_SCHED_CTX(thread).sched_flag_ttmr_set == 1) { /* The new suspend operation will halt the tick timer. */ - LOG_D("Thread [%s]'s timer has been halted.\n", thread->parent.name); + LOG_D("Thread [%s]'s timer has been halted.", thread->parent.name); rt_sched_thread_timer_stop(thread); } From 03881b0aac8f217ee4ce4bfebdd2aca57a8a4625 Mon Sep 17 00:00:00 2001 From: Kurngsy <154585910+Kurngsy@users.noreply.github.com> Date: Thu, 20 Nov 2025 17:59:53 +0800 Subject: [PATCH 08/12] Update src/thread.c Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- src/thread.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/thread.c b/src/thread.c index 18853a32c56..074b05e18ba 100644 --- a/src/thread.c +++ b/src/thread.c @@ -960,7 +960,7 @@ rt_err_t rt_thread_suspend_to_list(rt_thread_t thread, rt_list_t *susp_list, int } if (stat < suspend_flag) { - /* Update if a suspend_flag flag stricter */ + /* Update if suspend_flag is stricter */ _thread_set_suspend_state(thread, suspend_flag); } From 31a980451e396b1ed93348b69eda46c47d358d6b Mon Sep 17 00:00:00 2001 From: Kurngsy <154585910+Kurngsy@users.noreply.github.com> Date: Thu, 20 Nov 2025 18:11:39 +0800 Subject: [PATCH 09/12] Implement thread suspend state mapping logic Map suspend_flag to corresponding thread suspend state values and update suspend state if stricter flag is requested. --- src/thread.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/thread.c b/src/thread.c index 074b05e18ba..ad31a9d695d 100644 --- a/src/thread.c +++ b/src/thread.c @@ -958,8 +958,25 @@ rt_err_t rt_thread_suspend_to_list(rt_thread_t thread, rt_list_t *susp_list, int rt_sched_thread_timer_stop(thread); } - if (stat < suspend_flag) + /* Map suspend_flag to corresponding thread suspend state value */ + rt_uint8_t new_suspend_state; + switch (suspend_flag) { + case RT_INTERRUPTIBLE: + new_suspend_state = RT_THREAD_SUSPEND_INTERRUPTIBLE; + break; + case RT_KILLABLE: + new_suspend_state = RT_THREAD_SUSPEND_KILLABLE; + break; + case RT_UNINTERRUPTIBLE: + default: + new_suspend_state = RT_THREAD_SUSPEND_UNINTERRUPTIBLE; + break; + } + /* Compare the suspend state portion of stat with the new suspend state */ + if (stat < new_suspend_state) + { + /* Update if a stricter suspend_flag is requested */ /* Update if suspend_flag is stricter */ _thread_set_suspend_state(thread, suspend_flag); } From ddc6dc5437e367d9a1449edc2ad5d30a3680c9c4 Mon Sep 17 00:00:00 2001 From: Kurngsy <154585910+Kurngsy@users.noreply.github.com> Date: Thu, 20 Nov 2025 18:23:10 +0800 Subject: [PATCH 10/12] Refactor suspend state update comment for clarity --- src/thread.c | 1 - 1 file changed, 1 deletion(-) diff --git a/src/thread.c b/src/thread.c index ad31a9d695d..26e1dd59c4a 100644 --- a/src/thread.c +++ b/src/thread.c @@ -976,7 +976,6 @@ rt_err_t rt_thread_suspend_to_list(rt_thread_t thread, rt_list_t *susp_list, int /* Compare the suspend state portion of stat with the new suspend state */ if (stat < new_suspend_state) { - /* Update if a stricter suspend_flag is requested */ /* Update if suspend_flag is stricter */ _thread_set_suspend_state(thread, suspend_flag); } From 0877515caf3bff359c4733c0a31b7017441f04f2 Mon Sep 17 00:00:00 2001 From: Kurngsy <154585910+Kurngsy@users.noreply.github.com> Date: Fri, 21 Nov 2025 17:24:21 +0800 Subject: [PATCH 11/12] Refactor thread.c for code consistency and clarity --- src/thread.c | 148 +++++++++++++++++++++++++-------------------------- 1 file changed, 74 insertions(+), 74 deletions(-) diff --git a/src/thread.c b/src/thread.c index 26e1dd59c4a..b589d9e1200 100644 --- a/src/thread.c +++ b/src/thread.c @@ -41,13 +41,13 @@ #include #include -#define DBG_TAG "kernel.thread" -#define DBG_LVL DBG_INFO +#define DBG_TAG "kernel.thread" +#define DBG_LVL DBG_INFO #include #if defined(RT_USING_HOOK) && defined(RT_HOOK_USING_FUNC_PTR) static void (*rt_thread_suspend_hook)(rt_thread_t thread); -static void (*rt_thread_resume_hook)(rt_thread_t thread); +static void (*rt_thread_resume_hook) (rt_thread_t thread); /** * @brief This function sets a hook function when the system suspend a thread. @@ -91,7 +91,7 @@ static void _thread_detach_from_mutex(rt_thread_t thread) (rt_object_get_type(thread->pending_object) == RT_Object_Class_Mutex)) { /* remove it from its waiting list */ - struct rt_mutex *mutex = (struct rt_mutex *)thread->pending_object; + struct rt_mutex *mutex = (struct rt_mutex*)thread->pending_object; rt_mutex_drop_thread(mutex, thread); thread->pending_object = RT_NULL; } @@ -174,13 +174,13 @@ static void _thread_timeout(void *parameter) } static rt_err_t _thread_init(struct rt_thread *thread, - const char *name, + const char *name, void (*entry)(void *parameter), - void *parameter, - void *stack_start, - rt_uint32_t stack_size, - rt_uint8_t priority, - rt_uint32_t tick) + void *parameter, + void *stack_start, + rt_uint32_t stack_size, + rt_uint8_t priority, + rt_uint32_t tick) { RT_UNUSED(name); @@ -235,7 +235,7 @@ static rt_err_t _thread_init(struct rt_thread *thread, #endif /* initialize cleanup function and user data */ - thread->cleanup = 0; + thread->cleanup = 0; thread->user_data = 0; /* initialize thread timer */ @@ -248,14 +248,14 @@ static rt_err_t _thread_init(struct rt_thread *thread, /* initialize signal */ #ifdef RT_USING_SIGNALS - thread->sig_mask = 0x00; + thread->sig_mask = 0x00; thread->sig_pending = 0x00; #ifndef RT_USING_SMP - thread->sig_ret = RT_NULL; + thread->sig_ret = RT_NULL; #endif /* RT_USING_SMP */ thread->sig_vectors = RT_NULL; - thread->si_list = RT_NULL; + thread->si_list = RT_NULL; #endif /* RT_USING_SIGNALS */ #ifdef RT_USING_SMART @@ -337,13 +337,13 @@ static rt_err_t _thread_init(struct rt_thread *thread, * If the return value is any other values, it means this operation failed. */ rt_err_t rt_thread_init(struct rt_thread *thread, - const char *name, + const char *name, void (*entry)(void *parameter), - void *parameter, - void *stack_start, - rt_uint32_t stack_size, - rt_uint8_t priority, - rt_uint32_t tick) + void *parameter, + void *stack_start, + rt_uint32_t stack_size, + rt_uint8_t priority, + rt_uint32_t tick) { /* parameter check */ RT_ASSERT(thread != RT_NULL); @@ -378,7 +378,7 @@ rt_thread_t rt_thread_self(void) #ifndef RT_USING_SMP return rt_cpu_self()->current_thread; -#elif defined(ARCH_USING_HW_THREAD_SELF) +#elif defined (ARCH_USING_HW_THREAD_SELF) return rt_hw_thread_self(); #else /* !ARCH_USING_HW_THREAD_SELF */ @@ -549,9 +549,9 @@ static rt_err_t _thread_detach(rt_thread_t thread) */ rt_thread_t rt_thread_create(const char *name, void (*entry)(void *parameter), - void *parameter, + void *parameter, rt_uint32_t stack_size, - rt_uint8_t priority, + rt_uint8_t priority, rt_uint32_t tick) { /* parameter check */ @@ -822,56 +822,56 @@ rt_err_t rt_thread_control(rt_thread_t thread, int cmd, void *arg) switch (cmd) { - case RT_THREAD_CTRL_CHANGE_PRIORITY: - { - rt_err_t error; - rt_sched_lock_level_t slvl; - rt_sched_lock(&slvl); - error = rt_sched_thread_change_priority(thread, *(rt_uint8_t *)arg); - rt_sched_unlock(slvl); - return error; - } - - case RT_THREAD_CTRL_RESET_PRIORITY: - { - rt_err_t error; - rt_sched_lock_level_t slvl; - rt_sched_lock(&slvl); - error = rt_sched_thread_reset_priority(thread, *(rt_uint8_t *)arg); - rt_sched_unlock(slvl); - return error; - } - - case RT_THREAD_CTRL_STARTUP: - { - return rt_thread_startup(thread); - } + case RT_THREAD_CTRL_CHANGE_PRIORITY: + { + rt_err_t error; + rt_sched_lock_level_t slvl; + rt_sched_lock(&slvl); + error = rt_sched_thread_change_priority(thread, *(rt_uint8_t *)arg); + rt_sched_unlock(slvl); + return error; + } - case RT_THREAD_CTRL_CLOSE: - { - rt_err_t rt_err = -RT_EINVAL; + case RT_THREAD_CTRL_RESET_PRIORITY: + { + rt_err_t error; + rt_sched_lock_level_t slvl; + rt_sched_lock(&slvl); + error = rt_sched_thread_reset_priority(thread, *(rt_uint8_t *)arg); + rt_sched_unlock(slvl); + return error; + } - if (rt_object_is_systemobject((rt_object_t)thread) == RT_TRUE) + case RT_THREAD_CTRL_STARTUP: { - rt_err = rt_thread_detach(thread); + return rt_thread_startup(thread); } -#ifdef RT_USING_HEAP - else + + case RT_THREAD_CTRL_CLOSE: { - rt_err = rt_thread_delete(thread); + rt_err_t rt_err = -RT_EINVAL; + + if (rt_object_is_systemobject((rt_object_t)thread) == RT_TRUE) + { + rt_err = rt_thread_detach(thread); + } + #ifdef RT_USING_HEAP + else + { + rt_err = rt_thread_delete(thread); + } + #endif /* RT_USING_HEAP */ + rt_schedule(); + return rt_err; } -#endif /* RT_USING_HEAP */ - rt_schedule(); - return rt_err; - } - case RT_THREAD_CTRL_BIND_CPU: - { - rt_uint8_t cpu; + case RT_THREAD_CTRL_BIND_CPU: + { + rt_uint8_t cpu; - cpu = (rt_uint8_t)(rt_size_t)arg; - return rt_sched_thread_bind_cpu(thread, cpu); - } + cpu = (rt_uint8_t)(rt_size_t)arg; + return rt_sched_thread_bind_cpu(thread, cpu); + } default: break; @@ -942,7 +942,7 @@ rt_err_t rt_thread_suspend_to_list(rt_thread_t thread, rt_list_t *susp_list, int /* parameter check */ RT_ASSERT(thread != RT_NULL); RT_ASSERT(rt_object_get_type((rt_object_t)thread) == RT_Object_Class_Thread); - + LOG_D("thread suspend: %s", thread->parent.name); rt_sched_lock(&slvl); @@ -954,9 +954,9 @@ rt_err_t rt_thread_suspend_to_list(rt_thread_t thread, rt_list_t *susp_list, int if (RT_SCHED_CTX(thread).sched_flag_ttmr_set == 1) { /* The new suspend operation will halt the tick timer. */ - LOG_D("Thread [%s]'s timer has been halted.", thread->parent.name); + LOG_D("Thread [%s]'s timer has been halted.\n", thread->parent.name); rt_sched_thread_timer_stop(thread); - + } /* Map suspend_flag to corresponding thread suspend state value */ rt_uint8_t new_suspend_state; @@ -979,7 +979,7 @@ rt_err_t rt_thread_suspend_to_list(rt_thread_t thread, rt_list_t *susp_list, int /* Update if suspend_flag is stricter */ _thread_set_suspend_state(thread, suspend_flag); } - + rt_sched_unlock(slvl); return RT_EOK; } @@ -989,12 +989,12 @@ rt_err_t rt_thread_suspend_to_list(rt_thread_t thread, rt_list_t *susp_list, int rt_sched_unlock(slvl); return -RT_ERROR; } - - if (stat == RT_THREAD_RUNNING) + + if(stat == RT_THREAD_RUNNING) { RT_ASSERT(thread == rt_thread_self()); -} - + } + #ifdef RT_USING_SMART if (thread->lwp) { @@ -1187,7 +1187,7 @@ rt_err_t rt_thread_wakeup(rt_thread_t thread) } RTM_EXPORT(rt_thread_wakeup); -void rt_thread_wakeup_set(struct rt_thread *thread, rt_wakeup_func_t func, void *user_data) +void rt_thread_wakeup_set(struct rt_thread *thread, rt_wakeup_func_t func, void* user_data) { rt_sched_lock_level_t slvl; From f317ee7e36c30f5e51b7348f97e0c4ffe97a7d6e Mon Sep 17 00:00:00 2001 From: Kurngsy <154585910+Kurngsy@users.noreply.github.com> Date: Fri, 21 Nov 2025 17:26:10 +0800 Subject: [PATCH 12/12] Fix formatting of if statement in thread.c --- src/thread.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/thread.c b/src/thread.c index b589d9e1200..17bfdce08ba 100644 --- a/src/thread.c +++ b/src/thread.c @@ -990,7 +990,7 @@ rt_err_t rt_thread_suspend_to_list(rt_thread_t thread, rt_list_t *susp_list, int return -RT_ERROR; } - if(stat == RT_THREAD_RUNNING) + if (stat == RT_THREAD_RUNNING) { RT_ASSERT(thread == rt_thread_self()); }