diff options
author | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2012-07-11 02:43:12 +0000 |
---|---|---|
committer | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2012-07-11 02:43:12 +0000 |
commit | 018badad37fb444f4ed0373a1d68136aed608d2a (patch) | |
tree | a4d26f67a939ca59707f0baf5661dc79253c0edf /apps/namedapp/exec_namedapp.c | |
parent | d9b1d147a8a13b473965a04b0edeb41cd274cc4f (diff) | |
download | px4-nuttx-018badad37fb444f4ed0373a1d68136aed608d2a.tar.gz px4-nuttx-018badad37fb444f4ed0373a1d68136aed608d2a.tar.bz2 px4-nuttx-018badad37fb444f4ed0373a1d68136aed608d2a.zip |
Correct an error in named application priority when SCHED_RR is enabled
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@4928 42af7a65-404d-4744-a932-0658087f49c3
Diffstat (limited to 'apps/namedapp/exec_namedapp.c')
-rw-r--r-- | apps/namedapp/exec_namedapp.c | 67 |
1 files changed, 50 insertions, 17 deletions
diff --git a/apps/namedapp/exec_namedapp.c b/apps/namedapp/exec_namedapp.c index 75e5b83d0..264fca7b9 100644 --- a/apps/namedapp/exec_namedapp.c +++ b/apps/namedapp/exec_namedapp.c @@ -122,33 +122,66 @@ int namedapp_isavail(FAR const char *appname) * Execute the application with name 'appname', providing the arguments * in the argv[] array. * + * Returned Value: + * On success, the task ID of the named application is returned. On + * failure, -1 (ERROR) is returned an the errno value is set appropriately. + * ****************************************************************************/ int exec_namedapp(FAR const char *appname, FAR const char **argv) { - int i; - - if ((i = namedapp_isavail(appname)) >= 0) + pid_t pid; + int index; + + /* Verify that an application with this name exists */ + + index = namedapp_isavail(appname); + if (index >= 0) { -#ifndef CONFIG_CUSTOM_STACK - i = task_create(namedapps[i].name, namedapps[i].priority, - namedapps[i].stacksize, namedapps[i].main, - (argv) ? &argv[1] : (const char **)NULL); -#else - i = task_create(namedapps[i].name, namedapps[i].priority, namedapps[i].main, - (argv) ? &argv[1] : (const char **)NULL); -#endif + /* Disable pre-emption. This means that although we start the named + * application here, it will not actually run until pre-emption is + * re-enabled below. + */ + + sched_lock(); + + /* Start the named application task */ + + pid = TASK_CREATE(namedapps[index].name, namedapps[index].priority, + namedapps[index].stacksize, namedapps[index].main, + (argv) ? &argv[1] : (const char **)NULL); + + /* If robin robin scheduling is enabled, then set the scheduling policy + * of the new task to SCHED_RR before it has a chance to run. + */ #if CONFIG_RR_INTERVAL > 0 - if (i > 0) + if (pid > 0) { struct sched_param param; - - sched_getparam(0, ¶m); - sched_setscheduler(i, SCHED_RR, ¶m); + + /* Pre-emption is disabled so the task creation and the + * following operation will be atomic. The priority of the + * new task cannot yet have changed from its initial value. + */ + + param.sched_priority = namedapps[index].priority; + sched_setscheduler(pid, SCHED_RR, ¶m); } #endif + /* Now let the named application run */ + + sched_unlock(); + + /* Return the task ID of the new task if the task was sucessfully + * started. Otherwise, pid will be ERROR (and the errno value will + * be set appropriately). + */ + + return pid; } - - return i; + + /* Return ERROR with errno set appropriately */ + + return ERROR; } |