diff options
author | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2007-03-11 17:37:47 +0000 |
---|---|---|
committer | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2007-03-11 17:37:47 +0000 |
commit | 6877a8efaf6edad7dcff6412c1eb03973d080247 (patch) | |
tree | 700904d10859106a5fe5d49650d3ff89d9e5ea94 /nuttx/sched | |
parent | 8404d53e7285cad8c64992658a84a3d6809cef27 (diff) | |
download | px4-nuttx-6877a8efaf6edad7dcff6412c1eb03973d080247.tar.gz px4-nuttx-6877a8efaf6edad7dcff6412c1eb03973d080247.tar.bz2 px4-nuttx-6877a8efaf6edad7dcff6412c1eb03973d080247.zip |
task_create now accepts variable number of arguments; 8051 bringup changes
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@56 42af7a65-404d-4744-a932-0658087f49c3
Diffstat (limited to 'nuttx/sched')
-rw-r--r-- | nuttx/sched/os_internal.h | 6 | ||||
-rw-r--r-- | nuttx/sched/os_start.c | 4 | ||||
-rw-r--r-- | nuttx/sched/pthread_create.c | 7 | ||||
-rw-r--r-- | nuttx/sched/sched_foreach.c | 1 | ||||
-rw-r--r-- | nuttx/sched/sched_releasetcb.c | 4 | ||||
-rw-r--r-- | nuttx/sched/sched_setuptaskfiles.c | 2 | ||||
-rw-r--r-- | nuttx/sched/task_create.c | 61 | ||||
-rw-r--r-- | nuttx/sched/task_init.c | 14 |
8 files changed, 48 insertions, 51 deletions
diff --git a/nuttx/sched/os_internal.h b/nuttx/sched/os_internal.h index 26a709a99..222e0ba88 100644 --- a/nuttx/sched/os_internal.h +++ b/nuttx/sched/os_internal.h @@ -241,10 +241,8 @@ extern const tasklist_t g_tasklisttable[NUM_TASK_STATES]; extern void task_start(void); extern STATUS _task_init(FAR _TCB *tcb, const char *name, int priority, - start_t start, main_t main, - boolean pthread, - FAR char *arg1, FAR char *arg2, - FAR char *arg3, FAR char *arg4); + start_t start, main_t main, boolean pthread, + char *argv[]); extern boolean sched_addreadytorun(FAR _TCB *rtrtcb); extern boolean sched_removereadytorun(FAR _TCB *rtrtcb); diff --git a/nuttx/sched/os_start.c b/nuttx/sched/os_start.c index 18b8945ee..9036f17bd 100644 --- a/nuttx/sched/os_start.c +++ b/nuttx/sched/os_start.c @@ -408,10 +408,10 @@ void os_start(void) #ifndef CONFIG_CUSTOM_STACK init_taskid = task_create("init", SCHED_PRIORITY_DEFAULT, CONFIG_PROC_STACK_SIZE, - (main_t)user_start, 0, 0, 0, 0); + (main_t)user_start, (char **)NULL); #else init_taskid = task_create("init", SCHED_PRIORITY_DEFAULT, - (main_t)user_start, 0, 0, 0, 0); + (main_t)user_start, (char **)NULL); #endif ASSERT(init_taskid != ERROR); diff --git a/nuttx/sched/pthread_create.c b/nuttx/sched/pthread_create.c index ebf212516..72a5b4a81 100644 --- a/nuttx/sched/pthread_create.c +++ b/nuttx/sched/pthread_create.c @@ -178,6 +178,7 @@ 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; @@ -269,8 +270,10 @@ int pthread_create(pthread_t *thread, pthread_attr_t *attr, /* Initialize the task */ - status = _task_init(ptcb, NULL, priority, pthread_start, (main_t)startRoutine, - TRUE, (FAR char*)arg, NULL, NULL, NULL); + argv[0] = (char *)arg; + argv[1] = NULL; + status = _task_init(ptcb, NULL, priority, pthread_start, + (main_t)startRoutine, TRUE, argv); if (status != OK) { diff --git a/nuttx/sched/sched_foreach.c b/nuttx/sched/sched_foreach.c index f1c1dc05c..f66284685 100644 --- a/nuttx/sched/sched_foreach.c +++ b/nuttx/sched/sched_foreach.c @@ -65,7 +65,6 @@ void sched_foreach(sched_foreach_t handler, FAR void *arg) { - FAR _TCB *tcb; irqstate_t flags = irqsave(); int ndx; diff --git a/nuttx/sched/sched_releasetcb.c b/nuttx/sched/sched_releasetcb.c index 6415fba2b..e37e2bab3 100644 --- a/nuttx/sched/sched_releasetcb.c +++ b/nuttx/sched/sched_releasetcb.c @@ -123,9 +123,9 @@ int sched_releasetcb(FAR _TCB *tcb) if ((tcb->flags & TCB_FLAG_PTHREAD) == 0) { - for (i = 1; i < NUM_TASK_ARGS+1 && tcb->argv[i]; i++) + for (i = 1; i < CONFIG_MAX_TASK_ARGS+1 && tcb->argv[i]; i++) { - sched_free(tcb->argv[i]); + sched_free((FAR void*)tcb->argv[i]); } } diff --git a/nuttx/sched/sched_setuptaskfiles.c b/nuttx/sched/sched_setuptaskfiles.c index 25275e89b..2aee2e3d1 100644 --- a/nuttx/sched/sched_setuptaskfiles.c +++ b/nuttx/sched/sched_setuptaskfiles.c @@ -99,7 +99,7 @@ int sched_setuptaskfiles(FAR _TCB *tcb) } #if CONFIG_NFILE_STREAMS > 0 - /* Allocate file strems for the TCB */ + /* Allocate file streams for the TCB */ return sched_setupstreams(tcb); #else diff --git a/nuttx/sched/task_create.c b/nuttx/sched/task_create.c index 7b73c15fa..70e220fdd 100644 --- a/nuttx/sched/task_create.c +++ b/nuttx/sched/task_create.c @@ -170,7 +170,7 @@ void task_start(void) /* Count how many non-null arguments we are passing */ - for (argc = 1; argc <= NUM_TASK_ARGS; argc++) + for (argc = 1; argc <= CONFIG_MAX_TASK_ARGS; argc++) { /* The first non-null argument terminates the list */ @@ -212,8 +212,12 @@ void task_start(void) * entry - Entry point of a new task * main - Application start point of the new task * pthread - TRUE is the task emulates pthread behavior - * arg1-4 - Four required task arguments to pass to - * the task when it is started. + * 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 on success; ERROR on failure. @@ -225,10 +229,10 @@ void task_start(void) STATUS _task_init(FAR _TCB *tcb, const char *name, int priority, start_t start, main_t main, boolean pthread, - FAR char *arg1, FAR char *arg2, - FAR char *arg3, FAR char *arg4) + char *argv[]) { STATUS ret; + int i; /* Assign a unique task ID to the task. */ @@ -273,23 +277,16 @@ STATUS _task_init(FAR _TCB *tcb, const char *name, int priority, if (!pthread) { /* The first NULL argument terminates the list of - * arguments. + * arguments. The argv pointer may be NULL if no + * parameters are passed. */ - if (arg1) + i = 1; + if (argv) { - tcb->argv[1] = strdup(arg1); - if (arg2) + for (; i < CONFIG_MAX_TASK_ARGS+1 && argv[i-1]; i++) { - tcb->argv[2] = strdup(arg2); - if (arg3) - { - tcb->argv[3] = strdup(arg3); - if (arg4) - { - tcb->argv[4] = strdup(arg4); - } - } + tcb->argv[i] = strdup(argv[i-1]); } } } @@ -299,14 +296,20 @@ STATUS _task_init(FAR _TCB *tcb, const char *name, int priority, tcb->flags |= TCB_FLAG_PTHREAD; - /* And just copy the argument. (For pthreads, there - * is really only a single argument, arg1). + /* And just copy the argument. For pthreads, there + * is really only a single argument, argv[0]. It is + * copy as a value -- NOT duplicated. */ - tcb->argv[1] = arg1; - tcb->argv[2] = arg2; - tcb->argv[3] = arg3; - tcb->argv[4] = arg4; + i = 2; + tcb->argv[1] = argv[0]; + } + + /* Nullify any unused argument storage */ + + for (; i < CONFIG_MAX_TASK_ARGS+1; i++) + { + tcb->argv[i] = NULL; } /* Initialize other (non-zero) elements of the TCB */ @@ -409,14 +412,10 @@ STATUS task_activate(FAR _TCB *tcb) #ifndef CONFIG_CUSTOM_STACK int task_create(const char *name, int priority, - int stack_size, main_t entry, - FAR char *arg1, FAR char *arg2, - FAR char *arg3, FAR char *arg4) + int stack_size, main_t entry, char *argv[]) #else int task_create(const char *name, int priority, - main_t entry, - FAR char *arg1, FAR char *arg2, - FAR char *arg3, FAR char *arg4) + main_t entry, char *argv[]) #endif { FAR _TCB *tcb; @@ -454,7 +453,7 @@ int task_create(const char *name, int priority, /* Initialize the task control block */ status = _task_init(tcb, name, priority, task_start, entry, - FALSE, arg1, arg2, arg3, arg4); + FALSE, argv); if (status != OK) { sched_releasetcb(tcb); diff --git a/nuttx/sched/task_init.c b/nuttx/sched/task_init.c index 17596378b..b603ddc80 100644 --- a/nuttx/sched/task_init.c +++ b/nuttx/sched/task_init.c @@ -39,6 +39,7 @@ #include <sys/types.h> #include <sched.h> +#include <nuttx/arch.h> #include "os_internal.h" /************************************************************ @@ -94,21 +95,18 @@ #ifndef CONFIG_CUSTOM_STACK STATUS task_init(FAR _TCB *tcb, const char *name, int priority, - FAR uint32 *stack, uint32 stack_size, main_t entry, - FAR char *arg1, FAR char *arg2, - FAR char *arg3, FAR char *arg4) + FAR uint32 *stack, uint32 stack_size, + main_t entry, char *argv[]) { up_use_stack(tcb, stack, stack_size); return _task_init(tcb, name, priority, task_start, entry, - FALSE, arg1, arg2, arg3, arg4); + FALSE, argv); } #else STATUS task_init(FAR _TCB *tcb, const char *name, int priority, - main_t entry, - FAR char *arg1, FAR char *arg2, - FAR char *arg3, FAR char *arg4) + main_t entry, char *argv[]) { return _task_init(tcb, name, priority, task_start, entry, - FALSE, arg1, arg2, arg3, arg4); + FALSE, argv); } #endif |