Skip to content

Commit

Permalink
nxmutex: export priority ceiling interfaces with nxsem
Browse files Browse the repository at this point in the history
Signed-off-by: makejian <[email protected]>
  • Loading branch information
makejian committed Sep 9, 2024
1 parent 10adf17 commit f5f6f53
Show file tree
Hide file tree
Showing 3 changed files with 170 additions and 26 deletions.
66 changes: 66 additions & 0 deletions include/nuttx/mutex.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down Expand Up @@ -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
}
Expand Down
72 changes: 72 additions & 0 deletions libs/libc/misc/lib_mutex.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down
58 changes: 32 additions & 26 deletions sched/pthread/pthread.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

/****************************************************************************
Expand Down

0 comments on commit f5f6f53

Please sign in to comment.