nxmutex: export priority ceiling interfaces with nxsem

Signed-off-by: makejian <makejian@xiaomi.com>
This commit is contained in:
makejian 2024-08-05 18:06:56 +08:00 committed by Xiang Xiao
parent ee78219f9c
commit 85f8677e21
3 changed files with 170 additions and 26 deletions

View File

@ -336,6 +336,65 @@ int nxmutex_breaklock(FAR mutex_t *mutex, FAR unsigned int *locked);
int nxmutex_restorelock(FAR mutex_t *mutex, unsigned int locked);
/****************************************************************************
* Name: nxmutex_set_protocol
*
* Description:
* This function attempts to set the priority protocol of a mutex.
*
* Parameters:
* mutex - mutex descriptor.
* protocol - mutex protocol value to set.
*
* Return 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
*
****************************************************************************/
int nxmutex_set_protocol(FAR mutex_t *mutex, int protocol);
/****************************************************************************
* Name: nxmutex_getprioceiling
*
* Description:
* This function attempts to get the priority ceiling of a mutex.
*
* Parameters:
* mutex - mutex descriptor.
* prioceiling - location to return the mutex priority ceiling.
*
* Return 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
*
****************************************************************************/
int nxmutex_getprioceiling(FAR const mutex_t *mutex, FAR int *prioceiling);
/****************************************************************************
* Name: nxmutex_setprioceiling
*
* Description:
* This function attempts to set the priority ceiling of a mutex.
*
* Parameters:
* mutex - mutex descriptor.
* prioceiling - mutex priority ceiling value to set.
* old_ceiling - location to return the mutex ceiling priority set before.
*
* Return 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
*
****************************************************************************/
int nxmutex_setprioceiling(FAR mutex_t *mutex, int prioceiling,
FAR int *old_ceiling);
/****************************************************************************
* Name: nxrmutex_init
*
@ -615,6 +674,13 @@ int nxrmutex_breaklock(FAR rmutex_t *rmutex, FAR unsigned int *count);
int nxrmutex_restorelock(FAR rmutex_t *rmutex, unsigned int count);
#define nxrmutex_set_protocol(rmutex, protocol) \
nxmutex_set_protocol(&(rmutex)->mutex, protocol)
#define nxrmutex_getprioceiling(rmutex, prioceiling) \
nxmutex_getprioceiling(&(rmutex)->mutex, prioceiling)
#define nxrmutex_setprioceiling(rmutex, prioceiling, old_ceiling) \
nxmutex_setprioceiling(&(rmutex)->mutex, prioceiling, old_ceiling)
#undef EXTERN
#ifdef __cplusplus
}

View File

@ -480,6 +480,78 @@ int nxmutex_restorelock(FAR mutex_t *mutex, unsigned int locked)
return locked ? nxmutex_lock(mutex) : OK;
}
/****************************************************************************
* Name: nxmutex_set_protocol
*
* Description:
* This function attempts to set the priority protocol of a mutex.
*
* Parameters:
* mutex - mutex descriptor.
* protocol - mutex protocol value to set.
*
* Return 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
*
****************************************************************************/
int nxmutex_set_protocol(FAR mutex_t *mutex, int protocol)
{
return nxsem_set_protocol(&mutex->sem, protocol);
}
/****************************************************************************
* Name: nxmutex_getprioceiling
*
* Description:
* This function attempts to get the priority ceiling of a mutex.
*
* Parameters:
* mutex - mutex descriptor.
* prioceiling - location to return the mutex priority ceiling.
*
* Return 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
*
****************************************************************************/
#ifdef CONFIG_PRIORITY_PROTECT
int nxmutex_getprioceiling(FAR const mutex_t *mutex, FAR int *prioceiling)
{
return nxsem_getprioceiling(&mutex->sem, prioceiling);
}
#endif
/****************************************************************************
* Name: nxmutex_setprioceiling
*
* Description:
* This function attempts to set the priority ceiling of a mutex.
*
* Parameters:
* mutex - mutex descriptor.
* prioceiling - mutex priority ceiling value to set.
* old_ceiling - location to return the mutex ceiling priority set before.
*
* Return 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
*
****************************************************************************/
#ifdef CONFIG_PRIORITY_PROTECT
int nxmutex_setprioceiling(FAR mutex_t *mutex, int prioceiling,
FAR int *old_ceiling)
{
return nxsem_setprioceiling(&mutex->sem, prioceiling, old_ceiling);
}
#endif
/****************************************************************************
* Name: nxrmutex_init
*

View File

@ -41,33 +41,39 @@
****************************************************************************/
#ifdef CONFIG_PTHREAD_MUTEX_TYPES
# define mutex_init(m) nxrmutex_init(m)
# define mutex_destroy(m) nxrmutex_destroy(m)
# define mutex_is_hold(m) nxrmutex_is_hold(m)
# define mutex_is_locked(m) nxrmutex_is_locked(m)
# define mutex_is_recursive(m) nxrmutex_is_recursive(m)
# define mutex_get_holder(m) nxrmutex_get_holder(m)
# define mutex_reset(m) nxrmutex_reset(m)
# define mutex_unlock(m) nxrmutex_unlock(m)
# define mutex_lock(m) nxrmutex_lock(m)
# define mutex_trylock(m) nxrmutex_trylock(m)
# define mutex_breaklock(m,v) nxrmutex_breaklock(m,v)
# define mutex_restorelock(m,v) nxrmutex_restorelock(m,v)
# define mutex_clocklock(m,t) nxrmutex_clocklock(m,CLOCK_REALTIME,t)
# define mutex_init(m) nxrmutex_init(m)
# define mutex_destroy(m) nxrmutex_destroy(m)
# define mutex_is_hold(m) nxrmutex_is_hold(m)
# define mutex_is_locked(m) nxrmutex_is_locked(m)
# define mutex_is_recursive(m) nxrmutex_is_recursive(m)
# define mutex_get_holder(m) nxrmutex_get_holder(m)
# define mutex_reset(m) nxrmutex_reset(m)
# define mutex_unlock(m) nxrmutex_unlock(m)
# define mutex_lock(m) nxrmutex_lock(m)
# define mutex_trylock(m) nxrmutex_trylock(m)
# define mutex_breaklock(m,v) nxrmutex_breaklock(m,v)
# define mutex_restorelock(m,v) nxrmutex_restorelock(m,v)
# define mutex_clocklock(m,t) nxrmutex_clocklock(m,CLOCK_REALTIME,t)
# define mutex_set_protocol(m,p) nxrmutex_set_protocol(m,p)
# define mutex_getprioceiling(m,p) nxrmutex_getprioceiling(m,p)
# define mutex_setprioceiling(m,p,o) nxrmutex_setprioceiling(m,p,o)
#else
# define mutex_init(m) nxmutex_init(m)
# define mutex_destroy(m) nxmutex_destroy(m)
# define mutex_is_hold(m) nxmutex_is_hold(m)
# define mutex_is_recursive(m) (false)
# define mutex_is_locked(m) nxmutex_is_locked(m)
# define mutex_get_holder(m) nxmutex_get_holder(m)
# define mutex_reset(m) nxmutex_reset(m)
# define mutex_unlock(m) nxmutex_unlock(m)
# define mutex_lock(m) nxmutex_lock(m)
# define mutex_trylock(m) nxmutex_trylock(m)
# define mutex_breaklock(m,v) nxmutex_breaklock(m, v)
# define mutex_restorelock(m,v) nxmutex_restorelock(m, v)
# define mutex_clocklock(m,t) nxmutex_clocklock(m,CLOCK_REALTIME,t)
# define mutex_init(m) nxmutex_init(m)
# define mutex_destroy(m) nxmutex_destroy(m)
# define mutex_is_hold(m) nxmutex_is_hold(m)
# define mutex_is_recursive(m) (false)
# define mutex_is_locked(m) nxmutex_is_locked(m)
# define mutex_get_holder(m) nxmutex_get_holder(m)
# define mutex_reset(m) nxmutex_reset(m)
# define mutex_unlock(m) nxmutex_unlock(m)
# define mutex_lock(m) nxmutex_lock(m)
# define mutex_trylock(m) nxmutex_trylock(m)
# define mutex_breaklock(m,v) nxmutex_breaklock(m, v)
# define mutex_restorelock(m,v) nxmutex_restorelock(m, v)
# define mutex_clocklock(m,t) nxmutex_clocklock(m,CLOCK_REALTIME,t)
# define mutex_set_protocol(m,p) nxmutex_set_protocol(m,p)
# define mutex_getprioceiling(m,p) nxmutex_getprioceiling(m,p)
# define mutex_setprioceiling(m,p,o) nxmutex_setprioceiling(m,p,o)
#endif
/****************************************************************************