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 e39ef8563e18cd463855e8ba19a4642718f55187
Author: Ville Juven <ville.ju...@unikie.com>
AuthorDate: Fri Nov 24 10:54:22 2023 +0200

    semaphore/_SEM_XX: Remove the _SEM redirection macros as unnecessary
---
 Documentation/components/libs/index.rst |  4 +--
 include/nuttx/semaphore.h               | 45 ---------------------------------
 libs/libc/wqueue/work_cancel.c          |  4 +--
 libs/libc/wqueue/work_queue.c           |  6 ++---
 libs/libc/wqueue/work_usrthread.c       |  4 +--
 libs/libnx/nxmu/nx_bitmap.c             |  8 +++---
 libs/libnx/nxmu/nx_getrectangle.c       |  8 +++---
 7 files changed, 16 insertions(+), 63 deletions(-)

diff --git a/Documentation/components/libs/index.rst 
b/Documentation/components/libs/index.rst
index 3ef511cc3b..47cb071cf9 100644
--- a/Documentation/components/libs/index.rst
+++ b/Documentation/components/libs/index.rst
@@ -21,9 +21,7 @@ Libraries in NuttX are very special creatures.  They have 
these properties:
    For example, ``sem_wait()`` is both a cancellation point and modifies the
    errno value.  So within the FLAT build and without kernel version for
    the PROTECTED and KERNEL builds, the special internal OS interface
-   ``nxsem_wait()`` must be used.  Within libraries, the macro ``_SEM_WAIT()``
-   (as defined in ``include/nuttx/semaphore.h``) is used instead.  The
-   definition of this macro accounts for the different usage environments.
+   ``nxsem_wait()`` must be used.
 
 NOTE:  The libraries under ``libs/`` build differently from other NuttX
 components:  There are no build-related files in the ``libs/`` directory; it
diff --git a/include/nuttx/semaphore.h b/include/nuttx/semaphore.h
index 274c0a4284..58184d39ca 100644
--- a/include/nuttx/semaphore.h
+++ b/include/nuttx/semaphore.h
@@ -57,51 +57,6 @@
      {(c), (f), SEM_WAITLIST_INITIALIZER}
 #endif /* CONFIG_PRIORITY_INHERITANCE */
 
-/* Most internal nxsem_* interfaces are not available in the user space in
- * PROTECTED and KERNEL builds.  In that context, the application semaphore
- * interfaces must be used.  The differences between the two sets of
- * interfaces are:  (1) the nxsem_* interfaces do not cause cancellation
- * points and (2) they do not modify the errno variable.
- *
- * This is only important when compiling libraries (libc or libnx) that are
- * used both by the OS (libkc.a and libknx.a) or by the applications
- * (libc.a and libnx.a).  In that case, the correct interface must be
- * used for the build context.
- *
- * REVISIT:  In the flat build, the same functions must be used both by
- * the OS and by applications.  We have to use the normal user functions
- * in this case or we will fail to set the errno or fail to create the
- * cancellation point.
- */
-
-#if !defined(CONFIG_BUILD_FLAT) && defined(__KERNEL__)
-#  define _SEM_INIT(s,p,c)      nxsem_init(s,p,c)
-#  define _SEM_DESTROY(s)       nxsem_destroy(s)
-#  define _SEM_WAIT(s)          nxsem_wait(s)
-#  define _SEM_TRYWAIT(s)       nxsem_trywait(s)
-#  define _SEM_TIMEDWAIT(s,t)   nxsem_timedwait(s,t)
-#  define _SEM_CLOCKWAIT(s,c,t) nxsem_clockwait(s,c,t)
-#  define _SEM_POST(s)          nxsem_post(s)
-#  define _SEM_GETVALUE(s,v)    nxsem_get_value(s,v)
-#  define _SEM_GETPROTOCOL(s,p) nxsem_get_protocol(s,p)
-#  define _SEM_SETPROTOCOL(s,p) nxsem_set_protocol(s,p)
-#  define _SEM_ERRNO(r)         (-(r))
-#  define _SEM_ERRVAL(r)        (r)
-#else
-#  define _SEM_INIT(s,p,c)      sem_init(s,p,c)
-#  define _SEM_DESTROY(s)       sem_destroy(s)
-#  define _SEM_WAIT(s)          sem_wait(s)
-#  define _SEM_TRYWAIT(s)       sem_trywait(s)
-#  define _SEM_TIMEDWAIT(s,t)   sem_timedwait(s,t)
-#  define _SEM_CLOCKWAIT(s,c,t) sem_clockwait(s,c,t)
-#  define _SEM_GETVALUE(s,v)    sem_getvalue(s,v)
-#  define _SEM_POST(s)          sem_post(s)
-#  define _SEM_GETPROTOCOL(s,p) sem_getprotocol(s,p)
-#  define _SEM_SETPROTOCOL(s,p) sem_setprotocol(s,p)
-#  define _SEM_ERRNO(r)         errno
-#  define _SEM_ERRVAL(r)        (-errno)
-#endif
-
 /****************************************************************************
  * Public Type Definitions
  ****************************************************************************/
diff --git a/libs/libc/wqueue/work_cancel.c b/libs/libc/wqueue/work_cancel.c
index 760267d29c..839e204af1 100644
--- a/libs/libc/wqueue/work_cancel.c
+++ b/libs/libc/wqueue/work_cancel.c
@@ -112,10 +112,10 @@ static int work_qcancel(FAR struct usr_wqueue_s *wqueue,
           /* Remove the work at the head of the queue */
 
           dq_remfirst(&wqueue->q);
-          _SEM_GETVALUE(&wqueue->wake, &semcount);
+          nxsem_get_value(&wqueue->wake, &semcount);
           if (semcount < 1)
             {
-              _SEM_POST(&wqueue->wake);
+              nxsem_post(&wqueue->wake);
             }
         }
 
diff --git a/libs/libc/wqueue/work_queue.c b/libs/libc/wqueue/work_queue.c
index 145d5f81fc..5972fd78c2 100644
--- a/libs/libc/wqueue/work_queue.c
+++ b/libs/libc/wqueue/work_queue.c
@@ -96,7 +96,7 @@ static int work_qqueue(FAR struct usr_wqueue_s *wqueue,
       /* Add the watchdog to the head == tail of the queue. */
 
       dq_addfirst(&work->u.s.dq, &wqueue->q);
-      _SEM_POST(&wqueue->wake);
+      nxsem_post(&wqueue->wake);
     }
 
   /* There are other active watchdogs in the timer queue */
@@ -127,10 +127,10 @@ static int work_qqueue(FAR struct usr_wqueue_s *wqueue,
           /* Insert the watchdog at the head of the list */
 
           dq_addfirst(&work->u.s.dq, &wqueue->q);
-          _SEM_GETVALUE(&wqueue->wake, &semcount);
+          nxsem_get_value(&wqueue->wake, &semcount);
           if (semcount < 1)
             {
-              _SEM_POST(&wqueue->wake);
+              nxsem_post(&wqueue->wake);
             }
         }
       else
diff --git a/libs/libc/wqueue/work_usrthread.c 
b/libs/libc/wqueue/work_usrthread.c
index 3d57ca4ff8..df31aab459 100644
--- a/libs/libc/wqueue/work_usrthread.c
+++ b/libs/libc/wqueue/work_usrthread.c
@@ -191,7 +191,7 @@ static void work_process(FAR struct usr_wqueue_s *wqueue)
     {
       /* Wait indefinitely until work_queue has new items */
 
-      _SEM_WAIT(&wqueue->wake);
+      nxsem_wait(&wqueue->wake);
     }
   else
     {
@@ -208,7 +208,7 @@ static void work_process(FAR struct usr_wqueue_s *wqueue)
       clock_ticks2time(next, &delay);
       clock_timespec_add(&now, &delay, &rqtp);
 
-      _SEM_TIMEDWAIT(&wqueue->wake, &rqtp);
+      nxsem_timedwait(&wqueue->wake, &rqtp);
     }
 }
 
diff --git a/libs/libnx/nxmu/nx_bitmap.c b/libs/libnx/nxmu/nx_bitmap.c
index 4c39b626f2..9d23660562 100644
--- a/libs/libnx/nxmu/nx_bitmap.c
+++ b/libs/libnx/nxmu/nx_bitmap.c
@@ -95,10 +95,10 @@ int nx_bitmap(NXWINDOW hwnd, FAR const struct nxgl_rect_s 
*dest,
 
   outmsg.sem_done = &sem_done;
 
-  ret = _SEM_INIT(&sem_done, 0, 0);
+  ret = nxsem_init(&sem_done, 0, 0);
   if (ret < 0)
     {
-      gerr("ERROR: _SEM_INIT failed: %d\n", _SEM_ERRNO(ret));
+      gerr("ERROR: nxsem_init failed: %d\n", ret);
       return ret;
     }
 
@@ -112,12 +112,12 @@ int nx_bitmap(NXWINDOW hwnd, FAR const struct nxgl_rect_s 
*dest,
 
   if (ret == OK)
     {
-      ret = _SEM_WAIT(&sem_done);
+      ret = nxsem_wait(&sem_done);
     }
 
   /* Destroy the semaphore and return. */
 
-  _SEM_DESTROY(&sem_done);
+  nxsem_destroy(&sem_done);
 
   return ret;
 }
diff --git a/libs/libnx/nxmu/nx_getrectangle.c 
b/libs/libnx/nxmu/nx_getrectangle.c
index d84d1ec53f..4be68b40a2 100644
--- a/libs/libnx/nxmu/nx_getrectangle.c
+++ b/libs/libnx/nxmu/nx_getrectangle.c
@@ -90,10 +90,10 @@ int nx_getrectangle(NXWINDOW hwnd, FAR const struct 
nxgl_rect_s *rect,
 
   outmsg.sem_done = &sem_done;
 
-  ret = _SEM_INIT(&sem_done, 0, 0);
+  ret = nxsem_init(&sem_done, 0, 0);
   if (ret < 0)
     {
-      gerr("ERROR: _SEM_INIT failed: %d\n", _SEM_ERRNO(ret));
+      gerr("ERROR: nxsem_init failed: %d\n", ret);
       return ret;
     }
 
@@ -108,12 +108,12 @@ int nx_getrectangle(NXWINDOW hwnd, FAR const struct 
nxgl_rect_s *rect,
 
   if (ret == OK)
     {
-      ret = _SEM_WAIT(&sem_done);
+      ret = nxsem_wait(&sem_done);
     }
 
   /* Destroy the semaphore and return. */
 
-  _SEM_DESTROY(&sem_done);
+  nxsem_destroy(&sem_done);
 
   return ret;
 }

Reply via email to