summaryrefslogtreecommitdiff
path: root/nuttx/sched/atexit.c
diff options
context:
space:
mode:
authorpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2013-02-04 15:29:19 +0000
committerpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2013-02-04 15:29:19 +0000
commitc13bd69be3d117b359275bcf3b2d631bb19bd597 (patch)
tree9c91903e231aef3df957485f489d9ebac2fa330d /nuttx/sched/atexit.c
parent309ad4ddf471013483b1775e2438562b91a44653 (diff)
downloadpx4-nuttx-c13bd69be3d117b359275bcf3b2d631bb19bd597.tar.gz
px4-nuttx-c13bd69be3d117b359275bcf3b2d631bb19bd597.tar.bz2
px4-nuttx-c13bd69be3d117b359275bcf3b2d631bb19bd597.zip
Move atexit/on_exit data structures to task group; Now callbacks only occur when the final member of the task group exits
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@5607 42af7a65-404d-4744-a932-0658087f49c3
Diffstat (limited to 'nuttx/sched/atexit.c')
-rw-r--r--nuttx/sched/atexit.c28
1 files changed, 17 insertions, 11 deletions
diff --git a/nuttx/sched/atexit.c b/nuttx/sched/atexit.c
index b0559b01b..f60598884 100644
--- a/nuttx/sched/atexit.c
+++ b/nuttx/sched/atexit.c
@@ -1,7 +1,7 @@
/****************************************************************************
* sched/atexit.c
*
- * Copyright (C) 2007, 2009, 2011-2012 Gregory Nutt. All rights reserved.
+ * Copyright (C) 2007, 2009, 2011-2013 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
@@ -117,12 +117,15 @@ int atexit(void (*func)(void))
* can handle a callback function that recieves more parameters than it expects).
*/
- return on_exit(onexitfunc_t func, NULL);
+ return on_exit((onexitfunc_t)func, NULL);
#elif defined(CONFIG_SCHED_ATEXIT_MAX) && CONFIG_SCHED_ATEXIT_MAX > 1
- _TCB *tcb = (_TCB*)g_readytorun.head;
- int index;
- int ret = ERROR;
+ FAR _TCB *tcb = (FAR _TCB*)g_readytorun.head;
+ FAR struct task_group_s *group = tcb->group;
+ int index;
+ int ret = ERROR;
+
+ DEBUGASSERT(group);
/* The following must be atomic */
@@ -139,9 +142,9 @@ int atexit(void (*func)(void))
available = -1;
for (index = 0; index < CONFIG_SCHED_ATEXIT_MAX; index++)
{
- if (!tcb->atexitfunc[index])
+ if (!group->tg_atexitfunc[index])
{
- tcb->atexitfunc[index] = func;
+ group->tg_atexitfunc[index] = func;
ret = OK;
break;
}
@@ -152,15 +155,18 @@ int atexit(void (*func)(void))
return ret;
#else
- _TCB *tcb = (_TCB*)g_readytorun.head;
- int ret = ERROR;
+ FAR _TCB *tcb = (FAR _TCB*)g_readytorun.head;
+ FAR struct task_group_s *group = tcb->group;
+ int ret = ERROR;
+
+ DEBUGASSERT(group);
/* The following must be atomic */
sched_lock();
- if (func && !tcb->atexitfunc)
+ if (func && !group->tg_atexitfunc)
{
- tcb->atexitfunc = func;
+ group->tg_atexitfunc = func;
ret = OK;
}