aboutsummaryrefslogtreecommitdiff
path: root/nuttx/sched
diff options
context:
space:
mode:
authorpatacongo <patacongo@7fd9a85b-ad96-42d3-883c-3090e2eb8679>2012-04-23 13:59:31 +0000
committerpatacongo <patacongo@7fd9a85b-ad96-42d3-883c-3090e2eb8679>2012-04-23 13:59:31 +0000
commit09eac48792417206230798528de54a7d1c349f1d (patch)
treefd1605d23bc93e70f2d8bd7fa5541bec9d33cd2d /nuttx/sched
parent4cae5aee9fb5816b0d2fea1a72637fb0dc6fffbb (diff)
downloadpx4-firmware-09eac48792417206230798528de54a7d1c349f1d.tar.gz
px4-firmware-09eac48792417206230798528de54a7d1c349f1d.tar.bz2
px4-firmware-09eac48792417206230798528de54a7d1c349f1d.zip
Fix atexit() function being called twice
git-svn-id: https://nuttx.svn.sourceforge.net/svnroot/nuttx/trunk@4644 7fd9a85b-ad96-42d3-883c-3090e2eb8679
Diffstat (limited to 'nuttx/sched')
-rw-r--r--nuttx/sched/task_delete.c18
-rw-r--r--nuttx/sched/task_exithook.c18
2 files changed, 36 insertions, 0 deletions
diff --git a/nuttx/sched/task_delete.c b/nuttx/sched/task_delete.c
index 4cd2b3ba7..e5244a0b8 100644
--- a/nuttx/sched/task_delete.c
+++ b/nuttx/sched/task_delete.c
@@ -83,6 +83,21 @@
* This function causes a specified task to cease to exist. Its stack and
* TCB will be deallocated. This function is the companion to task_create().
*
+ * The logic in this function only deletes non-running tasks. If the 'pid'
+ * parameter refers to to the currently runing task, then processing is
+ * redirected to exit().
+ *
+ * Control will still be returned to task_delete() after the exit() logic
+ * finishes. In fact, this function is the final function called all task
+ * termination sequences. Here are all possible exit scenarios:
+ *
+ * - pthread_exit(). Calls exit()
+ * - exit(). Calls _exit()
+ * - _exit(). Calls task_deletecurrent() making the currently running task
+ * non-running then calls task_delete() to terminate the non-running
+ * task.
+ * - task_delete()
+ *
* Inputs:
* pid - The task ID of the task to delete. A pid of zero
* signifies the calling task.
@@ -145,6 +160,9 @@ int task_delete(pid_t pid)
* this as early as possible so that higher level clean-up logic
* can run in a healthy tasking environment.
*
+ * In the case where the task exits via exit(), task_exithook()
+ * may be called twice.
+ *
* I suppose EXIT_SUCCESS is an appropriate return value???
*/
diff --git a/nuttx/sched/task_exithook.c b/nuttx/sched/task_exithook.c
index 44073165a..e160a1cb3 100644
--- a/nuttx/sched/task_exithook.c
+++ b/nuttx/sched/task_exithook.c
@@ -114,14 +114,32 @@ void task_exithook(FAR _TCB *tcb, int status)
#ifdef CONFIG_SCHED_ATEXIT
if (tcb->atexitfunc)
{
+ /* Call the atexit function */
+
(*tcb->atexitfunc)();
+
+ /* Nullify the atexit function. task_exithook may be called more then
+ * once in most task exit scenarios. Nullifying the atext function
+ * pointer will assure that the callback is performed only once.
+ */
+
+ tcb->atexitfunc = NULL;
}
#endif
#ifdef CONFIG_SCHED_ONEXIT
if (tcb->onexitfunc)
{
+ /* Call the on_exit function */
+
(*tcb->onexitfunc)(status, tcb->onexitarg);
+
+ /* Nullify the on_exit function. task_exithook may be called more then
+ * once in most task exit scenarios. Nullifying the on_exit function
+ * pointer will assure that the callback is performed only once.
+ */
+
+ tcb->onexitfunc = NULL;
}
#endif