mirror of
https://github.com/apache/nuttx.git
synced 2026-05-18 08:54:05 +08:00
sched/environ: rm cestion_in evn
Replace global critical section with mutex in environment variable operations. Use nxrmutex_lock/unlock(&group->tg_mutex) instead of enter/leave_critical_section() to protect environment access, reducing interrupt latency and improving SMP responsiveness. Clean up unused irqstate_t flags variables in env_dup, env_getenv, env_setenv, and env_unsetenv. Signed-off-by: hujun5 <hujun5@xiaomi.com>
This commit is contained in:
@@ -66,7 +66,6 @@
|
||||
int env_dup(FAR struct task_group_s *group, FAR char * const *envcp)
|
||||
{
|
||||
FAR char **envp = NULL;
|
||||
irqstate_t flags;
|
||||
size_t envc = 0;
|
||||
size_t size;
|
||||
int ret = OK;
|
||||
@@ -81,7 +80,7 @@ int env_dup(FAR struct task_group_s *group, FAR char * const *envcp)
|
||||
* environment may be shared.
|
||||
*/
|
||||
|
||||
flags = enter_critical_section();
|
||||
nxrmutex_lock(&group->tg_mutex);
|
||||
|
||||
/* Count the strings */
|
||||
|
||||
@@ -142,8 +141,7 @@ int env_dup(FAR struct task_group_s *group, FAR char * const *envcp)
|
||||
/* Save the child environment allocation. */
|
||||
|
||||
group->tg_envp = envp;
|
||||
|
||||
leave_critical_section(flags);
|
||||
nxrmutex_unlock(&group->tg_mutex);
|
||||
}
|
||||
|
||||
return ret;
|
||||
|
||||
@@ -63,11 +63,8 @@ FAR char *getenv(FAR const char *name)
|
||||
FAR struct tcb_s *rtcb;
|
||||
FAR struct task_group_s *group;
|
||||
FAR char *pvalue = NULL;
|
||||
irqstate_t flags;
|
||||
ssize_t ret = OK;
|
||||
|
||||
flags = enter_critical_section();
|
||||
|
||||
/* Verify that a string was passed */
|
||||
|
||||
if (name == NULL)
|
||||
@@ -83,16 +80,26 @@ FAR char *getenv(FAR const char *name)
|
||||
|
||||
/* Check if the variable exists */
|
||||
|
||||
if (group == NULL || (ret = env_findvar(group, name)) < 0)
|
||||
if (group == NULL)
|
||||
{
|
||||
goto errout;
|
||||
}
|
||||
|
||||
nxrmutex_lock(&group->tg_mutex);
|
||||
ret = env_findvar(group, name);
|
||||
if (ret < 0)
|
||||
{
|
||||
nxrmutex_unlock(&group->tg_mutex);
|
||||
goto errout;
|
||||
}
|
||||
|
||||
/* It does! Get the value sub-string from the name=value string */
|
||||
|
||||
pvalue = strchr(group->tg_envp[ret], '=');
|
||||
if (pvalue == NULL)
|
||||
{
|
||||
nxrmutex_unlock(&group->tg_mutex);
|
||||
|
||||
/* The name=value string has no '=' This is a bug! */
|
||||
|
||||
ret = -EINVAL;
|
||||
@@ -102,11 +109,10 @@ FAR char *getenv(FAR const char *name)
|
||||
/* Adjust the pointer so that it points to the value right after the '=' */
|
||||
|
||||
pvalue++;
|
||||
leave_critical_section(flags);
|
||||
nxrmutex_unlock(&group->tg_mutex);
|
||||
return pvalue;
|
||||
|
||||
errout:
|
||||
leave_critical_section(flags);
|
||||
set_errno(-ret);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -76,7 +76,6 @@ int setenv(FAR const char *name, FAR const char *value, int overwrite)
|
||||
ssize_t envc;
|
||||
ssize_t envpc;
|
||||
ssize_t ret = OK;
|
||||
irqstate_t flags;
|
||||
int varlen;
|
||||
|
||||
/* Verify input parameter */
|
||||
@@ -111,11 +110,12 @@ int setenv(FAR const char *name, FAR const char *value, int overwrite)
|
||||
|
||||
/* Get a reference to the thread-private environ in the TCB. */
|
||||
|
||||
flags = enter_critical_section();
|
||||
rtcb = this_task();
|
||||
group = rtcb->group;
|
||||
DEBUGASSERT(group);
|
||||
|
||||
nxrmutex_lock(&group->tg_mutex);
|
||||
|
||||
/* Check if the variable already exists */
|
||||
|
||||
if (group->tg_envp && (ret = env_findvar(group, name)) >= 0)
|
||||
@@ -126,7 +126,7 @@ int setenv(FAR const char *name, FAR const char *value, int overwrite)
|
||||
{
|
||||
/* No.. then just return success */
|
||||
|
||||
leave_critical_section(flags);
|
||||
nxrmutex_unlock(&group->tg_mutex);
|
||||
return OK;
|
||||
}
|
||||
|
||||
@@ -197,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 */
|
||||
|
||||
snprintf(pvar, varlen, "%s=%s", name, value);
|
||||
leave_critical_section(flags);
|
||||
nxrmutex_unlock(&group->tg_mutex);
|
||||
return OK;
|
||||
|
||||
errout_with_var:
|
||||
group_free(group, pvar);
|
||||
errout_with_lock:
|
||||
leave_critical_section(flags);
|
||||
nxrmutex_unlock(&group->tg_mutex);
|
||||
errout:
|
||||
set_errno(ret);
|
||||
return ERROR;
|
||||
|
||||
@@ -63,7 +63,6 @@ int unsetenv(FAR const char *name)
|
||||
{
|
||||
FAR struct tcb_s *rtcb = this_task();
|
||||
FAR struct task_group_s *group = rtcb->group;
|
||||
irqstate_t flags;
|
||||
ssize_t idx;
|
||||
|
||||
DEBUGASSERT(group);
|
||||
@@ -78,7 +77,7 @@ int unsetenv(FAR const char *name)
|
||||
|
||||
/* Check if the variable exists */
|
||||
|
||||
flags = enter_critical_section();
|
||||
nxrmutex_lock(&group->tg_mutex);
|
||||
if (group && (idx = env_findvar(group, name)) >= 0)
|
||||
{
|
||||
/* It does! Remove the name=value pair from the environment. */
|
||||
@@ -86,7 +85,7 @@ int unsetenv(FAR const char *name)
|
||||
env_removevar(group, idx);
|
||||
}
|
||||
|
||||
leave_critical_section(flags);
|
||||
nxrmutex_unlock(&group->tg_mutex);
|
||||
return OK;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user