diff options
Diffstat (limited to 'nuttx/sched')
-rw-r--r-- | nuttx/sched/atexit.c | 20 | ||||
-rw-r--r-- | nuttx/sched/exit.c | 10 |
2 files changed, 23 insertions, 7 deletions
diff --git a/nuttx/sched/atexit.c b/nuttx/sched/atexit.c index 5ca6c5e0f..ca7ef58c4 100644 --- a/nuttx/sched/atexit.c +++ b/nuttx/sched/atexit.c @@ -1,7 +1,7 @@ /************************************************************************ * sched/atexit.c * - * Copyright (C) 2007, 2009 Gregory Nutt. All rights reserved. + * Copyright (C) 2007, 2009, 2011 Gregory Nutt. All rights reserved. * Author: Gregory Nutt <spudmonkey@racsa.co.cr> * * Redistribution and use in source and binary forms, with or without @@ -37,14 +37,20 @@ * Included Files ************************************************************************/ +#include <nuttx/config.h> + #include <stdlib.h> #include <assert.h> #include <unistd.h> #include <debug.h> #include <errno.h> + #include <nuttx/fs.h> + #include "os_internal.h" +#ifdef CONFIG_SCHED_ATEXT + /************************************************************************ * Definitions ************************************************************************/ @@ -83,7 +89,7 @@ * func * * Return Value: - * zero on success. + * Zero on success. Non-zero on failure. * ************************************************************************/ @@ -92,11 +98,19 @@ int atexit(void (*func)(void)) _TCB *tcb = (_TCB*)g_readytorun.head; int ret = ERROR; - if ((func) && (!tcb->exitfunc)) + /* The following must be atomic */ + + sched_lock(); + if (func && !tcb->exitfunc) { tcb->exitfunc = func; ret = OK; } + + sched_unlock(); return ret; } +#endif /* CONFIG_SCHED_ATEXT */ + + diff --git a/nuttx/sched/exit.c b/nuttx/sched/exit.c index b1f743d97..2f287009b 100644 --- a/nuttx/sched/exit.c +++ b/nuttx/sched/exit.c @@ -130,11 +130,13 @@ void exit(int status) /* If an exit function was registered, call it now. */ - if (tcb->exitfunc) { - - (*tcb->exitfunc)(); +#ifdef CONFIG_SCHED_ATEXT + if (tcb->exitfunc) + { + (*tcb->exitfunc)(); + } +#endif - } /* end if */ /* Then "really" exit */ _exit(status); |