diff options
Diffstat (limited to 'nuttx/sched/task_init.c')
-rw-r--r-- | nuttx/sched/task_init.c | 66 |
1 files changed, 50 insertions, 16 deletions
diff --git a/nuttx/sched/task_init.c b/nuttx/sched/task_init.c index 0f0fdc68e..78f35bc2a 100644 --- a/nuttx/sched/task_init.c +++ b/nuttx/sched/task_init.c @@ -1,7 +1,7 @@ /**************************************************************************** * sched/task_init.c * - * Copyright (C) 2007, 2009 Gregory Nutt. All rights reserved. + * Copyright (C) 2007, 2009, 2013 Gregory Nutt. All rights reserved. * Author: Gregory Nutt <gnutt@nuttx.org> * * Redistribution and use in source and binary forms, with or without @@ -42,10 +42,12 @@ #include <sys/types.h> #include <stdint.h> #include <sched.h> +#include <errno.h> + #include <nuttx/arch.h> #include "os_internal.h" -#include "env_internal.h" +#include "group_internal.h" /**************************************************************************** * Definitions @@ -102,10 +104,10 @@ * parameters are required, argv may be NULL. * * Return Value: - * OK on success; ERROR on failure. (See task_schedsetup() for possible - * failure conditions). On failure, the caller is responsible for freeing - * the stack memory and for calling sched_releasetcb() to free the TCB - * (which could be in most any state). + * OK on success; ERROR on failure with errno set appropriately. (See + * task_schedsetup() for possible failure conditions). On failure, the + * caller is responsible for freeing the stack memory and for calling + * sched_releasetcb() to free the TCB (which could be in most any state). * ****************************************************************************/ @@ -118,20 +120,30 @@ int task_init(FAR _TCB *tcb, const char *name, int priority, main_t entry, const char *argv[]) #endif { + int errcode; int ret; - /* Associate file descriptors with the new task */ + /* Create a new task group */ -#if CONFIG_NFILE_DESCRIPTORS > 0 || CONFIG_NSOCKET_DESCRIPTORS > 0 - if (sched_setuptaskfiles(tcb) != OK) +#ifdef HAVE_TASK_GROUP + ret = group_allocate(tcb); + if (ret < 0) { - return ERROR; + errcode = -ret; + goto errout; } #endif - /* Clone the parent's task environment */ + /* Associate file descriptors with the new task */ - (void)env_dup(tcb); +#if CONFIG_NFILE_DESCRIPTORS > 0 || CONFIG_NSOCKET_DESCRIPTORS > 0 + ret = group_setuptaskfiles(tcb); + if (ret < 0) + { + errcode = -ret; + goto errout_with_group; + } +#endif /* Configure the user provided stack region */ @@ -143,13 +155,35 @@ int task_init(FAR _TCB *tcb, const char *name, int priority, ret = task_schedsetup(tcb, priority, task_start, entry, TCB_FLAG_TTYPE_TASK); - if (ret == OK) + if (ret < OK) { - /* Setup to pass parameters to the new task */ + errcode = -ret; + goto errout_with_group; + } + + /* Setup to pass parameters to the new task */ + + (void)task_argsetup(tcb, name, argv); + + /* Now we have enough in place that we can join the group */ - (void)task_argsetup(tcb, name, argv); +#ifdef HAVE_TASK_GROUP + ret = group_initialize(tcb); + if (ret < 0) + { + errcode = -ret; + goto errout_with_group; } +#endif + return OK; - return ret; +errout_with_group: +#ifdef HAVE_TASK_GROUP + group_leave(tcb); + +errout: +#endif + set_errno(errcode); + return ERROR; } |