Skip to content

[kernel][mutex]fix assertion error when thread wakeup while waiting mutex #9357

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions src/ipc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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);

/**
Expand Down
Loading