summaryrefslogtreecommitdiff
path: root/kern/thread.h
diff options
context:
space:
mode:
authorRichard Braun <rbraun@sceen.net>2017-03-19 13:25:44 +0100
committerRichard Braun <rbraun@sceen.net>2017-03-19 13:25:44 +0100
commit447b54395ad134724a7cb91e0cb80745a95a5e80 (patch)
tree377122d1d313bb019f7df0b8984244c4445ef93f /kern/thread.h
parent91ee89778de7a5d392c57d80e9a8aa1fba347d15 (diff)
kern/thread: formally define interrupt context
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 28404fb4..486d6fae 100644
--- a/kern/thread.h
+++ b/kern/thread.h
@@ -600,6 +600,49 @@ thread_preempt_disable(void)
}
/*
+ * Interrupt level control functions.
+ *
+ * Functions that change the interrupt level are implicit compiler barriers.
+ */
+
+static inline bool
+thread_interrupted(void)
+{
+ return (thread_self()->intr != 0);
+}
+
+static inline void
+thread_intr_enter(void)
+{
+ struct thread *thread;
+
+ thread = thread_self();
+
+ if (thread->intr == 0) {
+ thread_preempt_disable();
+ }
+
+ thread->intr++;
+ assert(thread->intr != 0);
+ barrier();
+}
+
+static inline void
+thread_intr_leave(void)
+{
+ struct thread *thread;
+
+ barrier();
+ thread = thread_self();
+ assert(thread->intr != 0);
+ thread->intr--;
+
+ if (thread->intr == 0) {
+ thread_preempt_enable_no_resched();
+ }
+}
+
+/*
* Lockless synchronization read-side critical section nesting counter
* control functions.
*/