sched: group: Fix group_kill_children() for SMP

Summary:
- During testing iperf -s with lc823450-xgevk:rndis,
  I noticed that hard fault happens
- Finally, I found that group_kill_children() is not
  not protected by a critical section
- This commit fixes this issue

Impact:
- SMP only

Testing:
- Tested with iperf with the following configurations
- lc823450-xgevk:rndis, spresense:rndis_smp
- Tested with ostest with the following configurations
- lc823450-xgevk:rndis, esp32-devkitc:smp (QEMU)
- sabre-6quad:smp (QEMU), maix-bit:smp (QEMU)
- spresense:rndis_smp, sim:smp

Signed-off-by: Masayuki Ishikawa <Masayuki.Ishikawa@jp.sony.com>
This commit is contained in:
Masayuki Ishikawa 2021-02-03 09:34:14 +09:00 committed by Xiang Xiao
parent 18ce105e8b
commit 82efbd5e6f

View File

@ -131,14 +131,26 @@ int group_kill_children(FAR struct tcb_s *tcb)
{
int ret;
#ifdef CONFIG_SMP
/* NOTE: sched_lock() is not enough for SMP
* because tcb->group will be accessed from the child tasks
*/
irqstate_t flags = enter_critical_section();
#else
/* Lock the scheduler so that there this thread will not lose priority
* until all of its children are suspended.
*/
sched_lock();
#endif
ret = group_foreachchild(tcb->group, group_kill_children_handler,
(FAR void *)((uintptr_t)tcb->pid));
#ifdef CONFIG_SMP
leave_critical_section(flags);
#else
sched_unlock();
#endif
return ret;
}