diff options
Diffstat (limited to 'nuttx/sched')
-rw-r--r-- | nuttx/sched/os_internal.h | 2 | ||||
-rw-r--r-- | nuttx/sched/pthread_create.c | 72 | ||||
-rw-r--r-- | nuttx/sched/task_create.c | 2 | ||||
-rw-r--r-- | nuttx/sched/task_init.c | 2 | ||||
-rw-r--r-- | nuttx/sched/task_setup.c | 65 |
5 files changed, 92 insertions, 51 deletions
diff --git a/nuttx/sched/os_internal.h b/nuttx/sched/os_internal.h index ca2222ad6..0fa7172b5 100644 --- a/nuttx/sched/os_internal.h +++ b/nuttx/sched/os_internal.h @@ -243,7 +243,7 @@ extern void task_start(void); extern STATUS task_schedsetup(FAR _TCB *tcb, int priority, start_t start, main_t main); extern STATUS task_argsetup(FAR _TCB *tcb, const char *name, - boolean pthread, char *argv[]); + char *argv[]); extern boolean sched_addreadytorun(FAR _TCB *rtrtcb); extern boolean sched_removereadytorun(FAR _TCB *rtrtcb); diff --git a/nuttx/sched/pthread_create.c b/nuttx/sched/pthread_create.c index 33fdcf00f..4346a6f65 100644 --- a/nuttx/sched/pthread_create.c +++ b/nuttx/sched/pthread_create.c @@ -75,11 +75,74 @@ FAR pthread_attr_t g_default_pthread_attr = * Private Variables ************************************************************/ +/* This is the name for name-less pthreads */ + +static const char g_pthreadname[] = "<pthread>"; + /************************************************************ * Private Functions ************************************************************/ /************************************************************ + * Name: pthread_argsetup + * + * Description: + * This functions sets up parameters in the Task Control + * Block (TCB) in preparation for starting a new thread. + * + * pthread_argsetup() is called from task_init() and task_start() + * to create a new task (with arguments cloned via strdup) + * or pthread_create() which has one argument passed by + * value (distinguished by the pthread boolean argument). + * + * Input Parameters: + * tcb - Address of the new task's TCB + * name - Name of the new task (not used) + * argv - A pointer to an array of input parameters. + * Up to CONFIG_MAX_TASK_ARG parameters may be + * provided. If fewer than CONFIG_MAX_TASK_ARG + * parameters are passed, the list should be + * terminated with a NULL argv[] value. + * If no parameters are required, argv may be NULL. + * + * Return Value: + * OK + * + ************************************************************/ + +static void pthread_argsetup(FAR _TCB *tcb, pthread_addr_t arg) +{ + int i; + +#if CONFIG_TASK_NAME_SIZE > 0 + /* Copy the pthread name into the TCB */ + + strncpy(tcb->name, g_pthreadname, CONFIG_TASK_NAME_SIZE); + + /* Save the name as the first argument in the TCB */ + + tcb->argv[0] = tcb->name; +#else + /* Save the name as the first argument in the TCB */ + + tcb->argv[0] = (char *)g_pthreadname; +#endif /* CONFIG_TASK_NAME_SIZE */ + + /* For pthreads, args are strictly pass-by-value; that actual + * type wrapped by pthread_addr_t is unknown. + */ + + tcb->argv[1] = (char*)arg; + + /* Nullify the remaining, unused argument storage */ + + for (i = 2; i < CONFIG_MAX_TASK_ARGS+1; i++) + { + tcb->argv[i] = NULL; + } +} + +/************************************************************ * Function: pthread_addjoininfo * * Description: @@ -178,7 +241,6 @@ int pthread_create(pthread_t *thread, pthread_attr_t *attr, FAR _TCB *ptcb; FAR join_t *pjoin; STATUS status; - char *argv[2]; int priority; #if CONFIG_RR_INTERVAL > 0 int policy; @@ -280,13 +342,15 @@ int pthread_create(pthread_t *thread, pthread_attr_t *attr, return ERROR; } + /* Mark this task as a pthread */ + + ptcb->flags |= TCB_FLAG_PTHREAD; + /* Configure the TCB for a pthread receiving on parameter * passed by value */ - argv[0] = (char *)arg; - argv[1] = NULL; - (void)task_argsetup(ptcb, NULL, TRUE, argv); + (void)pthread_argsetup(ptcb, arg); /* Attach the join info to the TCB. */ diff --git a/nuttx/sched/task_create.c b/nuttx/sched/task_create.c index c3d1b453b..04313c499 100644 --- a/nuttx/sched/task_create.c +++ b/nuttx/sched/task_create.c @@ -159,7 +159,7 @@ int task_create(const char *name, int priority, /* Setup to pass parameters to the new task */ - (void)task_argsetup(tcb, name, FALSE, argv); + (void)task_argsetup(tcb, name, argv); /* Get the assigned pid before we start the task */ diff --git a/nuttx/sched/task_init.c b/nuttx/sched/task_init.c index 92fd53fb2..f1dc42292 100644 --- a/nuttx/sched/task_init.c +++ b/nuttx/sched/task_init.c @@ -127,7 +127,7 @@ STATUS task_init(FAR _TCB *tcb, const char *name, int priority, { /* Setup to pass parameters to the new task */ - (void)task_argsetup(tcb, name, FALSE, argv); + (void)task_argsetup(tcb, name, argv); } return ret; } diff --git a/nuttx/sched/task_setup.c b/nuttx/sched/task_setup.c index 744f5fbf4..fbce5fcee 100644 --- a/nuttx/sched/task_setup.c +++ b/nuttx/sched/task_setup.c @@ -64,13 +64,13 @@ /* This is the name for un-named tasks */ -static const char g_noname[] = "no name"; +static const char g_noname[] = "<noname>"; /************************************************************ * Private Function Prototypes ************************************************************/ -static STATUS task_assignpid(FAR _TCB* tcb); +static STATUS task_assignpid(FAR _TCB* tcb); /************************************************************ * Private Functions @@ -216,15 +216,13 @@ STATUS task_schedsetup(FAR _TCB *tcb, int priority, * This functions sets up parameters in the Task Control * Block (TCB) in preparation for starting a new thread. * - * task_argsetup() is called from task_init() and task_start() - * to create a new task (with arguments cloned via strdup) - * or pthread_create() which has one argument passed by - * value (distinguished by the pthread boolean argument). + * task_argsetup() is called only from task_init() and + * task_start() to create a new task. Argumens are + * cloned via strdup. * * Input Parameters: * tcb - Address of the new task's TCB * name - Name of the new task (not used) - * pthread - TRUE is the task emulates pthread behavior * argv - A pointer to an array of input parameters. * Up to CONFIG_MAX_TASK_ARG parameters may be * provided. If fewer than CONFIG_MAX_TASK_ARG @@ -237,69 +235,48 @@ STATUS task_schedsetup(FAR _TCB *tcb, int priority, * ************************************************************/ -STATUS task_argsetup(FAR _TCB *tcb, const char *name, - boolean pthread, char *argv[]) +STATUS task_argsetup(FAR _TCB *tcb, const char *name, char *argv[]) { int i; #if CONFIG_TASK_NAME_SIZE > 0 - /* Give a name to the unnamed threads */ + /* Give a name to the unnamed tasks */ if (!name) { name = (char *)g_noname; } - /* copy the name into the TCB */ + /* Copy the name into the TCB */ strncpy(tcb->name, name, CONFIG_TASK_NAME_SIZE); -#endif /* CONFIG_TASK_NAME_SIZE */ - /* Save the arguments in the TCB */ + /* Save the name as the first argument */ -#if CONFIG_TASK_NAME_SIZE > 0 tcb->argv[0] = tcb->name; #else + /* Save the name as the first argument */ + tcb->argv[0] = (char *)g_noname; -#endif +#endif /* CONFIG_TASK_NAME_SIZE */ - /* For pthreads, args are strictly pass-by-value; the char* - * arguments wrap some unknown value cast to char*. However, - * for tasks, the life of the argument must be as long as + /* For tasks, the life of the argument must be as long as * the life of the task and the arguments must be strings. * So for tasks, we have to to dup the strings. + * + * The first NULL argument terminates the list of + * arguments. The argv pointer may be NULL if no + * parameters are passed. */ - if (!pthread) + i = 1; + if (argv) { - /* The first NULL argument terminates the list of - * arguments. The argv pointer may be NULL if no - * parameters are passed. - */ - - i = 1; - if (argv) + for (; i < CONFIG_MAX_TASK_ARGS+1 && argv[i-1]; i++) { - for (; i < CONFIG_MAX_TASK_ARGS+1 && argv[i-1]; i++) - { - tcb->argv[i] = strdup(argv[i-1]); - } + tcb->argv[i] = strdup(argv[i-1]); } } - else - { - /* Mark this task as a pthread */ - - tcb->flags |= TCB_FLAG_PTHREAD; - - /* And just copy the argument. For pthreads, there - * is really only a single argument, argv[0]. It is - * copied as a value -- NOT duplicated. - */ - - i = 2; - tcb->argv[1] = argv[0]; - } /* Nullify any unused argument storage */ |