From 0c234505bf5c1f463619dd567ba9a0715c636d27 Mon Sep 17 00:00:00 2001 From: Petro Karashchenko Date: Mon, 6 Jun 2022 23:15:12 +0200 Subject: [PATCH] nuttx/mutex: do not use non-nx interface in kernel except libs Signed-off-by: Petro Karashchenko --- include/mutex.h | 522 +++++++++++++++++++++++++++++ include/nuttx/mutex.h | 184 ++++++---- include/nuttx/serial/tioctl.h | 2 +- libs/libc/modlib/modlib_registry.c | 6 +- libs/libc/netdb/lib_dnsinit.c | 6 +- libs/libc/stdio/lib_fclose.c | 2 +- libs/libc/stdio/lib_libfilesem.c | 6 +- libs/libc/stdio/lib_libstream.c | 8 +- net/route/net_fileroute.c | 4 +- 9 files changed, 655 insertions(+), 85 deletions(-) create mode 100644 include/mutex.h diff --git a/include/mutex.h b/include/mutex.h new file mode 100644 index 0000000000000..5b98150617cf7 --- /dev/null +++ b/include/mutex.h @@ -0,0 +1,522 @@ +/**************************************************************************** + * include/mutex.h + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +#ifndef __INCLUDE_MUTEX_H +#define __INCLUDE_MUTEX_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include +#include +#include +#include +#include + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +#define MUTEX_NO_HOLDER (pid_t)-1 + +/* Initializers */ + +#define MUTEX_INITIALIZER {SEM_INITIALIZER(1),MUTEX_NO_HOLDER} +#define RMUTEX_INITIALIZER {MUTEX_INITIALIZER,0} + +/**************************************************************************** + * Public Type Declarations + ****************************************************************************/ + +struct mutex_s +{ + sem_t sem; + pid_t holder; +}; + +typedef struct mutex_s mutex_t; + +struct rmutex_s +{ + mutex_t mutex; + uint16_t count; +}; + +typedef struct rmutex_s rmutex_t; + +#ifdef __cplusplus +#define EXTERN extern "C" +extern "C" +{ +#else +#define EXTERN extern +#endif + +/**************************************************************************** + * Public Function Prototypes + ****************************************************************************/ + +/**************************************************************************** + * Name: mutex_init + * + * Description: + * This function initializes the UNNAMED mutex 'mutex'. Following a + * successful call to mutex_init(), the mutex may be used in subsequent + * calls to mutex_lock(), mutex_unlock(), and mutex_trymutex->sem(). The mutex + * remains usable until it is destroyed. + * + * Only 'mutex' itself may be used for performing synchronization. The result + * of referring to copies of 'mutex' in calls to mutex_lock(), + * mutex_trylock(), mutex_unlock(), and mutex_destroy() is undefined. + * + * Input Parameters: + * mutex - Mutex to be initialized + * + * Returned Value: + * This returns zero (OK) if successful. Otherwise, -1 (ERROR) is + * returned and the errno value is set appropriately. + * + ****************************************************************************/ + +static inline int mutex_init(FAR mutex_t *mutex) +{ + DEBUGASSERT(mutex != NULL); + + mutex->holder = MUTEX_NO_HOLDER; + return sem_init(&mutex->sem, 0, 1); +} + +/**************************************************************************** + * Name: mutex_destroy + * + * Description: + * This function is used to destroy the un-named mutex indicated by + * 'mutex'. Only a mutex that was created using mutex_init() may be + * destroyed using mutex_destroy(); the effect of calling mutex_destroy() + * with a named mutex is undefined. The effect of subsequent use of + * the mutex 'mutex' is undefined until 'mutex' is re-initialized by another + * call to mutex_init(). + * + * The effect of destroying a mutex upon which other processes are + * currently blocked is undefined. + * + * Input Parameters: + * mutex - Mutex to be destroyed. + * + * Returned Value: + * This is an internal OS interface and should not be used by applications. + * It follows the NuttX internal error return policy: Zero (OK) is + * returned on success. A negated errno value is returned on failure. + * + ****************************************************************************/ + +static inline int mutex_destroy(FAR mutex_t *mutex) +{ + DEBUGASSERT(mutex != NULL); + + return sem_destroy(&mutex->sem); +} + +/**************************************************************************** + * Name: mutex_lock + * + * Description: + * This function attempts to lock the mutex referenced by 'mutex'. If + * the mutex value is (<=) zero, then the calling task will not return + * until it successfully acquires the lock. + * + * Input Parameters: + * mutex - Mutex descriptor. + * + * Returned Value: + * This function returns zero (OK) if successful. Otherwise, -1 (ERROR) is + * returned and the errno value is set appropriately. Possible errno + * values include: + * + * - EINVAL: Invalid attempt to get the mutex + * + ****************************************************************************/ + +static inline int mutex_lock(FAR mutex_t *mutex) +{ + int ret; + + DEBUGASSERT(mutex != NULL); + + do + { + /* Take the semaphore (perhaps waiting) */ + + ret = sem_wait(&mutex->sem); + } + while (errno == -EINTR); + + if (ret == OK) + { + mutex->holder = gettid(); + } + + return ret; +} + +/**************************************************************************** + * Name: mutex_trylock + * + * Description: + * This function locks the specified mutex only if the mutex is + * currently not locked. In either case, the call returns without + * blocking. + * + * Input Parameters: + * mutex - Mutex descriptor + * + * Returned Value: + * Zero (OK) on success or -1 (ERROR) if unsuccessful. If this function + * returns -1(ERROR), then the cause of the failure will be reported in + * errno variable as: + * + * EINVAL - Invalid attempt to get the mutex + * EAGAIN - The mutex is not available. + * + ****************************************************************************/ + +static inline int mutex_trylock(FAR mutex_t *mutex) +{ + int ret; + + DEBUGASSERT(mutex != NULL); + + ret = sem_trywait(&mutex->sem); + if (ret == OK) + { + mutex->holder = gettid(); + } + + return ret; +} + +/**************************************************************************** + * Name: mutex_is_locked + * + * Description: + * This function get the lock state the mutex referenced by 'mutex'. + * + * Parameters: + * mutex - Mutex descriptor. + * + * Return Value: + * true if mutex is locked and false is mutex is free + * + ****************************************************************************/ + +static inline bool mutex_is_locked(FAR mutex_t *mutex) +{ + int cnt; + int ret; + + DEBUGASSERT(mutex != NULL); + + ret = sem_getvalue(&mutex->sem, &cnt); + + DEBUGASSERT(ret == OK); + + return cnt < 1; +} + +/**************************************************************************** + * Name: mutex_unlock + * + * Description: + * When a task has finished with a mutex, it will call mutex_unlock(). + * This function unlocks the mutex referenced by 'mutex' by performing the + * mutex unlock operation on that mutex. + * + * If the mutex value resulting from this operation is positive, then + * no tasks were blocked waiting for the mutex to become unlocked; the + * mutex is simply incremented. + * + * If the value of the mutex resulting from this operation is zero, + * then one of the tasks blocked waiting for the mutex shall be + * allowed to return successfully from its call to mutex_lock(). + * + * Input Parameters: + * mutex - Mutex descriptor + * + * Returned Value: + * This function return zero (OK) if successful. Otherwise, -1 (ERROR) is + * returned and the errno value is set appropriately. + * + ****************************************************************************/ + +static inline int mutex_unlock(FAR mutex_t *mutex) +{ + int ret = ERROR; + + DEBUGASSERT(mutex != NULL); + + if (mutex->holder == gettid()) + { + mutex->holder = MUTEX_NO_HOLDER; + ret = sem_post(&mutex->sem); + } + else + { + set_errno(EPERM); + } + + return ret; +} + +/**************************************************************************** + * Name: rmutex_init + * + * Description: + * This function initializes the UNNAMED recursive mutex 'mutex'. Following + * a successful call to rmutex_init(), the recursive mutex may be used in + * subsequent calls to rmutex_lock(), rmutex_unlock(), and rmutex_trylock(). + * The recursive mutex remains usable until it is destroyed. + * + * Only 'rmutex' itself may be used for performing synchronization. + * The result of referring to copies of 'rmutex' in calls to rmutex_lock(), + * rmutex_trylock(), rmutex_unlock(), and rmutex_destroy() is undefined. + * + * Input Parameters: + * rmutex - Recursive mutex to be initialized + * + * Returned Value: + * This returns zero (OK) if successful. Otherwise, -1 (ERROR) is + * returned and the errno value is set appropriately. + * + ****************************************************************************/ + +static inline int rmutex_init(FAR rmutex_t *rmutex) +{ + DEBUGASSERT(rmutex != NULL); + + rmutex->count = 0; + return mutex_init(&rmutex->mutex); +} + +/**************************************************************************** + * Name: rmutex_destroy + * + * Description: + * This function is used to destroy the un-named recursive mutex indicated + * by 'mutex'. Only a recursive mutex that was created using rmutex_init() + * may be destroyed using rmutex_destroy(); the effect of calling + * rmutex_destroy() with a named recursive mutex is undefined. The effect + * of subsequent use of the recursive mutex 'rmutex' is undefined until + * 'rmutex' is re-initialized by another call to rmutex_init(). + * + * The effect of destroying a recursive mutex upon which other processes are + * currently blocked is undefined. + * + * Input Parameters: + * rmutex - Recursive mutex to be destroyed. + * + * Returned Value: + * This function is a application interface. It returns zero (OK) if + * successful. Otherwise, -1 (ERROR) is returned and the errno value is + * set appropriately. + * + ****************************************************************************/ + +static inline int rmutex_destroy(FAR rmutex_t *rmutex) +{ + DEBUGASSERT(rmutex != NULL); + + return mutex_destroy(&rmutex->mutex); +} + +/**************************************************************************** + * Name: rmutex_lock + * + * Description: + * This function attempts to lock the recursive mutex referenced by + * 'rmutex'. If the recursive mutex value is (<=) zero, then the calling + * task will not return until it successfully acquires the lock. If the + * recursive mutex is already locked by the calling thread then only the + * nested lock counter is incremented. + * + * Input Parameters: + * rmutex - Recurseive mutex descriptor. + * + * Returned Value: + * This function returns zero (OK) if successful. Otherwise, -1 (ERROR) is + * returned and the errno value is set appropriately. Possible errno + * values include: + * + * - EINVAL: Invalid attempt to get the recursive mutex + * + ****************************************************************************/ + +static inline int rmutex_lock(FAR rmutex_t *rmutex) +{ + int ret; + + DEBUGASSERT(rmutex != NULL); + + if (rmutex->mutex.holder == gettid()) + { + DEBUGASSERT(rmutex->count < UINT16_MAX); + rmutex->count++; + ret = OK; + } + else + { + ret = mutex_lock(&rmutex->mutex); + if (ret == OK) + { + rmutex->count = 1; + } + } + + return ret; +} + +/**************************************************************************** + * Name: rmutex_trylock + * + * Description: + * This function locks the specified recursive mutex only if the recursive + * mutex is currently not locked. In either case, the call returns without + * blocking. + * + * Input Parameters: + * rmutex - Recursive mutex descriptor + * + * Returned Value: + * Zero (OK) on success or -1 (ERROR) if unsuccessful. If this function + * returns -1(ERROR), then the cause of the failure will be reported in + * errno variable as: + * + * EINVAL - Invalid attempt to get the recursive mutex + * EAGAIN - The recursive mutex is not available. + * + ****************************************************************************/ + +static inline int rmutex_trylock(FAR rmutex_t *rmutex) +{ + int ret; + + DEBUGASSERT(rmutex != NULL); + + if (rmutex->mutex.holder == gettid()) + { + DEBUGASSERT(rmutex->count < UINT16_MAX); + rmutex->count++; + ret = OK; + } + else + { + ret = mutex_trylock(&rmutex->mutex); + if (ret == OK) + { + rmutex->count = 1; + } + } + + return ret; +} + +/**************************************************************************** + * Name: rmutex_is_locked + * + * Description: + * This function get the lock state the recursive mutex referenced by + * 'rmutex'. + * + * Parameters: + * rmutex - Recursive mutex descriptor. + * + * Return Value: + * 'true' if recursive mutex is locked and 'false' is recursive mutex is + * free + * + ****************************************************************************/ + +static inline bool rmutex_is_locked(FAR rmutex_t *rmutex) +{ + DEBUGASSERT(rmutex != NULL); + + return mutex_is_locked(&rmutex->mutex); +} + +/**************************************************************************** + * Name: rmutex_unlock + * + * Description: + * When a task has finished with a recursive mutex, it will call + * rmutex_unlock(). This function unlocks the recursive mutex referenced + * by 'mutex' by performing the recursive mutex unlock operation on that + * recursive mutex. + * + * If the recursive mutex value resulting from this operation is positive, + * then no tasks were blocked waiting for the recursive mutex to become + * unlocked; the recursive mutex is simply incremented. + * + * If the value of the recursive mutex resulting from this operation is + * zero, then one of the tasks blocked waiting for the recursive mutex + * shall be allowed to return successfully from its call to rmutex_lock(). + * + * Input Parameters: + * rmutex - Recursive mutex descriptor + * + * Returned Value: + * This function return zero (OK) if successful. Otherwise, -1 (ERROR) is + * returned and the errno value is set appropriately. + * + ****************************************************************************/ + +static inline int rmutex_unlock(FAR rmutex_t *rmutex) +{ + int ret = ERROR; + + DEBUGASSERT(rmutex != NULL); + + if (rmutex->mutex.holder == gettid()) + { + DEBUGASSERT(rmutex->count > 0); + if (rmutex->count == 1) + { + rmutex->count = 0; + ret = mutex_unlock(&rmutex->mutex); + } + else + { + rmutex->count--; + ret = OK; + } + } + else + { + set_errno(EPERM); + } + + return ret; +} + +#undef EXTERN +#ifdef __cplusplus +} +#endif + +#endif /* __INCLUDE_MUTEX_H */ diff --git a/include/nuttx/mutex.h b/include/nuttx/mutex.h index d2367639a148f..4bd3b284b583f 100644 --- a/include/nuttx/mutex.h +++ b/include/nuttx/mutex.h @@ -25,41 +25,81 @@ * Included Files ****************************************************************************/ -#include +#include + #include -#include -#include +#include + #include /**************************************************************************** * Pre-processor Definitions ****************************************************************************/ -#define NXRMUTEX_NO_HOLDER (pid_t)-1 -#define NXMUTEX_INITIALIZER SEM_INITIALIZER(1) -#define NXRMUTEX_INITIALIZER {SEM_INITIALIZER(1), NXRMUTEX_NO_HOLDER, 0} - -/**************************************************************************** - * Public Type Definitions - ****************************************************************************/ - -typedef sem_t mutex_t; - -struct rmutex_s -{ - mutex_t mutex; - pid_t holder; - uint16_t count; -}; - -typedef struct rmutex_s rmutex_t; +/* Initializers */ + +#define NXMUTEX_INITIALIZER {NXSEM_INITIALIZER(1,0),MUTEX_NO_HOLDER} +#define NXRMUTEX_INITIALIZER {NXMUTEX_INITIALIZER,0} + +/* 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 _MUTEX_INIT(m) nxmutex_init(m) +# define _MUTEX_DESTROY(m) nxmutex_destroy(m) +# define _MUTEX_LOCK(m) nxmutex_lock(m) +# define _MUTEX_TRYLOCK(m) nxmutex_trylock(m) +# define _MUTEX_IS_LOCKED(m) nxmutex_is_locked(m) +# define _MUTEX_UNLOCK(m) nxmutex_unlock(m) +# define _MUTEX_ERRNO(r) (-(r)) +# define _MUTEX_ERRVAL(r) (r) + +# define _RMUTEX_INIT(m) nxrmutex_init(m) +# define _RMUTEX_DESTROY(m) nxrmutex_destroy(m) +# define _RMUTEX_LOCK(m) nxrmutex_lock(m) +# define _RMUTEX_TRYLOCK(m) nxrmutex_trylock(m) +# define _RMUTEX_IS_LOCKED(m) nxrmutex_is_locked(m) +# define _RMUTEX_UNLOCK(m) nxrmutex_unlock(m) +# define _RMUTEX_ERRNO(r) (-(r)) +# define _RMUTEX_ERRVAL(r) (r) +#else +# define _MUTEX_INIT(m) mutex_init(m) +# define _MUTEX_DESTROY(m) mutex_destroy(m) +# define _MUTEX_LOCK(m) mutex_lock(m) +# define _MUTEX_TRYLOCK(m) mutex_trylock(m) +# define _MUTEX_IS_LOCKED(m) mutex_is_locked(m) +# define _MUTEX_UNLOCK(m) mutex_unlock(m) +# define _MUTEX_ERRNO(r) errno +# define _MUTEX_ERRVAL(r) (-errno) + +# define _RMUTEX_INIT(m) rmutex_init(m) +# define _RMUTEX_DESTROY(m) rmutex_destroy(m) +# define _RMUTEX_LOCK(m) rmutex_lock(m) +# define _RMUTEX_TRYLOCK(m) rmutex_trylock(m) +# define _RMUTEX_IS_LOCKED(m) rmutex_is_locked(m) +# define _RMUTEX_UNLOCK(m) rmutex_unlock(m) +# define _RMUTEX_ERRNO(r) errno +# define _RMUTEX_ERRVAL(r) (-errno) +#endif /**************************************************************************** * Public Function Prototypes ****************************************************************************/ -#ifndef __ASSEMBLY__ - #ifdef __cplusplus #define EXTERN extern "C" extern "C" @@ -89,14 +129,10 @@ extern "C" static inline int nxmutex_init(FAR mutex_t *mutex) { - int ret = _SEM_INIT(mutex, 0, 1); - - if (ret < 0) - { - return _SEM_ERRVAL(ret); - } + DEBUGASSERT(mutex != NULL); - return ret; + mutex->holder = MUTEX_NO_HOLDER; + return nxsem_init(&mutex->sem, 0, 1); } /**************************************************************************** @@ -120,14 +156,9 @@ static inline int nxmutex_init(FAR mutex_t *mutex) static inline int nxmutex_destroy(FAR mutex_t *mutex) { - int ret = _SEM_DESTROY(mutex); + DEBUGASSERT(mutex != NULL); - if (ret < 0) - { - return _SEM_ERRVAL(ret); - } - - return ret; + return nxsem_destroy(&mutex->sem); } /**************************************************************************** @@ -154,21 +185,19 @@ static inline int nxmutex_lock(FAR mutex_t *mutex) { int ret; - for (; ; ) + DEBUGASSERT(mutex != NULL); + + do { /* Take the semaphore (perhaps waiting) */ - ret = _SEM_WAIT(mutex); - if (ret >= 0) - { - break; - } + ret = nxsem_wait_uninterruptible(&mutex->sem); + } + while (ret == -ECANCELED); - ret = _SEM_ERRVAL(ret); - if (ret != -EINTR && ret != -ECANCELED) - { - break; - } + if (ret == OK) + { + mutex->holder = gettid(); } return ret; @@ -197,11 +226,14 @@ static inline int nxmutex_lock(FAR mutex_t *mutex) static inline int nxmutex_trylock(FAR mutex_t *mutex) { - int ret = _SEM_TRYWAIT(mutex); + int ret; - if (ret < 0) + DEBUGASSERT(mutex != NULL); + + ret = nxsem_trywait(&mutex->sem); + if (ret == OK) { - return _SEM_ERRVAL(ret); + mutex->holder = gettid(); } return ret; @@ -225,7 +257,9 @@ static inline bool nxmutex_is_locked(FAR mutex_t *mutex) int cnt; int ret; - ret = _SEM_GETVALUE(mutex, &cnt); + DEBUGASSERT(mutex != NULL); + + ret = nxsem_get_value(&mutex->sem, &cnt); DEBUGASSERT(ret == OK); @@ -256,10 +290,16 @@ static inline int nxmutex_unlock(FAR mutex_t *mutex) { int ret; - ret = _SEM_POST(mutex); - if (ret < 0) + DEBUGASSERT(mutex != NULL); + + if (mutex->holder == gettid()) + { + mutex->holder = MUTEX_NO_HOLDER; + ret = nxsem_post(&mutex->sem); + } + else { - return _SEM_ERRVAL(ret); + ret = -EPERM; } return ret; @@ -287,8 +327,9 @@ static inline int nxmutex_unlock(FAR mutex_t *mutex) static inline int nxrmutex_init(FAR rmutex_t *rmutex) { + DEBUGASSERT(rmutex != NULL); + rmutex->count = 0; - rmutex->holder = NXRMUTEX_NO_HOLDER; return nxmutex_init(&rmutex->mutex); } @@ -310,6 +351,8 @@ static inline int nxrmutex_init(FAR rmutex_t *rmutex) static inline int nxrmutex_destroy(FAR rmutex_t *rmutex) { + DEBUGASSERT(rmutex != NULL); + return nxmutex_destroy(&rmutex->mutex); } @@ -334,10 +377,11 @@ static inline int nxrmutex_destroy(FAR rmutex_t *rmutex) static inline int nxrmutex_lock(FAR rmutex_t *rmutex) { - pid_t tid = gettid(); int ret; - if (rmutex->holder == tid) + DEBUGASSERT(rmutex != NULL); + + if (rmutex->mutex.holder == gettid()) { DEBUGASSERT(rmutex->count < UINT16_MAX); rmutex->count++; @@ -348,7 +392,6 @@ static inline int nxrmutex_lock(FAR rmutex_t *rmutex) ret = nxmutex_lock(&rmutex->mutex); if (ret == OK) { - rmutex->holder = tid; rmutex->count = 1; } } @@ -381,10 +424,11 @@ static inline int nxrmutex_lock(FAR rmutex_t *rmutex) static inline int nxrmutex_trylock(FAR rmutex_t *rmutex) { - pid_t tid = gettid(); int ret; - if (rmutex->holder == tid) + DEBUGASSERT(rmutex != NULL); + + if (rmutex->mutex.holder == gettid()) { DEBUGASSERT(rmutex->count < UINT16_MAX); rmutex->count++; @@ -395,7 +439,6 @@ static inline int nxrmutex_trylock(FAR rmutex_t *rmutex) ret = nxmutex_trylock(&rmutex->mutex); if (ret == OK) { - rmutex->holder = tid; rmutex->count = 1; } } @@ -419,7 +462,9 @@ static inline int nxrmutex_trylock(FAR rmutex_t *rmutex) static inline bool nxrmutex_is_locked(FAR rmutex_t *rmutex) { - return rmutex->count > 0; + DEBUGASSERT(rmutex != NULL); + + return nxmutex_is_locked(&rmutex->mutex); } /**************************************************************************** @@ -445,16 +490,16 @@ static inline bool nxrmutex_is_locked(FAR rmutex_t *rmutex) static inline int nxrmutex_unlock(FAR rmutex_t *rmutex) { - pid_t tid = gettid(); - int ret = -EPERM; + int ret; + + DEBUGASSERT(rmutex != NULL); - if (rmutex->holder == tid) + if (rmutex->mutex.holder == gettid()) { DEBUGASSERT(rmutex->count > 0); if (rmutex->count == 1) { rmutex->count = 0; - rmutex->holder = NXRMUTEX_NO_HOLDER; ret = nxmutex_unlock(&rmutex->mutex); } else @@ -463,6 +508,10 @@ static inline int nxrmutex_unlock(FAR rmutex_t *rmutex) ret = OK; } } + else + { + ret = -EPERM; + } return ret; } @@ -472,5 +521,4 @@ static inline int nxrmutex_unlock(FAR rmutex_t *rmutex) } #endif -#endif /* __ASSEMBLY__ */ #endif /* __INCLUDE_NUTTX_MUTEX_H */ diff --git a/include/nuttx/serial/tioctl.h b/include/nuttx/serial/tioctl.h index 23a38667f504c..251585de8e2af 100644 --- a/include/nuttx/serial/tioctl.h +++ b/include/nuttx/serial/tioctl.h @@ -86,7 +86,7 @@ /* Controlling TTY */ #define TIOCSCTTY _TIOC(0x0018) /* Make controlling TTY: int */ -#define TIOCNOTTY _TIOC(0x0019) /* Give up controllinog TTY: void */ +#define TIOCNOTTY _TIOC(0x0019) /* Give up controlling TTY: void */ /* Exclusive mode */ diff --git a/libs/libc/modlib/modlib_registry.c b/libs/libc/modlib/modlib_registry.c index 6194de11c5a82..ce977fa290b66 100644 --- a/libs/libc/modlib/modlib_registry.c +++ b/libs/libc/modlib/modlib_registry.c @@ -44,7 +44,7 @@ * Private Data ****************************************************************************/ -static rmutex_t g_modlock = NXRMUTEX_INITIALIZER; +static rmutex_t g_modlock = RMUTEX_INITIALIZER; static FAR struct module_s *g_mod_registry; @@ -68,7 +68,7 @@ static FAR struct module_s *g_mod_registry; void modlib_registry_lock(void) { - nxrmutex_lock(&g_modlock); + _RMUTEX_LOCK(&g_modlock); } /**************************************************************************** @@ -87,7 +87,7 @@ void modlib_registry_lock(void) void modlib_registry_unlock(void) { - nxrmutex_unlock(&g_modlock); + _RMUTEX_UNLOCK(&g_modlock); } /**************************************************************************** diff --git a/libs/libc/netdb/lib_dnsinit.c b/libs/libc/netdb/lib_dnsinit.c index 51795168a77f4..f4083370fae40 100644 --- a/libs/libc/netdb/lib_dnsinit.c +++ b/libs/libc/netdb/lib_dnsinit.c @@ -40,7 +40,7 @@ /* Protects DNS cache, nameserver list and notify list. */ -static rmutex_t g_dns_lock = NXRMUTEX_INITIALIZER; +static rmutex_t g_dns_lock = RMUTEX_INITIALIZER; /**************************************************************************** * Public Data @@ -143,7 +143,7 @@ bool dns_initialize(void) void dns_semtake(void) { - nxrmutex_lock(&g_dns_lock); + _RMUTEX_LOCK(&g_dns_lock); } /**************************************************************************** @@ -156,5 +156,5 @@ void dns_semtake(void) void dns_semgive(void) { - nxrmutex_unlock(&g_dns_lock); + _RMUTEX_UNLOCK(&g_dns_lock); } diff --git a/libs/libc/stdio/lib_fclose.c b/libs/libc/stdio/lib_fclose.c index d414f5abee5e0..0c2717f5c203f 100644 --- a/libs/libc/stdio/lib_fclose.c +++ b/libs/libc/stdio/lib_fclose.c @@ -135,7 +135,7 @@ int fclose(FAR FILE *stream) #ifndef CONFIG_STDIO_DISABLE_BUFFERING /* Destroy the semaphore */ - nxrmutex_destroy(&stream->fs_lock); + _RMUTEX_DESTROY(&stream->fs_lock); /* Release the buffer */ diff --git a/libs/libc/stdio/lib_libfilesem.c b/libs/libc/stdio/lib_libfilesem.c index 6f778a62f05a7..73c0c3b5ab392 100644 --- a/libs/libc/stdio/lib_libfilesem.c +++ b/libs/libc/stdio/lib_libfilesem.c @@ -50,7 +50,7 @@ void lib_sem_initialize(FAR struct file_struct *stream) * to private data sets. */ - nxrmutex_init(&stream->fs_lock); + _RMUTEX_INIT(&stream->fs_lock); } /**************************************************************************** @@ -59,7 +59,7 @@ void lib_sem_initialize(FAR struct file_struct *stream) void lib_take_semaphore(FAR struct file_struct *stream) { - nxrmutex_lock(&stream->fs_lock); + _RMUTEX_LOCK(&stream->fs_lock); } /**************************************************************************** @@ -68,7 +68,7 @@ void lib_take_semaphore(FAR struct file_struct *stream) void lib_give_semaphore(FAR struct file_struct *stream) { - nxrmutex_unlock(&stream->fs_lock); + _RMUTEX_UNLOCK(&stream->fs_lock); } #endif /* CONFIG_STDIO_DISABLE_BUFFERING */ diff --git a/libs/libc/stdio/lib_libstream.c b/libs/libc/stdio/lib_libstream.c index 3a25734287aff..b1ee6afb297d9 100644 --- a/libs/libc/stdio/lib_libstream.c +++ b/libs/libc/stdio/lib_libstream.c @@ -118,7 +118,7 @@ void lib_stream_release(FAR struct task_group_s *group) #ifndef CONFIG_STDIO_DISABLE_BUFFERING /* Destroy the semaphore that protects the IO buffer */ - nxrmutex_destroy(&stream->fs_lock); + _RMUTEX_DESTROY(&stream->fs_lock); #endif /* Release the stream */ @@ -142,9 +142,9 @@ void lib_stream_release(FAR struct task_group_s *group) /* Destroy stdin, stdout and stderr stream */ #ifndef CONFIG_STDIO_DISABLE_BUFFERING - nxrmutex_destroy(&list->sl_std[0].fs_lock); - nxrmutex_destroy(&list->sl_std[1].fs_lock); - nxrmutex_destroy(&list->sl_std[2].fs_lock); + _RMUTEX_DESTROY(&list->sl_std[0].fs_lock); + _RMUTEX_DESTROY(&list->sl_std[1].fs_lock); + _RMUTEX_DESTROY(&list->sl_std[2].fs_lock); #endif } diff --git a/net/route/net_fileroute.c b/net/route/net_fileroute.c index 1b35179ff61f7..9d61a917c9d02 100644 --- a/net/route/net_fileroute.c +++ b/net/route/net_fileroute.c @@ -56,13 +56,13 @@ #ifdef CONFIG_ROUTE_IPv4_FILEROUTE /* Used to lock a routing table for exclusive write-only access */ -static rmutex_t g_ipv4_lock = RMUTEX_INITIALIZER; +static rmutex_t g_ipv4_lock = NXRMUTEX_INITIALIZER; #endif #ifdef CONFIG_ROUTE_IPv6_FILEROUTE /* Used to lock a routing table for exclusive write-only access */ -static rmutex_t g_ipv6_lock = RMUTEX_INITIALIZER; +static rmutex_t g_ipv6_lock = NXRMUTEX_INITIALIZER; #endif /****************************************************************************