diff --git a/configs/stm3240g-eval/README.txt b/configs/stm3240g-eval/README.txt index 5e66b4d0ff3..7fb69eeb493 100644 --- a/configs/stm3240g-eval/README.txt +++ b/configs/stm3240g-eval/README.txt @@ -954,8 +954,6 @@ Where is one of the following: knxwm: ----- - [WARNING: This is a work in progress]. - This is identical to the nxwm configuration below except that NuttX is built as a kernel-mode, monolithic module and the user applications are built separately. Is is recommended to use a special make command; @@ -1470,14 +1468,16 @@ Where is one of the following: 1. Install the nxwm configuration - $ cd ~/nuttx-code/nuttx/tools - $ ./configure.sh stm3240g-eval/nxwm + $ cd ~/nuttx-code/nuttx + $ tools/configure.sh stm3240g-eval/nxwm + + Use the -l option with the configure.sh script if you are using a + Linux host; use the -c option if you are using Cygwin under Windows. + Use the -h option to see other selections. 2. Make the build context (only) - $ cd .. $ make context - ... 3. Install the nxwm unit test @@ -1491,13 +1491,11 @@ Where is one of the following: $ cd ~/nuttx-code/NxWidgets/libnxwidgets $ make TOPDIR=~/nuttx-code/nuttx - ... 5. Build the NxWM library $ cd ~/nuttx-code/NxWidgets/nxwm $ make TOPDIR=~/nuttx-code/nuttx - ... 6. Built NuttX with the installed unit test as the application diff --git a/include/nuttx/nx/nxmu.h b/include/nuttx/nx/nxmu.h index 5bfdb379b99..b3e53e36111 100644 --- a/include/nuttx/nx/nxmu.h +++ b/include/nuttx/nx/nxmu.h @@ -47,6 +47,7 @@ #include #include +#include #include #ifdef CONFIG_NX_MULTIUSER @@ -87,7 +88,7 @@ /* Handy macros */ -#define nxmu_semgive(sem) nxsem_post(sem) /* To match nxmu_semtake() */ +#define nxmu_semgive(sem) _SEM_POST(sem) /* To match nxmu_semtake() */ /**************************************************************************** * Public Types diff --git a/include/nuttx/semaphore.h b/include/nuttx/semaphore.h index 842ae236e59..40be237c34c 100644 --- a/include/nuttx/semaphore.h +++ b/include/nuttx/semaphore.h @@ -57,6 +57,39 @@ #define SEM_PRIO_INHERIT 1 #define SEM_PRIO_PROTECT 2 +/* 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 + * (libuc.a and libunx.a). The that case, the correct interface must be + * used for the build context. + * + * REVISIT: The fact that sem_wait() is a cancellation point is an issue + * and may cause violations: It makes functions into cancellation points! + */ + +#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_POST(s) nxsem_post(s) +# 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_POST(s) sem_post(s) +# define _SEM_ERRNO(r) errno +# define _SEM_ERRVAL(r) (-errno) +#endif + /**************************************************************************** * Public Type Definitions ****************************************************************************/ diff --git a/libnx/nxfonts/nxfonts_cache.c b/libnx/nxfonts/nxfonts_cache.c index b9e04ad8b2f..4bcc43d4c36 100644 --- a/libnx/nxfonts/nxfonts_cache.c +++ b/libnx/nxfonts/nxfonts_cache.c @@ -45,6 +45,7 @@ #include #include +#include #include #include "nxcontext.h" @@ -109,15 +110,15 @@ static void nxf_list_lock(void) /* Get exclusive access to the font cache */ - while ((ret = sem_wait(&g_cachesem)) < 0) + while ((ret = _SEM_WAIT(&g_cachesem)) < 0) { - int errorcode = errno; + int errorcode = _SEM_ERRNO(ret); DEBUGASSERT(errorcode == EINTR || errorcode == ECANCELED); UNUSED(errorcode); } } -#define nxf_list_unlock() (nxsem_post(&g_cachesem)) +#define nxf_list_unlock() (_SEM_POST(&g_cachesem)) /**************************************************************************** * Name: nxf_removecache @@ -166,15 +167,15 @@ static void nxf_cache_lock(FAR struct nxfonts_fcache_s *priv) /* Get exclusive access to the font cache */ - while ((ret = sem_wait(&priv->fsem)) < 0) + while ((ret = _SEM_WAIT(&priv->fsem)) < 0) { - int errorcode = errno; + int errorcode = _SEM_ERRNO(ret); DEBUGASSERT(errorcode == EINTR || errorcode == ECANCELED); UNUSED(errorcode); } } -#define nxf_cache_unlock(p) (nxsem_post(&priv->fsem)) +#define nxf_cache_unlock(p) (_SEM_POST(&priv->fsem)) /**************************************************************************** * Name: nxf_removeglyph @@ -845,7 +846,7 @@ void nxf_cache_disconnect(FCACHE fhandle) /* Destroy the serializing semaphore... while we are holding it? */ - nxsem_destroy(&priv->fsem); + _SEM_DESTROY(&priv->fsem); /* Finally, free the font cache stucture itself */ diff --git a/libnx/nxmu/nx_bitmap.c b/libnx/nxmu/nx_bitmap.c index cd7645add43..e63bbbcfeb0 100644 --- a/libnx/nxmu/nx_bitmap.c +++ b/libnx/nxmu/nx_bitmap.c @@ -115,7 +115,7 @@ int nx_bitmap(NXWINDOW hwnd, FAR const struct nxgl_rect_s *dest, if (ret != OK) { - gerr("ERROR: nxsem_init failed: %d\n", errno); + gerr("ERROR: sem_init failed: %d\n", errno); return ret; } @@ -138,7 +138,7 @@ int nx_bitmap(NXWINDOW hwnd, FAR const struct nxgl_rect_s *dest, /* Destroy the semaphore and return. */ - nxsem_destroy(&sem_done); + sem_destroy(&sem_done); return ret; } diff --git a/libnx/nxmu/nx_connect.c b/libnx/nxmu/nx_connect.c index 9e035c86dd3..662a102bd39 100644 --- a/libnx/nxmu/nx_connect.c +++ b/libnx/nxmu/nx_connect.c @@ -43,10 +43,12 @@ #include #include #include +#include #include #include #include +#include #include #include @@ -65,7 +67,7 @@ * NOTE: that client ID 0 is reserved for the server(s) themselves */ -static sem_t g_nxlibsem = { 1 }; +static sem_t g_nxlibsem = SEM_INITIALIZER(1); static uint32_t g_nxcid = 1; /**************************************************************************** diff --git a/libnx/nxmu/nx_getrectangle.c b/libnx/nxmu/nx_getrectangle.c index ecfb4451b43..feb4d97fa43 100644 --- a/libnx/nxmu/nx_getrectangle.c +++ b/libnx/nxmu/nx_getrectangle.c @@ -106,10 +106,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 = _SEM_INIT(&sem_done, 0, 0); if (ret < 0) { - gerr("ERROR: nxsem_init failed: %d\n", errno); + gerr("ERROR: _SEM_INIT failed: %d\n", _SEM_ERRNO(ret)); return ret; } @@ -127,12 +127,12 @@ int nx_getrectangle(NXWINDOW hwnd, FAR const struct nxgl_rect_s *rect, if (ret == OK) { - ret = sem_wait(&sem_done); + ret = _SEM_WAIT(&sem_done); } /* Destroy the semaphore and return. */ - nxsem_destroy(&sem_done); + _SEM_DESTROY(&sem_done); return ret; } diff --git a/mm/mm_heap/mm_sem.c b/mm/mm_heap/mm_sem.c index 99f519f1342..fae3b278678 100644 --- a/mm/mm_heap/mm_sem.c +++ b/mm/mm_heap/mm_sem.c @@ -52,28 +52,23 @@ ****************************************************************************/ /* Internal nxsem_* interfaces are not available in the user space in - * PROTECTED and FLAT builds. In that context, the application semaphore + * 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. * + * See additional definitions in include/nuttx/semaphore.h + * * REVISIT: The fact that sem_wait() is a cancellation point is an issue * and does cause a violation: It makes all of the memory management - * interfaces into cancellation points! + * interfaces into cancellation points when used from user space in the + * PROTECTED and KERNEL builds. */ #if defined(CONFIG_BUILD_FLAT) || defined(__KERNEL__) -# define SEM_INIT(s,p,c) nxsem_init(s,p,c) -# define SEM_WAIT(s) nxsem_wait(s) -# define SEM_TRYWAIT(s) nxsem_trywait(s) -# define SEM_POST(s) nxsem_post(s) -# define SEM_ERROR(r) +# define _SEM_GETERROR(r) #else -# define SEM_INIT(s,p,c) sem_init(s,p,c) -# define SEM_WAIT(s) sem_wait(s) -# define SEM_TRYWAIT(s) sem_trywait(s) -# define SEM_POST(s) sem_post(s) -# define SEM_ERROR(r) (r) = -errno +# define _SEM_GETERROR(r) (r) = -errno #endif /* Define the following to enable semaphore state monitoring */ @@ -114,7 +109,7 @@ void mm_seminitialize(FAR struct mm_heap_s *heap) * private data sets). */ - (void)SEM_INIT(&heap->mm_semaphore, 0, 1); + (void)nxsem_init(&heap->mm_semaphore, 0, 1); heap->mm_holder = -1; heap->mm_counts_held = 0; @@ -149,10 +144,10 @@ int mm_trysemaphore(FAR struct mm_heap_s *heap) { /* Try to take the semaphore (perhaps waiting) */ - ret = SEM_TRYWAIT(&heap->mm_semaphore); + ret = _SEM_TRYWAIT(&heap->mm_semaphore); if (ret < 0) { - SEM_ERROR(ret); + _SEM_GETERROR(ret); return ret; } @@ -194,7 +189,7 @@ void mm_takesemaphore(FAR struct mm_heap_s *heap) mseminfo("PID=%d taking\n", my_pid); do { - ret = SEM_WAIT(&heap->mm_semaphore); + ret = _SEM_WAIT(&heap->mm_semaphore); /* The only case that an error should occur here is if the wait * was awakened by a signal. @@ -261,6 +256,6 @@ void mm_givesemaphore(FAR struct mm_heap_s *heap) heap->mm_holder = -1; heap->mm_counts_held = 0; - DEBUGVERIFY(SEM_POST(&heap->mm_semaphore)); + DEBUGVERIFY(_SEM_POST(&heap->mm_semaphore)); } } diff --git a/sched/pthread/pthread_sigmask.c b/sched/pthread/pthread_sigmask.c index 0a9fb16d2de..fb87f28c3f2 100644 --- a/sched/pthread/pthread_sigmask.c +++ b/sched/pthread/pthread_sigmask.c @@ -44,6 +44,8 @@ #include #include +#include + /**************************************************************************** * Public Functions ****************************************************************************/