Skip to content

Commit 160fd84

Browse files
committed
fix assertion error when thread wakeup while waiting mutex
1 parent 2598a9c commit 160fd84

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

Diff for: src/ipc.c

+8-2
Original file line numberDiff line numberDiff line change
@@ -1450,13 +1450,13 @@ static rt_err_t _rt_mutex_take(rt_mutex_t mutex, rt_int32_t timeout, int suspend
14501450

14511451
rt_spin_lock(&(mutex->spinlock));
14521452

1453-
if (thread->error == RT_EOK)
1453+
if (mutex->owner == thread)
14541454
{
14551455
/**
14561456
* get mutex successfully
14571457
* Note: assert to avoid an unexpected resume
14581458
*/
1459-
RT_ASSERT(mutex->owner == thread);
1459+
RT_ASSERT(thread->error == RT_EOK);
14601460
}
14611461
else
14621462
{
@@ -1468,6 +1468,12 @@ static rt_err_t _rt_mutex_take(rt_mutex_t mutex, rt_int32_t timeout, int suspend
14681468
/* get value first before calling to other APIs */
14691469
ret = thread->error;
14701470

1471+
/* unexpected resume */
1472+
if (ret == RT_EOK)
1473+
{
1474+
ret = -RT_EINTR;
1475+
}
1476+
14711477
rt_sched_lock(&slvl);
14721478

14731479
/**

0 commit comments

Comments
 (0)