nxmutex: export priority ceiling interfaces with nxsem
Signed-off-by: makejian <makejian@xiaomi.com>
diff --git a/include/nuttx/mutex.h b/include/nuttx/mutex.h
index 6299fd3..315a232 100644
--- a/include/nuttx/mutex.h
+++ b/include/nuttx/mutex.h
@@ -337,6 +337,65 @@
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
*
* Description:
@@ -615,6 +674,13 @@
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
}
diff --git a/libs/libc/misc/lib_mutex.c b/libs/libc/misc/lib_mutex.c
index a00df06..ae783a1 100644
--- a/libs/libc/misc/lib_mutex.c
+++ b/libs/libc/misc/lib_mutex.c
@@ -481,6 +481,78 @@
}
/****************************************************************************
+ * 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
*
* Description:
diff --git a/sched/pthread/pthread.h b/sched/pthread/pthread.h
index 6e7dd8b..869a136 100644
--- a/sched/pthread/pthread.h
+++ b/sched/pthread/pthread.h
@@ -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
/****************************************************************************