diff --git a/sched/sched/sched_waitid.c b/sched/sched/sched_waitid.c index b8fb630b9c3..20019342af1 100644 --- a/sched/sched/sched_waitid.c +++ b/sched/sched/sched_waitid.c @@ -143,6 +143,14 @@ int nx_waitid(int idtype, id_t id, FAR siginfo_t *info, int options) sigemptyset(&set); nxsig_addset(&set, SIGCHLD); + /* NOTE: sched_lock() is not enough for SMP + * because the child task is running on another CPU + */ + +#ifdef CONFIG_SMP + irqstate_t flags = enter_critical_section(); +#endif + /* Disable pre-emption so that nothing changes while the loop executes */ sched_lock(); @@ -379,6 +387,11 @@ int nx_waitid(int idtype, id_t id, FAR siginfo_t *info, int options) errout: sched_unlock(); + +#ifdef CONFIG_SMP + leave_critical_section(flags); +#endif + return ret; } diff --git a/sched/sched/sched_waitpid.c b/sched/sched/sched_waitpid.c index b23a68ecd95..0dd7de6ca51 100644 --- a/sched/sched/sched_waitpid.c +++ b/sched/sched/sched_waitpid.c @@ -72,6 +72,14 @@ pid_t nx_waitpid(pid_t pid, int *stat_loc, int options) DEBUGASSERT(stat_loc); + /* NOTE: sched_lock() is not enough for SMP + * because the child task is running on another CPU + */ + +#ifdef CONFIG_SMP + irqstate_t flags = enter_critical_section(); +#endif + /* Disable pre-emption so that nothing changes in the following tests */ sched_lock(); @@ -158,11 +166,15 @@ pid_t nx_waitpid(pid_t pid, int *stat_loc, int options) /* On success, return the PID */ - sched_unlock(); - return pid; + ret = pid; errout: sched_unlock(); + +#ifdef CONFIG_SMP + leave_critical_section(flags); +#endif + return ret; } @@ -199,6 +211,14 @@ pid_t nx_waitpid(pid_t pid, int *stat_loc, int options) sigemptyset(&set); nxsig_addset(&set, SIGCHLD); + /* NOTE: sched_lock() is not enough for SMP + * because the child task is running on another CPU + */ + +#ifdef CONFIG_SMP + irqstate_t flags = enter_critical_section(); +#endif + /* Disable pre-emption so that nothing changes while the loop executes */ sched_lock(); @@ -438,11 +458,17 @@ pid_t nx_waitpid(pid_t pid, int *stat_loc, int options) } } - sched_unlock(); - return pid; + /* On success, return the PID */ + + ret = pid; errout: sched_unlock(); + +#ifdef CONFIG_SMP + leave_critical_section(flags); +#endif + return ret; } #endif /* CONFIG_SCHED_HAVE_PARENT */ diff --git a/sched/task/task_exithook.c b/sched/task/task_exithook.c index 8b9ff31d8dd..9b9477c0f32 100644 --- a/sched/task/task_exithook.c +++ b/sched/task/task_exithook.c @@ -634,6 +634,12 @@ void nxtask_exithook(FAR struct tcb_s *tcb, int status, bool nonblocking) nxtask_recover(tcb); + /* NOTE: signal handling needs to be done in a criticl section */ + +#ifdef CONFIG_SMP + irqstate_t flags = enter_critical_section(); +#endif + /* Send the SIGCHLD signal to the parent task group */ nxtask_signalparent(tcb, status); @@ -668,6 +674,10 @@ void nxtask_exithook(FAR struct tcb_s *tcb, int status, bool nonblocking) nxsig_cleanup(tcb); /* Deallocate Signal lists */ +#ifdef CONFIG_SMP + leave_critical_section(flags); +#endif + /* This function can be re-entered in certain cases. Set a flag * bit in the TCB to not that we have already completed this exit * processing.