Skip to content

Commit 32cf867

Browse files
authored
Merge pull request #4134 from Hxinrong/rt_event_recvBranch
add error checks of function rt_event_recv()
2 parents a9a004f + db4b3ff commit 32cf867

File tree

2 files changed

+37
-4
lines changed

2 files changed

+37
-4
lines changed

bsp/nrf5x/libraries/templates/nrf52x/applications/ble_nus_app.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -599,9 +599,20 @@ static void _stack_thread(void *parameter)
599599
{
600600
rt_uint32_t event = 0;
601601
rt_tick_t dispatch_timeout = RT_WAITING_NO;
602+
rt_err_t result;
602603

603-
rt_event_recv(stack_event, STACK_EV_DISCON | STACK_EV_DISPATCH | STACK_EV_KEY,
604+
result = rt_event_recv(stack_event, STACK_EV_DISCON | STACK_EV_DISPATCH | STACK_EV_KEY,
604605
RT_EVENT_FLAG_OR | RT_EVENT_FLAG_CLEAR, next_timeout, &event);
606+
if (result == -RT_ETIMEOUT)
607+
{
608+
LOG_E("wait completed timeout");
609+
continue;
610+
}
611+
else if (result == -RT_ERROR)
612+
{
613+
LOG_E("event received error");
614+
continue;
615+
}
605616

606617
if (evt_dispatch_worker() != RT_EOK)
607618
{

components/dfs/filesystems/jffs2/src/gcthread.c

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,8 @@ jffs2_stop_garbage_collect_thread(struct jffs2_sb_info *c)
187187
{
188188
struct super_block *sb=OFNI_BS_2SFFJ(c);
189189
cyg_mtab_entry *mte;
190-
rt_uint32_t e;
190+
rt_uint32_t e;
191+
rt_err_t result;
191192

192193
//RT_ASSERT(sb->s_gc_thread_handle);
193194

@@ -198,10 +199,20 @@ jffs2_stop_garbage_collect_thread(struct jffs2_sb_info *c)
198199

199200
D1(printk("jffs2_stop_garbage_collect_thread wait\n"));
200201

201-
rt_event_recv(&sb->s_gc_thread_flags,
202+
result = rt_event_recv(&sb->s_gc_thread_flags,
202203
GC_THREAD_FLAG_HAS_EXIT,
203204
RT_EVENT_FLAG_OR | RT_EVENT_FLAG_CLEAR,
204205
RT_WAITING_FOREVER, &e);
206+
if (result == -RT_ETIMEOUT)
207+
{
208+
LOG_E("wait completed timeout");
209+
return;
210+
}
211+
else if (result == -RT_ERROR)
212+
{
213+
LOG_E("event received error");
214+
return;
215+
}
205216

206217
// Kill and free the resources ... this is safe due to the flag
207218
// from the thread.
@@ -218,15 +229,26 @@ jffs2_garbage_collect_thread(unsigned long data)
218229
struct super_block *sb=OFNI_BS_2SFFJ(c);
219230
cyg_mtab_entry *mte;
220231
rt_uint32_t flag = 0;
232+
rt_err_t result;
221233

222234
D1(printk("jffs2_garbage_collect_thread START\n"));
223235

224236
while(1) {
225-
rt_event_recv(&sb->s_gc_thread_flags,
237+
result = rt_event_recv(&sb->s_gc_thread_flags,
226238
GC_THREAD_FLAG_TRIG | GC_THREAD_FLAG_STOP,
227239
RT_EVENT_FLAG_OR | RT_EVENT_FLAG_CLEAR,
228240
cyg_current_time() + CYGNUM_JFFS2_GS_THREAD_TICKS,
229241
&flag);
242+
if (result == -RT_ETIMEOUT)
243+
{
244+
LOG_E("wait completed timeout");
245+
continue;
246+
}
247+
else if (result == -RT_ERROR)
248+
{
249+
LOG_E("event received error");
250+
continue;
251+
}
230252

231253
if (flag & GC_THREAD_FLAG_STOP)
232254
break;

0 commit comments

Comments
 (0)