forked from nuttx/nuttx-update
sched/environ: There is no need to use sched_[un]lock
Signed-off-by: hujun5 <hujun5@xiaomi.com>
This commit is contained in:
parent
656baa2a12
commit
451f9372db
4 changed files with 18 additions and 14 deletions
|
@ -66,6 +66,7 @@
|
||||||
int env_dup(FAR struct task_group_s *group, FAR char * const *envcp)
|
int env_dup(FAR struct task_group_s *group, FAR char * const *envcp)
|
||||||
{
|
{
|
||||||
FAR char **envp = NULL;
|
FAR char **envp = NULL;
|
||||||
|
irqstate_t flags;
|
||||||
size_t envc = 0;
|
size_t envc = 0;
|
||||||
size_t size;
|
size_t size;
|
||||||
int ret = OK;
|
int ret = OK;
|
||||||
|
@ -80,7 +81,7 @@ int env_dup(FAR struct task_group_s *group, FAR char * const *envcp)
|
||||||
* environment may be shared.
|
* environment may be shared.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
sched_lock();
|
flags = enter_critical_section();
|
||||||
|
|
||||||
/* Count the strings */
|
/* Count the strings */
|
||||||
|
|
||||||
|
@ -142,7 +143,7 @@ int env_dup(FAR struct task_group_s *group, FAR char * const *envcp)
|
||||||
|
|
||||||
group->tg_envp = envp;
|
group->tg_envp = envp;
|
||||||
|
|
||||||
sched_unlock();
|
leave_critical_section(flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
|
|
|
@ -63,8 +63,11 @@ FAR char *getenv(FAR const char *name)
|
||||||
FAR struct tcb_s *rtcb;
|
FAR struct tcb_s *rtcb;
|
||||||
FAR struct task_group_s *group;
|
FAR struct task_group_s *group;
|
||||||
FAR char *pvalue = NULL;
|
FAR char *pvalue = NULL;
|
||||||
|
irqstate_t flags;
|
||||||
ssize_t ret = OK;
|
ssize_t ret = OK;
|
||||||
|
|
||||||
|
flags = enter_critical_section();
|
||||||
|
|
||||||
/* Verify that a string was passed */
|
/* Verify that a string was passed */
|
||||||
|
|
||||||
if (name == NULL)
|
if (name == NULL)
|
||||||
|
@ -75,7 +78,6 @@ FAR char *getenv(FAR const char *name)
|
||||||
|
|
||||||
/* Get a reference to the thread-private environ in the TCB. */
|
/* Get a reference to the thread-private environ in the TCB. */
|
||||||
|
|
||||||
sched_lock();
|
|
||||||
rtcb = this_task();
|
rtcb = this_task();
|
||||||
group = rtcb->group;
|
group = rtcb->group;
|
||||||
|
|
||||||
|
@ -83,7 +85,7 @@ FAR char *getenv(FAR const char *name)
|
||||||
|
|
||||||
if (group == NULL || (ret = env_findvar(group, name)) < 0)
|
if (group == NULL || (ret = env_findvar(group, name)) < 0)
|
||||||
{
|
{
|
||||||
goto errout_with_lock;
|
goto errout;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* It does! Get the value sub-string from the name=value string */
|
/* It does! Get the value sub-string from the name=value string */
|
||||||
|
@ -94,18 +96,17 @@ FAR char *getenv(FAR const char *name)
|
||||||
/* The name=value string has no '=' This is a bug! */
|
/* The name=value string has no '=' This is a bug! */
|
||||||
|
|
||||||
ret = -EINVAL;
|
ret = -EINVAL;
|
||||||
goto errout_with_lock;
|
goto errout;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Adjust the pointer so that it points to the value right after the '=' */
|
/* Adjust the pointer so that it points to the value right after the '=' */
|
||||||
|
|
||||||
pvalue++;
|
pvalue++;
|
||||||
sched_unlock();
|
leave_critical_section(flags);
|
||||||
return pvalue;
|
return pvalue;
|
||||||
|
|
||||||
errout_with_lock:
|
|
||||||
sched_unlock();
|
|
||||||
errout:
|
errout:
|
||||||
|
leave_critical_section(flags);
|
||||||
set_errno(-ret);
|
set_errno(-ret);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
|
@ -76,6 +76,7 @@ int setenv(FAR const char *name, FAR const char *value, int overwrite)
|
||||||
ssize_t envc;
|
ssize_t envc;
|
||||||
ssize_t envpc;
|
ssize_t envpc;
|
||||||
ssize_t ret = OK;
|
ssize_t ret = OK;
|
||||||
|
irqstate_t flags;
|
||||||
int varlen;
|
int varlen;
|
||||||
|
|
||||||
/* Verify input parameter */
|
/* Verify input parameter */
|
||||||
|
@ -110,7 +111,7 @@ int setenv(FAR const char *name, FAR const char *value, int overwrite)
|
||||||
|
|
||||||
/* Get a reference to the thread-private environ in the TCB. */
|
/* Get a reference to the thread-private environ in the TCB. */
|
||||||
|
|
||||||
sched_lock();
|
flags = enter_critical_section();
|
||||||
rtcb = this_task();
|
rtcb = this_task();
|
||||||
group = rtcb->group;
|
group = rtcb->group;
|
||||||
DEBUGASSERT(group);
|
DEBUGASSERT(group);
|
||||||
|
@ -125,7 +126,7 @@ int setenv(FAR const char *name, FAR const char *value, int overwrite)
|
||||||
{
|
{
|
||||||
/* No.. then just return success */
|
/* No.. then just return success */
|
||||||
|
|
||||||
sched_unlock();
|
leave_critical_section(flags);
|
||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -196,13 +197,13 @@ int setenv(FAR const char *name, FAR const char *value, int overwrite)
|
||||||
/* Now, put the new name=value string into the environment buffer */
|
/* Now, put the new name=value string into the environment buffer */
|
||||||
|
|
||||||
snprintf(pvar, varlen, "%s=%s", name, value);
|
snprintf(pvar, varlen, "%s=%s", name, value);
|
||||||
sched_unlock();
|
leave_critical_section(flags);
|
||||||
return OK;
|
return OK;
|
||||||
|
|
||||||
errout_with_var:
|
errout_with_var:
|
||||||
group_free(group, pvar);
|
group_free(group, pvar);
|
||||||
errout_with_lock:
|
errout_with_lock:
|
||||||
sched_unlock();
|
leave_critical_section(flags);
|
||||||
errout:
|
errout:
|
||||||
set_errno(ret);
|
set_errno(ret);
|
||||||
return ERROR;
|
return ERROR;
|
||||||
|
|
|
@ -63,6 +63,7 @@ int unsetenv(FAR const char *name)
|
||||||
{
|
{
|
||||||
FAR struct tcb_s *rtcb = this_task();
|
FAR struct tcb_s *rtcb = this_task();
|
||||||
FAR struct task_group_s *group = rtcb->group;
|
FAR struct task_group_s *group = rtcb->group;
|
||||||
|
irqstate_t flags;
|
||||||
ssize_t idx;
|
ssize_t idx;
|
||||||
|
|
||||||
DEBUGASSERT(group);
|
DEBUGASSERT(group);
|
||||||
|
@ -77,7 +78,7 @@ int unsetenv(FAR const char *name)
|
||||||
|
|
||||||
/* Check if the variable exists */
|
/* Check if the variable exists */
|
||||||
|
|
||||||
sched_lock();
|
flags = enter_critical_section();
|
||||||
if (group && (idx = env_findvar(group, name)) >= 0)
|
if (group && (idx = env_findvar(group, name)) >= 0)
|
||||||
{
|
{
|
||||||
/* It does! Remove the name=value pair from the environment. */
|
/* It does! Remove the name=value pair from the environment. */
|
||||||
|
@ -85,7 +86,7 @@ int unsetenv(FAR const char *name)
|
||||||
env_removevar(group, idx);
|
env_removevar(group, idx);
|
||||||
}
|
}
|
||||||
|
|
||||||
sched_unlock();
|
leave_critical_section(flags);
|
||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue