You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by da...@apache.org on 2020/08/18 14:59:32 UTC

[incubator-nuttx] branch master updated: libc: Replace all [nx]sem_xxx with _SEM_XXX

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

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


The following commit(s) were added to refs/heads/master by this push:
     new a7a81b5  libc: Replace all [nx]sem_xxx with _SEM_XXX
a7a81b5 is described below

commit a7a81b5126fe65713ab84078cf6171e34aee2363
Author: Xiang Xiao <xi...@xiaomi.com>
AuthorDate: Fri Aug 14 02:59:16 2020 +0800

    libc: Replace all [nx]sem_xxx with _SEM_XXX
    
    Signed-off-by: Xiang Xiao <xi...@xiaomi.com>
    Change-Id: I34f407ccd52391588ac1b720fce59d24458fe218
---
 libs/libc/misc/lib_filesem.c      |   5 +-
 libs/libc/misc/lib_stream.c       |   2 +-
 libs/libc/stdio/lib_fclose.c      |   9 ++--
 libs/libc/wqueue/work_lock.c      |  19 +++----
 libs/libc/wqueue/work_usrthread.c | 110 ++++++++++++++++++--------------------
 5 files changed, 71 insertions(+), 74 deletions(-)

diff --git a/libs/libc/misc/lib_filesem.c b/libs/libc/misc/lib_filesem.c
index 25214b9..5550d06 100644
--- a/libs/libc/misc/lib_filesem.c
+++ b/libs/libc/misc/lib_filesem.c
@@ -69,7 +69,7 @@ void lib_sem_initialize(FAR struct file_struct *stream)
    * to private data sets.
    */
 
-  nxsem_init(&stream->fs_sem, 0, 1);
+  _SEM_INIT(&stream->fs_sem, 0, 1);
 
   stream->fs_holder = -1;
   stream->fs_counts = 0;
@@ -106,7 +106,8 @@ void lib_take_semaphore(FAR struct file_struct *stream)
            * was awakened by a signal.
            */
 
-          DEBUGASSERT(_SEM_ERRNO(ret) == EINTR || _SEM_ERRNO(ret) == ECANCELED);
+          DEBUGASSERT(_SEM_ERRNO(ret) == EINTR ||
+                      _SEM_ERRNO(ret) == ECANCELED);
           UNUSED(ret);
         }
 
diff --git a/libs/libc/misc/lib_stream.c b/libs/libc/misc/lib_stream.c
index 2aa48c9..2f0e557 100644
--- a/libs/libc/misc/lib_stream.c
+++ b/libs/libc/misc/lib_stream.c
@@ -83,7 +83,7 @@ void lib_stream_initialize(FAR struct task_group_s *group)
 
   /* Initialize the list access mutex */
 
-  nxsem_init(&list->sl_sem, 0, 1);
+  _SEM_INIT(&list->sl_sem, 0, 1);
 
   /* Initialize each FILE structure */
 
diff --git a/libs/libc/stdio/lib_fclose.c b/libs/libc/stdio/lib_fclose.c
index 34cb117..c531c1f 100644
--- a/libs/libc/stdio/lib_fclose.c
+++ b/libs/libc/stdio/lib_fclose.c
@@ -1,7 +1,8 @@
 /****************************************************************************
  * libs/libc/stdio/lib_fclose.c
  *
- *   Copyright (C) 2007-2009, 2011, 2013, 2017 Gregory Nutt. All rights reserved.
+ *   Copyright (C) 2007-2009, 2011, 2013, 2017 Gregory Nutt.
+ *   All rights reserved.
  *   Author: Gregory Nutt <gn...@nuttx.org>
  *
  * Redistribution and use in source and binary forms, with or without
@@ -92,7 +93,7 @@ int fclose(FAR FILE *stream)
               errcode = get_errno();
             }
 
-          /* Close the underlying file descriptor and save the return status */
+          /* Close the file descriptor and save the return status */
 
           status = close(stream->fs_fd);
 
@@ -110,7 +111,7 @@ int fclose(FAR FILE *stream)
 #ifndef CONFIG_STDIO_DISABLE_BUFFERING
       /* Destroy the semaphore */
 
-      sem_destroy(&stream->fs_sem);
+      _SEM_DESTROY(&stream->fs_sem);
 
       /* Release the buffer */
 
@@ -135,7 +136,7 @@ int fclose(FAR FILE *stream)
       stream->fs_oflags = 0;
 #endif
 
-      /* Setting the file descriptor to -1 makes the stream available for reuse */
+      /* Set file descriptor to -1 makes the stream available for reuse */
 
       stream->fs_fd = -1;
     }
diff --git a/libs/libc/wqueue/work_lock.c b/libs/libc/wqueue/work_lock.c
index 90612f2..ad3f286 100644
--- a/libs/libc/wqueue/work_lock.c
+++ b/libs/libc/wqueue/work_lock.c
@@ -73,19 +73,20 @@ int work_lock(void)
   int ret;
 
 #ifdef CONFIG_BUILD_PROTECTED
-  ret = sem_wait(&g_usrsem);
+  ret = _SEM_WAIT(&g_usrsem);
   if (ret < 0)
     {
-      DEBUGASSERT(errno == EINTR || errno == ECANCELED);
+      DEBUGASSERT(_SEM_ERRNO(ret) == EINTR ||
+                  _SEM_ERRNO(ret) == ECANCELED);
       return -EINTR;
     }
 #else
-   ret = pthread_mutex_lock(&g_usrmutex);
-   if (ret != 0)
-     {
-       DEBUGASSERT(ret == EINTR);
-       return -EINTR;
-     }
+  ret = pthread_mutex_lock(&g_usrmutex);
+  if (ret != 0)
+    {
+      DEBUGASSERT(ret == EINTR);
+      return -EINTR;
+    }
 #endif
 
   return ret;
@@ -108,7 +109,7 @@ int work_lock(void)
 void work_unlock(void)
 {
 #ifdef CONFIG_BUILD_PROTECTED
-  sem_post(&g_usrsem);
+  _SEM_POST(&g_usrsem);
 #else
   pthread_mutex_unlock(&g_usrmutex);
 #endif
diff --git a/libs/libc/wqueue/work_usrthread.c b/libs/libc/wqueue/work_usrthread.c
index 98f09d7..fae1a00 100644
--- a/libs/libc/wqueue/work_usrthread.c
+++ b/libs/libc/wqueue/work_usrthread.c
@@ -191,7 +191,7 @@ void work_process(FAR struct usr_wqueue_s *wqueue)
 
           if (worker != NULL)
             {
-              /* Extract the work argument (before unlocking the work queue) */
+              /* Extract the work argument before unlocking the work queue */
 
               arg = work->arg;
 
@@ -206,9 +206,9 @@ void work_process(FAR struct usr_wqueue_s *wqueue)
               work_unlock();
               worker(arg);
 
-              /* Now, unfortunately, since we unlocked the work queue we don't
-               * know the state of the work list and we will have to start
-               * back at the head of the list.
+              /* Now, unfortunately, since we unlocked the work queue we
+               * don't know the state of the work list and we will have to
+               * start back at the head of the list.
                */
 
               ret = work_lock();
@@ -362,79 +362,73 @@ static pthread_addr_t work_usrthread(pthread_addr_t arg)
 
 int work_usrstart(void)
 {
-  /* Initialize work queue data structures */
-
 #ifdef CONFIG_BUILD_PROTECTED
-  {
-    /* Set up the work queue lock */
+  /* Set up the work queue lock */
 
-    nxsem_init(&g_usrsem, 0, 1);
+  _SEM_INIT(&g_usrsem, 0, 1);
 
-    /* Start a user-mode worker thread for use by applications. */
+  /* Start a user-mode worker thread for use by applications. */
 
-    g_usrwork.pid = task_create("uwork",
-                                CONFIG_LIB_USRWORKPRIORITY,
-                                CONFIG_LIB_USRWORKSTACKSIZE,
-                                (main_t)work_usrthread,
-                                (FAR char * const *)NULL);
+  g_usrwork.pid = task_create("uwork",
+                              CONFIG_LIB_USRWORKPRIORITY,
+                              CONFIG_LIB_USRWORKSTACKSIZE,
+                              (main_t)work_usrthread,
+                              (FAR char * const *)NULL);
 
-    DEBUGASSERT(g_usrwork.pid > 0);
-    if (g_usrwork.pid < 0)
-      {
-        int errcode = get_errno();
-        DEBUGASSERT(errcode > 0);
-        return -errcode;
-      }
+  DEBUGASSERT(g_usrwork.pid > 0);
+  if (g_usrwork.pid < 0)
+    {
+      int errcode = get_errno();
+      DEBUGASSERT(errcode > 0);
+      return -errcode;
+    }
 
-    return g_usrwork.pid;
-  }
+  return g_usrwork.pid;
 #else
-  {
-    pthread_t usrwork;
-    pthread_attr_t attr;
-    struct sched_param param;
-    int ret;
+  pthread_t usrwork;
+  pthread_attr_t attr;
+  struct sched_param param;
+  int ret;
 
-    /* Set up the work queue lock */
+  /* Set up the work queue lock */
 
-    pthread_mutex_init(&g_usrmutex, NULL);
+  pthread_mutex_init(&g_usrmutex, NULL);
 
-    /* Start a user-mode worker thread for use by applications. */
+  /* Start a user-mode worker thread for use by applications. */
 
-    pthread_attr_init(&attr);
-    pthread_attr_setstacksize(&attr, CONFIG_LIB_USRWORKSTACKSIZE);
+  pthread_attr_init(&attr);
+  pthread_attr_setstacksize(&attr, CONFIG_LIB_USRWORKSTACKSIZE);
 
 #ifdef CONFIG_SCHED_SPORADIC
-    /* Get the current sporadic scheduling parameters.  Those will not be
-     * modified.
-     */
-
-    ret = set_getparam(pid, &param);
-    if (ret < 0)
-      {
-        int erroode = get_errno();
-        return -errcode;
-      }
+  /* Get the current sporadic scheduling parameters.  Those will not be
+   * modified.
+   */
+
+  ret = set_getparam(pid, &param);
+  if (ret < 0)
+    {
+      int errcode = get_errno();
+      return -errcode;
+    }
 #endif
 
-    param.sched_priority = CONFIG_LIB_USRWORKPRIORITY;
-    pthread_attr_setschedparam(&attr, &param);
+  param.sched_priority = CONFIG_LIB_USRWORKPRIORITY;
+  pthread_attr_setschedparam(&attr, &param);
 
-    ret = pthread_create(&usrwork, &attr, work_usrthread, NULL);
-    if (ret != 0)
-      {
-        return -ret;
-      }
+  ret = pthread_create(&usrwork, &attr, work_usrthread, NULL);
+  if (ret != 0)
+    {
+      return -ret;
+    }
 
-    /* Detach because the return value and completion status will not be
-     * requested.
-     */
+  /* Detach because the return value and completion status will not be
+   * requested.
+   */
 
-    pthread_detach(usrwork);
+  pthread_detach(usrwork);
 
-    g_usrwork.pid = (pid_t)usrwork;
-    return g_usrwork.pid;
-  }
+  g_usrwork.pid = (pid_t)usrwork;
+  return g_usrwork.pid;
 #endif
 }