Skip to content

Commit d2160d3

Browse files
authored
fixup: ipc: protect taken_list on shared lock
为什么提交这份PR (why to submit this PR) Issue: using iperf server with sshd together and the kernel will get stuck occasionally. taken_list is accessed from other mutex when updating priority. 你的解决方案是什么 (what is your solution) protect taken_list on shared lock, but not on mutex local spinlock. Signed-off-by: Shell <[email protected]>
1 parent cea7670 commit d2160d3

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

src/ipc.c

+14-12
Original file line numberDiff line numberDiff line change
@@ -945,28 +945,30 @@ static rt_bool_t _check_and_update_prio(rt_thread_t thread, rt_mutex_t mutex)
945945
static void _mutex_before_delete_detach(rt_mutex_t mutex)
946946
{
947947
rt_sched_lock_level_t slvl;
948-
rt_bool_t need_schedule;
948+
rt_bool_t need_schedule = RT_FALSE;
949949

950950
rt_spin_lock(&(mutex->spinlock));
951951
/* wakeup all suspended threads */
952952
rt_susp_list_resume_all(&(mutex->parent.suspend_thread), RT_ERROR);
953+
954+
rt_sched_lock(&slvl);
955+
953956
/* remove mutex from thread's taken list */
954957
rt_list_remove(&mutex->taken_list);
955958

956959
/* whether change the thread priority */
957960
if (mutex->owner)
958961
{
959-
rt_sched_lock(&slvl);
960962
need_schedule = _check_and_update_prio(mutex->owner, mutex);
963+
}
961964

962-
if (need_schedule)
963-
{
964-
rt_sched_unlock_n_resched(slvl);
965-
}
966-
else
967-
{
968-
rt_sched_unlock(slvl);
969-
}
965+
if (need_schedule)
966+
{
967+
rt_sched_unlock_n_resched(slvl);
968+
}
969+
else
970+
{
971+
rt_sched_unlock(slvl);
970972
}
971973

972974
/* unlock and do necessary reschedule if required */
@@ -1617,11 +1619,11 @@ rt_err_t rt_mutex_release(rt_mutex_t mutex)
16171619
/* if no hold */
16181620
if (mutex->hold == 0)
16191621
{
1622+
rt_sched_lock(&slvl);
1623+
16201624
/* remove mutex from thread's taken list */
16211625
rt_list_remove(&mutex->taken_list);
16221626

1623-
rt_sched_lock(&slvl);
1624-
16251627
/* whether change the thread priority */
16261628
need_schedule = _check_and_update_prio(thread, mutex);
16271629

0 commit comments

Comments
 (0)