Skip to content

fixup: ipc: protect taken_list on shared lock #9368

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

Merged
merged 1 commit into from
Sep 4, 2024
Merged
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
26 changes: 14 additions & 12 deletions src/ipc.c
Original file line number Diff line number Diff line change
Expand Up @@ -945,28 +945,30 @@ static rt_bool_t _check_and_update_prio(rt_thread_t thread, rt_mutex_t mutex)
static void _mutex_before_delete_detach(rt_mutex_t mutex)
{
rt_sched_lock_level_t slvl;
rt_bool_t need_schedule;
rt_bool_t need_schedule = RT_FALSE;

rt_spin_lock(&(mutex->spinlock));
/* wakeup all suspended threads */
rt_susp_list_resume_all(&(mutex->parent.suspend_thread), RT_ERROR);

rt_sched_lock(&slvl);

/* remove mutex from thread's taken list */
rt_list_remove(&mutex->taken_list);

/* whether change the thread priority */
if (mutex->owner)
{
rt_sched_lock(&slvl);
need_schedule = _check_and_update_prio(mutex->owner, mutex);
}

if (need_schedule)
{
rt_sched_unlock_n_resched(slvl);
}
else
{
rt_sched_unlock(slvl);
}
if (need_schedule)
{
rt_sched_unlock_n_resched(slvl);
}
else
{
rt_sched_unlock(slvl);
}

/* unlock and do necessary reschedule if required */
Expand Down Expand Up @@ -1617,11 +1619,11 @@ rt_err_t rt_mutex_release(rt_mutex_t mutex)
/* if no hold */
if (mutex->hold == 0)
{
rt_sched_lock(&slvl);

/* remove mutex from thread's taken list */
rt_list_remove(&mutex->taken_list);

rt_sched_lock(&slvl);

/* whether change the thread priority */
need_schedule = _check_and_update_prio(thread, mutex);

Expand Down
Loading