diff options
Diffstat (limited to 'nuttx/sched/task_setup.c')
-rw-r--r-- | nuttx/sched/task_setup.c | 43 |
1 files changed, 40 insertions, 3 deletions
diff --git a/nuttx/sched/task_setup.c b/nuttx/sched/task_setup.c index a37fb165a..92897f0ae 100644 --- a/nuttx/sched/task_setup.c +++ b/nuttx/sched/task_setup.c @@ -147,6 +147,37 @@ static int task_assignpid(FAR _TCB *tcb) } /**************************************************************************** + * Name: task_saveparent + * + * Description: + * Save the task ID of the parent task in the child task's TCB. + * + * Parameters: + * tcb - The TCB of the new, child task. + * + * Returned Value: + * None + * + * Assumptions: + * The parent of the new task is the task at the head of the ready-to-run + * list. + * + ****************************************************************************/ + +#ifdef CONFIG_SCHED_HAVE_PARENT +static inline void task_saveparent(FAR _TCB *tcb) +{ + FAR _TCB *rtcb = (FAR _TCB*)g_readytorun.head; + + DEBUGASSERT(rtcb->nchildren < UINT16_MAX); + tcb->parent = rtcb->pid; + rtcb->nchildren++; +} +#else +# define task_saveparent(tcb) +#endif + +/**************************************************************************** * Name: task_dupdspace * * Description: @@ -161,6 +192,8 @@ static int task_assignpid(FAR _TCB *tcb) * None * * Assumptions: + * The parent of the new task is the task at the head of the ready-to-run + * list. * ****************************************************************************/ @@ -231,8 +264,12 @@ int task_schedsetup(FAR _TCB *tcb, int priority, start_t start, main_t main) tcb->start = start; tcb->entry.main = main; - /* exec() and pthread_create() inherit the signal mask of the - * parent thread. I suppose that task_create() should as well. + /* Save the task ID of the parent task in the TCB */ + + task_saveparent(tcb); + + /* exec(), pthread_create(), task_create(), and vfork() all + * inherit the signal mask of the parent thread. */ #ifndef CONFIG_DISABLE_SIGNALS @@ -243,7 +280,7 @@ int task_schedsetup(FAR _TCB *tcb, int priority, start_t start, main_t main) * until it is activated. */ - tcb->task_state = TSTATE_TASK_INVALID; + tcb->task_state = TSTATE_TASK_INVALID; /* Clone the parent tasks D-Space (if it was running PIC). This * must be done before calling up_initial_state() so that the |