diff options
author | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2013-02-04 15:29:19 +0000 |
---|---|---|
committer | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2013-02-04 15:29:19 +0000 |
commit | c13bd69be3d117b359275bcf3b2d631bb19bd597 (patch) | |
tree | 9c91903e231aef3df957485f489d9ebac2fa330d /nuttx/sched/on_exit.c | |
parent | 309ad4ddf471013483b1775e2438562b91a44653 (diff) | |
download | px4-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/on_exit.c')
-rw-r--r-- | nuttx/sched/on_exit.c | 24 |
1 files changed, 15 insertions, 9 deletions
diff --git a/nuttx/sched/on_exit.c b/nuttx/sched/on_exit.c index 19a4f9196..89c4a2d57 100644 --- a/nuttx/sched/on_exit.c +++ b/nuttx/sched/on_exit.c @@ -1,7 +1,7 @@ /**************************************************************************** * sched/on_exit.c * - * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * Copyright (C) 2012-2013 Gregory Nutt. All rights reserved. * Author: Gregory Nutt <gnutt@nuttx.org> * * Redistribution and use in source and binary forms, with or without @@ -115,10 +115,13 @@ int on_exit(CODE void (*func)(int, FAR void *), FAR void *arg) { #if defined(CONFIG_SCHED_ONEXIT_MAX) && CONFIG_SCHED_ONEXIT_MAX > 1 - _TCB *tcb = (_TCB*)g_readytorun.head; + FAR _TCB *tcb = (FAR _TCB*)g_readytorun.head; + FAR struct task_group_s *group = tcb->group; int index; int ret = ENOSPC; + DEBUGASSERT(group); + /* The following must be atomic */ if (func) @@ -133,10 +136,10 @@ int on_exit(CODE void (*func)(int, FAR void *), FAR void *arg) for (index = 0; index < CONFIG_SCHED_ONEXIT_MAX; index++) { - if (!tcb->onexitfunc[index]) + if (!group->tg_onexitfunc[index]) { - tcb->onexitfunc[index] = func; - tcb->onexitarg[index] = arg; + group->tg_onexitfunc[index] = func; + group->tg_onexitarg[index] = arg; ret = OK; break; } @@ -147,16 +150,19 @@ int on_exit(CODE void (*func)(int, FAR void *), FAR void *arg) return ret; #else - _TCB *tcb = (_TCB*)g_readytorun.head; + FAR _TCB *tcb = (FAR _TCB*)g_readytorun.head; + FAR struct task_group_s *group = tcb->group; int ret = ENOSPC; + DEBUGASSERT(group); + /* The following must be atomic */ sched_lock(); - if (func && !tcb->onexitfunc) + if (func && !group->tg_onexitfunc) { - tcb->onexitfunc = func; - tcb->onexitarg = arg; + group->tg_onexitfunc = func; + group->tg_onexitarg = arg; ret = OK; } |