summaryrefslogtreecommitdiff
path: root/kern/mutex.h
diff options
context:
space:
mode:
authorRichard Braun <rbraun@sceen.net>2017-03-04 16:27:05 +0100
committerRichard Braun <rbraun@sceen.net>2017-03-04 16:52:30 +0100
commitf4d75d0cd8424c17521d520fd9018ea22b7daaad (patch)
treea6f4807984c781e3584c79491ecb23e75f012ac6 /kern/mutex.h
parent3fcd23576e800ebbfb1378c2e6aff2e9e1027989 (diff)
kern/mutex: implement the --enable-mutex-pi option
This option turns all regular mutexes into real-time mutexes.
Diffstat (limited to 'kern/mutex.h')
-rw-r--r--kern/mutex.h46
1 files changed, 45 insertions, 1 deletions
diff --git a/kern/mutex.h b/kern/mutex.h
index 2804fc44..c8ae4639 100644
--- a/kern/mutex.h
+++ b/kern/mutex.h
@@ -25,10 +25,52 @@
#ifndef _KERN_MUTEX_H
#define _KERN_MUTEX_H
+#include <kern/mutex_types.h>
+
+#ifdef X15_MUTEX_PI
+
+#include <kern/rtmutex.h>
+
+struct mutex;
+
+#define mutex_assert_locked(mutex) rtmutex_assert_locked(&(mutex)->rtmutex)
+
+static inline void
+mutex_init(struct mutex *mutex)
+{
+ rtmutex_init(&mutex->rtmutex);
+}
+
+static inline int
+mutex_trylock(struct mutex *mutex)
+{
+ return rtmutex_trylock(&mutex->rtmutex);
+}
+
+static inline void
+mutex_lock(struct mutex *mutex)
+{
+ rtmutex_lock(&mutex->rtmutex);
+}
+
+static inline void
+mutex_unlock(struct mutex *mutex)
+{
+ rtmutex_unlock(&mutex->rtmutex);
+
+ /*
+ * If this mutex was used along with a condition variable, wake up
+ * a potential pending waiter. This must be done after the mutex is
+ * unlocked so that a higher priority thread can directly acquire it.
+ */
+ thread_wakeup_last_cond();
+}
+
+#else /* X15_MUTEX_PI */
+
#include <kern/assert.h>
#include <kern/error.h>
#include <kern/mutex_i.h>
-#include <kern/mutex_types.h>
#include <kern/thread.h>
struct mutex;
@@ -114,4 +156,6 @@ mutex_unlock(struct mutex *mutex)
thread_wakeup_last_cond();
}
+#endif /* X15_MUTEX_PI */
+
#endif /* _KERN_MUTEX_H */