From c13bd69be3d117b359275bcf3b2d631bb19bd597 Mon Sep 17 00:00:00 2001 From: patacongo Date: Mon, 4 Feb 2013 15:29:19 +0000 Subject: 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 --- nuttx/sched/atexit.c | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) (limited to 'nuttx/sched/atexit.c') 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 * * 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; } -- cgit v1.2.3