From 4a909b931f4e24f37bd54c15579cf744e52d9294 Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Tue, 20 Dec 2016 15:06:13 +0100 Subject: [PATCH] os: enable priority inheritance for RTT mutexes Signed-off-by: Johannes Meyer --- rtt/os/gnulinux/fosi.h | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/rtt/os/gnulinux/fosi.h b/rtt/os/gnulinux/fosi.h index 5f2d3b1e2..96049e86a 100644 --- a/rtt/os/gnulinux/fosi.h +++ b/rtt/os/gnulinux/fosi.h @@ -135,7 +135,7 @@ extern "C" * This function should return ticks, * but we use ticks == nsecs in userspace */ - static inline NANO_TIME rtos_get_time_ticks() + static inline NANO_TIME rtos_get_time_ticks(void) { return rtos_get_time_ns(); } @@ -205,7 +205,17 @@ extern "C" static inline int rtos_mutex_init(rt_mutex_t* m) { - return pthread_mutex_init(m, 0 ); + pthread_mutexattr_t attr; + int ret = pthread_mutexattr_init(&attr); + if (ret != 0) return ret; + + ret = pthread_mutexattr_setprotocol(&attr, PTHREAD_PRIO_INHERIT); + if (ret != 0) return ret; + + ret = pthread_mutex_init(m, &attr); + + pthread_mutexattr_destroy(&attr); + return ret; } static inline int rtos_mutex_destroy(rt_mutex_t* m ) @@ -222,6 +232,8 @@ extern "C" // make mutex recursive ret = pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE_NP); if (ret != 0) return ret; + ret = pthread_mutexattr_setprotocol(&attr, PTHREAD_PRIO_INHERIT); + if (ret != 0) return ret; ret = pthread_mutex_init(m, &attr); @@ -304,14 +316,6 @@ extern "C" return pthread_mutex_unlock(m); } - static inline void rtos_enable_rt_warning() - { - } - - static inline void rtos_disable_rt_warning() - { - } - typedef pthread_cond_t rt_cond_t; static inline int rtos_cond_init(rt_cond_t *cond) @@ -354,6 +358,14 @@ extern "C" return pthread_cond_broadcast(cond); } + static inline void rtos_enable_rt_warning(void) + { + } + + static inline void rtos_disable_rt_warning(void) + { + } + #define rtos_printf printf #ifdef __cplusplus