From 3bb8edf4c1b9b0a8ecb1cd9072da3e5edc3502b0 Mon Sep 17 00:00:00 2001 From: Han Xinrong Date: Mon, 7 Dec 2020 20:13:03 +0800 Subject: [PATCH 1/3] error check of rt_event_recv() add error check --- .../templates/nrf52x/applications/ble_nus_app.c | 4 +++- components/dfs/filesystems/jffs2/src/gcthread.c | 10 +++++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/bsp/nrf5x/libraries/templates/nrf52x/applications/ble_nus_app.c b/bsp/nrf5x/libraries/templates/nrf52x/applications/ble_nus_app.c index f4a51493ed..0ce3d43a36 100644 --- a/bsp/nrf5x/libraries/templates/nrf52x/applications/ble_nus_app.c +++ b/bsp/nrf5x/libraries/templates/nrf52x/applications/ble_nus_app.c @@ -599,9 +599,11 @@ static void _stack_thread(void *parameter) { rt_uint32_t event = 0; rt_tick_t dispatch_timeout = RT_WAITING_NO; + rt_err_t result; - rt_event_recv(stack_event, STACK_EV_DISCON | STACK_EV_DISPATCH | STACK_EV_KEY, + result = rt_event_recv(stack_event, STACK_EV_DISCON | STACK_EV_DISPATCH | STACK_EV_KEY, RT_EVENT_FLAG_OR | RT_EVENT_FLAG_CLEAR, next_timeout, &event); + RT_ASSERT(result == RT_EOK); if (evt_dispatch_worker() != RT_EOK) { diff --git a/components/dfs/filesystems/jffs2/src/gcthread.c b/components/dfs/filesystems/jffs2/src/gcthread.c index 4005ec4788..3807e705b1 100644 --- a/components/dfs/filesystems/jffs2/src/gcthread.c +++ b/components/dfs/filesystems/jffs2/src/gcthread.c @@ -187,7 +187,8 @@ jffs2_stop_garbage_collect_thread(struct jffs2_sb_info *c) { struct super_block *sb=OFNI_BS_2SFFJ(c); cyg_mtab_entry *mte; - rt_uint32_t e; + rt_uint32_t e; + rt_err_t result; //RT_ASSERT(sb->s_gc_thread_handle); @@ -198,10 +199,11 @@ jffs2_stop_garbage_collect_thread(struct jffs2_sb_info *c) D1(printk("jffs2_stop_garbage_collect_thread wait\n")); - rt_event_recv(&sb->s_gc_thread_flags, + result = rt_event_recv(&sb->s_gc_thread_flags, GC_THREAD_FLAG_HAS_EXIT, RT_EVENT_FLAG_OR | RT_EVENT_FLAG_CLEAR, RT_WAITING_FOREVER, &e); + RT_ASSERT(result == RT_EOK); // Kill and free the resources ... this is safe due to the flag // from the thread. @@ -218,15 +220,17 @@ jffs2_garbage_collect_thread(unsigned long data) struct super_block *sb=OFNI_BS_2SFFJ(c); cyg_mtab_entry *mte; rt_uint32_t flag = 0; + rt_err_t result; D1(printk("jffs2_garbage_collect_thread START\n")); while(1) { - rt_event_recv(&sb->s_gc_thread_flags, + result = rt_event_recv(&sb->s_gc_thread_flags, GC_THREAD_FLAG_TRIG | GC_THREAD_FLAG_STOP, RT_EVENT_FLAG_OR | RT_EVENT_FLAG_CLEAR, cyg_current_time() + CYGNUM_JFFS2_GS_THREAD_TICKS, &flag); + RT_ASSERT(result == RT_EOK); if (flag & GC_THREAD_FLAG_STOP) break; From a1fe7b1ddf882ab37eb61157fffcf2e42c7b2357 Mon Sep 17 00:00:00 2001 From: Han Xinrong Date: Sun, 13 Dec 2020 19:11:04 +0800 Subject: [PATCH 2/3] modify the error check of rt_event_recv() --- .../templates/nrf52x/applications/ble_nus_app.c | 8 +++++++- components/dfs/filesystems/jffs2/src/gcthread.c | 16 ++++++++++++++-- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/bsp/nrf5x/libraries/templates/nrf52x/applications/ble_nus_app.c b/bsp/nrf5x/libraries/templates/nrf52x/applications/ble_nus_app.c index 0ce3d43a36..48709eb5c1 100644 --- a/bsp/nrf5x/libraries/templates/nrf52x/applications/ble_nus_app.c +++ b/bsp/nrf5x/libraries/templates/nrf52x/applications/ble_nus_app.c @@ -603,7 +603,13 @@ static void _stack_thread(void *parameter) result = rt_event_recv(stack_event, STACK_EV_DISCON | STACK_EV_DISPATCH | STACK_EV_KEY, RT_EVENT_FLAG_OR | RT_EVENT_FLAG_CLEAR, next_timeout, &event); - RT_ASSERT(result == RT_EOK); + if (result == -RT_ETIMEOUT) { + LOG_E("wait completed timeout"); + continue; + }else if (result == -RT_ERROR) { + LOG_E("event received error"); + continue; + } if (evt_dispatch_worker() != RT_EOK) { diff --git a/components/dfs/filesystems/jffs2/src/gcthread.c b/components/dfs/filesystems/jffs2/src/gcthread.c index 3807e705b1..0aad0ae3ae 100644 --- a/components/dfs/filesystems/jffs2/src/gcthread.c +++ b/components/dfs/filesystems/jffs2/src/gcthread.c @@ -203,7 +203,13 @@ jffs2_stop_garbage_collect_thread(struct jffs2_sb_info *c) GC_THREAD_FLAG_HAS_EXIT, RT_EVENT_FLAG_OR | RT_EVENT_FLAG_CLEAR, RT_WAITING_FOREVER, &e); - RT_ASSERT(result == RT_EOK); + if (result == -RT_ETIMEOUT) { + LOG_E("wait completed timeout"); + return; + }else if (result == -RT_ERROR) { + LOG_E("event received error"); + return; + } // Kill and free the resources ... this is safe due to the flag // from the thread. @@ -230,7 +236,13 @@ jffs2_garbage_collect_thread(unsigned long data) RT_EVENT_FLAG_OR | RT_EVENT_FLAG_CLEAR, cyg_current_time() + CYGNUM_JFFS2_GS_THREAD_TICKS, &flag); - RT_ASSERT(result == RT_EOK); + if (result == -RT_ETIMEOUT) { + LOG_E("wait completed timeout"); + continue; + }else if (result == -RT_ERROR) { + LOG_E("event received error"); + continue; + } if (flag & GC_THREAD_FLAG_STOP) break; From db4b3ff125871427e78cd7105b28f68a3e7c646c Mon Sep 17 00:00:00 2001 From: Han Xinrong Date: Tue, 15 Dec 2020 11:37:23 +0800 Subject: [PATCH 3/3] modify code style --- .../nrf52x/applications/ble_nus_app.c | 7 +++-- .../dfs/filesystems/jffs2/src/gcthread.c | 26 ++++++++++++------- 2 files changed, 21 insertions(+), 12 deletions(-) diff --git a/bsp/nrf5x/libraries/templates/nrf52x/applications/ble_nus_app.c b/bsp/nrf5x/libraries/templates/nrf52x/applications/ble_nus_app.c index 48709eb5c1..5739e91c7e 100644 --- a/bsp/nrf5x/libraries/templates/nrf52x/applications/ble_nus_app.c +++ b/bsp/nrf5x/libraries/templates/nrf52x/applications/ble_nus_app.c @@ -603,10 +603,13 @@ static void _stack_thread(void *parameter) result = rt_event_recv(stack_event, STACK_EV_DISCON | STACK_EV_DISPATCH | STACK_EV_KEY, RT_EVENT_FLAG_OR | RT_EVENT_FLAG_CLEAR, next_timeout, &event); - if (result == -RT_ETIMEOUT) { + if (result == -RT_ETIMEOUT) + { LOG_E("wait completed timeout"); continue; - }else if (result == -RT_ERROR) { + } + else if (result == -RT_ERROR) + { LOG_E("event received error"); continue; } diff --git a/components/dfs/filesystems/jffs2/src/gcthread.c b/components/dfs/filesystems/jffs2/src/gcthread.c index 0aad0ae3ae..ab66e1878e 100644 --- a/components/dfs/filesystems/jffs2/src/gcthread.c +++ b/components/dfs/filesystems/jffs2/src/gcthread.c @@ -187,7 +187,7 @@ jffs2_stop_garbage_collect_thread(struct jffs2_sb_info *c) { struct super_block *sb=OFNI_BS_2SFFJ(c); cyg_mtab_entry *mte; - rt_uint32_t e; + rt_uint32_t e; rt_err_t result; //RT_ASSERT(sb->s_gc_thread_handle); @@ -203,13 +203,16 @@ jffs2_stop_garbage_collect_thread(struct jffs2_sb_info *c) GC_THREAD_FLAG_HAS_EXIT, RT_EVENT_FLAG_OR | RT_EVENT_FLAG_CLEAR, RT_WAITING_FOREVER, &e); - if (result == -RT_ETIMEOUT) { - LOG_E("wait completed timeout"); - return; - }else if (result == -RT_ERROR) { - LOG_E("event received error"); - return; - } + if (result == -RT_ETIMEOUT) + { + LOG_E("wait completed timeout"); + return; + } + else if (result == -RT_ERROR) + { + LOG_E("event received error"); + return; + } // Kill and free the resources ... this is safe due to the flag // from the thread. @@ -236,10 +239,13 @@ jffs2_garbage_collect_thread(unsigned long data) RT_EVENT_FLAG_OR | RT_EVENT_FLAG_CLEAR, cyg_current_time() + CYGNUM_JFFS2_GS_THREAD_TICKS, &flag); - if (result == -RT_ETIMEOUT) { + if (result == -RT_ETIMEOUT) + { LOG_E("wait completed timeout"); continue; - }else if (result == -RT_ERROR) { + } + else if (result == -RT_ERROR) + { LOG_E("event received error"); continue; }