summaryrefslogtreecommitdiff
path: root/kern/thread.h
diff options
context:
space:
mode:
authorRichard Braun <rbraun@sceen.net>2017-03-04 16:09:51 +0100
committerRichard Braun <rbraun@sceen.net>2017-03-04 16:52:29 +0100
commit3ae5551b3368b16ddbc1441710e1f272b1c0ad22 (patch)
treeca8910cf5638fb390bf9b34ab3ca98a3a9e66c8a /kern/thread.h
parentef9426483f2f388c4874c6b12e0800645c3dbce4 (diff)
kern/{condition,mutex}: reimplement on top of sleep queues
Diffstat (limited to 'kern/thread.h')
-rw-r--r--kern/thread.h43
1 files changed, 43 insertions, 0 deletions
diff --git a/kern/thread.h b/kern/thread.h
index 15babbfc..b9308b65 100644
--- a/kern/thread.h
+++ b/kern/thread.h
@@ -37,6 +37,7 @@
#include <stddef.h>
#include <kern/assert.h>
+#include <kern/condition.h>
#include <kern/cpumap.h>
#include <kern/macros.h>
#include <kern/spinlock_types.h>
@@ -436,6 +437,48 @@ thread_sleepq_return(struct sleepq *sleepq)
}
/*
+ * Condition variable related functions.
+ */
+
+static inline void
+thread_set_last_cond(struct condition *last_cond)
+{
+ struct thread *thread;
+
+ thread = thread_self();
+ assert(thread->last_cond == NULL);
+ thread->last_cond = last_cond;
+}
+
+static inline struct condition *
+thread_pull_last_cond(void)
+{
+ struct condition *last_cond;
+ struct thread *thread;
+
+ thread = thread_self();
+ last_cond = thread->last_cond;
+
+ if (last_cond != NULL) {
+ thread->last_cond = NULL;
+ }
+
+ return last_cond;
+}
+
+static inline void
+thread_wakeup_last_cond(void)
+{
+ struct condition *last_cond;
+
+ last_cond = thread_pull_last_cond();
+
+ if (last_cond != NULL) {
+ condition_wakeup(last_cond);
+ }
+}
+
+/*
* Turnstile lending functions.
*/