diff --git a/src/ipc.c b/src/ipc.c index 5ffcf017c2c..9eb85d8d5e4 100644 --- a/src/ipc.c +++ b/src/ipc.c @@ -1448,13 +1448,12 @@ static rt_err_t _rt_mutex_take(rt_mutex_t mutex, rt_int32_t timeout, int suspend rt_spin_lock(&(mutex->spinlock)); - if (thread->error == RT_EOK) + if (mutex->owner == thread) { /** * get mutex successfully - * Note: assert to avoid an unexpected resume */ - RT_ASSERT(mutex->owner == thread); + RT_ASSERT(thread->error == RT_EOK); } else { @@ -1466,6 +1465,12 @@ static rt_err_t _rt_mutex_take(rt_mutex_t mutex, rt_int32_t timeout, int suspend /* get value first before calling to other APIs */ ret = thread->error; + /* unexpected resume */ + if (ret == RT_EOK) + { + ret = -RT_EINTR; + } + rt_sched_lock(&slvl); /**