int task_init(FAR _TCB *tcb, const char *name, int priority, main_t entry, const char *argv[]) #endif { int ret; /* Associate file descriptors with the new task */ #if CONFIG_NFILE_DESCRIPTORS > 0 || CONFIG_NSOCKET_DESCRIPTORS > 0 if (sched_setuptaskfiles(tcb) != OK) { return ERROR; } #endif /* Clone the parent's task environment */ (void)env_dup(tcb); /* Configure the user provided stack region */ #ifndef CONFIG_CUSTOM_STACK up_use_stack(tcb, stack, stack_size); #endif /* Initialize the task control block */ ret = task_schedsetup(tcb, priority, task_start, entry, TCB_FLAG_TTYPE_TASK); if (ret == OK) { /* Setup to pass parameters to the new task */ (void)task_argsetup(tcb, name, argv); } return ret; }
int task_init(FAR struct tcb_s *tcb, const char *name, int priority, FAR uint32_t *stack, uint32_t stack_size, main_t entry, FAR char * const argv[]) { FAR struct task_tcb_s *ttcb = (FAR struct task_tcb_s *)tcb; int errcode; int ret; /* Only tasks and kernel threads can be initialized in this way */ #ifndef CONFIG_DISABLE_PTHREAD DEBUGASSERT(tcb && (tcb->flags & TCB_FLAG_TTYPE_MASK) != TCB_FLAG_TTYPE_PTHREAD); #endif /* Create a new task group */ #ifdef HAVE_TASK_GROUP ret = group_allocate(ttcb, tcb->flags); if (ret < 0) { errcode = -ret; goto errout; } #endif /* Associate file descriptors with the new task */ #if CONFIG_NFILE_DESCRIPTORS > 0 || CONFIG_NSOCKET_DESCRIPTORS > 0 ret = group_setuptaskfiles(ttcb); if (ret < 0) { errcode = -ret; goto errout_with_group; } #endif /* Configure the user provided stack region */ up_use_stack(tcb, stack, stack_size); /* Initialize the task control block */ ret = task_schedsetup(ttcb, priority, task_start, entry, TCB_FLAG_TTYPE_TASK); if (ret < OK) { errcode = -ret; goto errout_with_group; } /* Setup to pass parameters to the new task */ (void)task_argsetup(ttcb, name, argv); /* Now we have enough in place that we can join the group */ #ifdef HAVE_TASK_GROUP ret = group_initialize(ttcb); if (ret < 0) { errcode = -ret; goto errout_with_group; } #endif return OK; errout_with_group: #ifdef HAVE_TASK_GROUP group_leave(tcb); errout: #endif set_errno(errcode); return ERROR; }