summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2012-07-11 02:43:12 +0000
committerpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2012-07-11 02:43:12 +0000
commit018badad37fb444f4ed0373a1d68136aed608d2a (patch)
treea4d26f67a939ca59707f0baf5661dc79253c0edf
parentd9b1d147a8a13b473965a04b0edeb41cd274cc4f (diff)
downloadnuttx-018badad37fb444f4ed0373a1d68136aed608d2a.tar.gz
nuttx-018badad37fb444f4ed0373a1d68136aed608d2a.tar.bz2
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
-rwxr-xr-xapps/ChangeLog.txt6
-rw-r--r--apps/namedapp/exec_namedapp.c67
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 <gnutt@nuttx.org>
+
+ * 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, &param);
- sched_setscheduler(i, SCHED_RR, &param);
+
+ /* 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, &param);
}
#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;
}