From 018badad37fb444f4ed0373a1d68136aed608d2a Mon Sep 17 00:00:00 2001 From: patacongo Date: Wed, 11 Jul 2012 02:43:12 +0000 Subject: 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 --- apps/ChangeLog.txt | 6 ++++ apps/namedapp/exec_namedapp.c | 67 ++++++++++++++++++++++++++++++++----------- 2 files changed, 56 insertions(+), 17 deletions(-) diff --git a/apps/ChangeLog.txt b/apps/ChangeLog.txt index 6aa705545..f2578c473 100755 --- a/apps/ChangeLog.txt +++ b/apps/ChangeLog.txt @@ -242,3 +242,9 @@ * apps/nshlib/nsh_fscmds.c: Add the 'mv' command 6.20 2012-xx-xx Gregory Nutt + + * namedapp/exec_namedapp.c - Correct an error when round robin scheduling + is enabled. The priority of the new, named application was erroneously + being set to the priority of the parent thread; losing its configured + priority. Reported by Mike Smith. + 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; } -- cgit v1.2.3