diff options
author | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2013-01-25 23:21:27 +0000 |
---|---|---|
committer | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2013-01-25 23:21:27 +0000 |
commit | 239e2808cca6ee4c356d087bc83889fc57e64307 (patch) | |
tree | fd3a16f87e715df6729c7966a230f93214e98e20 /nuttx/sched/env_release.c | |
parent | fdaa22ed2d565e49983e956bc056f1e0797bd9a9 (diff) | |
download | px4-firmware-239e2808cca6ee4c356d087bc83889fc57e64307.tar.gz px4-firmware-239e2808cca6ee4c356d087bc83889fc57e64307.tar.bz2 px4-firmware-239e2808cca6ee4c356d087bc83889fc57e64307.zip |
Move environment variables in the task group structure
git-svn-id: http://svn.code.sf.net/p/nuttx/code/trunk@5565 42af7a65-404d-4744-a932-0658087f49c3
Diffstat (limited to 'nuttx/sched/env_release.c')
-rw-r--r-- | nuttx/sched/env_release.c | 68 |
1 files changed, 24 insertions, 44 deletions
diff --git a/nuttx/sched/env_release.c b/nuttx/sched/env_release.c index 8bc8d2205..4de55c388 100644 --- a/nuttx/sched/env_release.c +++ b/nuttx/sched/env_release.c @@ -1,7 +1,7 @@ /**************************************************************************** - * sched/env_clearenv.c + * sched/env_release.c * - * Copyright (C) 2007, 2009 Gregory Nutt. All rights reserved. + * Copyright (C) 2007, 2009, 2013 Gregory Nutt. All rights reserved. * Author: Gregory Nutt <gnutt@nuttx.org> * * Redistribution and use in source and binary forms, with or without @@ -58,65 +58,45 @@ * Name: env_release * * Description: - * The env_release() function clears the environment of all name-value - * pairs and sets the value of the external variable environ to NULL. + * env_release() is called only from group_leave() when the last member of + * a task group exits. The env_release() function clears the environment + * of all name-value pairs and sets the value of the external variable + * environ to NULL. * * Parameters: - * ptcb Identifies the TCB containing the environment structure + * tcb Identifies the TCB containing the environment structure to be + * released. * * Return Value: - * zero on success + * None * * Assumptions: * Not called from an interrupt handler * ****************************************************************************/ -int env_release(FAR _TCB *ptcb) +void env_release(FAR _TCB *tcb) { - int ret = OK; + FAR struct task_group_s *group; - if (!ptcb) - { - ret = -EINVAL; - } - else - { - FAR environ_t *envp; - - /* Examine the environ data in the TCB. Preemption is disabled because the - * the environment could be shared among threads. - */ - - sched_lock(); - envp = ptcb->envp; - if (ptcb->envp) - { - /* Check the reference count on the environment structure */ + DEBUGASSERT(tcb && tcb->group); + group = tcb->group; - if (envp->ev_crefs <= 1) - { - /* Decrementing the reference count will destroy the environment */ + /* Free any allocate environment strings */ - sched_free(envp); - } - else - { - /* The environment will persist after decrementing the reference - * count */ - - envp->ev_crefs--; - } - - /* In any case, the environment is no longer accessible on this thread */ - - ptcb->envp = NULL; - } + if (group->tg_envp) + { + /* Free the environment */ - sched_unlock(); + sched_free(group->tg_envp); } - return ret; + /* In any event, make sure that all environment-related varialbles in the + * task group structure are reset to initial values. + */ + + group->tg_envsize = 0; + group->tg_envp = NULL; } #endif /* CONFIG_DISABLE_ENVIRON */ |