This is an automated email from the ASF dual-hosted git repository.

xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git

commit 451f9372dbdfc0d7dce9ce4f7d3f24869a7a0966
Author: hujun5 <[email protected]>
AuthorDate: Sun Dec 10 15:57:20 2023 +0800

    sched/environ: There is no need to use sched_[un]lock
    
    Signed-off-by: hujun5 <[email protected]>
---
 sched/environ/env_dup.c      |  5 +++--
 sched/environ/env_getenv.c   | 13 +++++++------
 sched/environ/env_setenv.c   |  9 +++++----
 sched/environ/env_unsetenv.c |  5 +++--
 4 files changed, 18 insertions(+), 14 deletions(-)

diff --git a/sched/environ/env_dup.c b/sched/environ/env_dup.c
index ee45aae037..4f773d78e3 100644
--- a/sched/environ/env_dup.c
+++ b/sched/environ/env_dup.c
@@ -66,6 +66,7 @@
 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;
@@ -80,7 +81,7 @@ int env_dup(FAR struct task_group_s *group, FAR char * const 
*envcp)
        * environment may be shared.
        */
 
-      sched_lock();
+      flags = enter_critical_section();
 
       /* Count the strings */
 
@@ -142,7 +143,7 @@ int env_dup(FAR struct task_group_s *group, FAR char * 
const *envcp)
 
       group->tg_envp = envp;
 
-      sched_unlock();
+      leave_critical_section(flags);
     }
 
   return ret;
diff --git a/sched/environ/env_getenv.c b/sched/environ/env_getenv.c
index 0e45c336be..7cc2805f14 100644
--- a/sched/environ/env_getenv.c
+++ b/sched/environ/env_getenv.c
@@ -63,8 +63,11 @@ 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)
@@ -75,7 +78,6 @@ FAR char *getenv(FAR const char *name)
 
   /* Get a reference to the thread-private environ in the TCB. */
 
-  sched_lock();
   rtcb  = this_task();
   group = rtcb->group;
 
@@ -83,7 +85,7 @@ FAR char *getenv(FAR const char *name)
 
   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 */
@@ -94,18 +96,17 @@ FAR char *getenv(FAR const char *name)
       /* The name=value string has no '='  This is a bug! */
 
       ret = -EINVAL;
-      goto errout_with_lock;
+      goto errout;
     }
 
   /* Adjust the pointer so that it points to the value right after the '=' */
 
   pvalue++;
-  sched_unlock();
+  leave_critical_section(flags);
   return pvalue;
 
-errout_with_lock:
-  sched_unlock();
 errout:
+  leave_critical_section(flags);
   set_errno(-ret);
   return NULL;
 }
diff --git a/sched/environ/env_setenv.c b/sched/environ/env_setenv.c
index d1c36815fe..a64906180b 100644
--- a/sched/environ/env_setenv.c
+++ b/sched/environ/env_setenv.c
@@ -76,6 +76,7 @@ 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 */
@@ -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. */
 
-  sched_lock();
+  flags = enter_critical_section();
   rtcb  = this_task();
   group = rtcb->group;
   DEBUGASSERT(group);
@@ -125,7 +126,7 @@ int setenv(FAR const char *name, FAR const char *value, int 
overwrite)
         {
           /* No.. then just return success */
 
-          sched_unlock();
+          leave_critical_section(flags);
           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 */
 
   snprintf(pvar, varlen, "%s=%s", name, value);
-  sched_unlock();
+  leave_critical_section(flags);
   return OK;
 
 errout_with_var:
   group_free(group, pvar);
 errout_with_lock:
-  sched_unlock();
+  leave_critical_section(flags);
 errout:
   set_errno(ret);
   return ERROR;
diff --git a/sched/environ/env_unsetenv.c b/sched/environ/env_unsetenv.c
index 87f24603f0..fb4a206c5a 100644
--- a/sched/environ/env_unsetenv.c
+++ b/sched/environ/env_unsetenv.c
@@ -63,6 +63,7 @@ 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);
@@ -77,7 +78,7 @@ int unsetenv(FAR const char *name)
 
   /* Check if the variable exists */
 
-  sched_lock();
+  flags = enter_critical_section();
   if (group && (idx = env_findvar(group, name)) >= 0)
     {
       /* It does!  Remove the name=value pair from the environment. */
@@ -85,7 +86,7 @@ int unsetenv(FAR const char *name)
       env_removevar(group, idx);
     }
 
-  sched_unlock();
+  leave_critical_section(flags);
   return OK;
 }
 

Reply via email to