Skip to content

Commit

Permalink
semaphore/_SEM_XX: Remove the _SEM redirection macros as unnecessary
Browse files Browse the repository at this point in the history
  • Loading branch information
pussuw authored and xiaoxiang781216 committed Nov 27, 2023
1 parent 5f36a43 commit e39ef85
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 63 deletions.
4 changes: 1 addition & 3 deletions Documentation/components/libs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
45 changes: 0 additions & 45 deletions include/nuttx/semaphore.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
****************************************************************************/
Expand Down
4 changes: 2 additions & 2 deletions libs/libc/wqueue/work_cancel.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down
6 changes: 3 additions & 3 deletions libs/libc/wqueue/work_queue.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions libs/libc/wqueue/work_usrthread.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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);
}
}

Expand Down
8 changes: 4 additions & 4 deletions libs/libnx/nxmu/nx_bitmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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;
}
8 changes: 4 additions & 4 deletions libs/libnx/nxmu/nx_getrectangle.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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;
}

0 comments on commit e39ef85

Please sign in to comment.