diff options
author | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2012-04-23 13:59:31 +0000 |
---|---|---|
committer | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2012-04-23 13:59:31 +0000 |
commit | 68bc7cefbd11c4dbeca86fb64fac3466dd4f5b69 (patch) | |
tree | fd1605d23bc93e70f2d8bd7fa5541bec9d33cd2d /nuttx/sched | |
parent | cc17fe8980154e5af111651cce271798b4f8482b (diff) | |
download | px4-nuttx-68bc7cefbd11c4dbeca86fb64fac3466dd4f5b69.tar.gz px4-nuttx-68bc7cefbd11c4dbeca86fb64fac3466dd4f5b69.tar.bz2 px4-nuttx-68bc7cefbd11c4dbeca86fb64fac3466dd4f5b69.zip |
Fix atexit() function being called twice
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@4644 42af7a65-404d-4744-a932-0658087f49c3
Diffstat (limited to 'nuttx/sched')
-rw-r--r-- | nuttx/sched/task_delete.c | 18 | ||||
-rw-r--r-- | nuttx/sched/task_exithook.c | 18 |
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 |