Index: kernel/generic/include/proc/scheduler.h
===================================================================
--- kernel/generic/include/proc/scheduler.h	(revision 11d2c98362478850f6d9f3d23e3a07426ab94485)
+++ kernel/generic/include/proc/scheduler.h	(revision 6188fee70f91508871094638e99dcaf9d73efdc0)
@@ -57,4 +57,5 @@
 extern void scheduler_fpu_lazy_request(void);
 extern void scheduler(void);
+extern void scheduler_locked(ipl_t);
 extern void kcpulb(void *arg);
 
Index: kernel/generic/include/proc/thread.h
===================================================================
--- kernel/generic/include/proc/thread.h	(revision 11d2c98362478850f6d9f3d23e3a07426ab94485)
+++ kernel/generic/include/proc/thread.h	(revision 6188fee70f91508871094638e99dcaf9d73efdc0)
@@ -79,4 +79,7 @@
 	odlink_t lthreads;
 
+	/** Tracking variable for thread_wait/thread_wakeup */
+	atomic_int sleep_state;
+
 	/**
 	 * If true, the thread is terminating.
@@ -85,4 +88,7 @@
 	 */
 	volatile bool interrupted;
+
+	/** Wait queue in which this thread sleeps. Used for debug printouts. */
+	_Atomic(waitq_t *) sleep_queue;
 
 	/** Waitq for thread_join_timeout(). */
@@ -108,29 +114,4 @@
 	context_t saved_context;
 	ipl_t saved_ipl;
-
-	/**
-	 * From here, the stored timeout context
-	 * is restored when sleep times out.
-	 */
-	context_t sleep_timeout_context;
-
-	/**
-	 * From here, the stored interruption context
-	 * is restored when sleep is interrupted.
-	 */
-	context_t sleep_interruption_context;
-
-	/** If true, the thread can be interrupted from sleep. */
-	bool sleep_interruptible;
-
-	/**
-	 * If true, and this thread's sleep returns without a wakeup
-	 * (timed out or interrupted), waitq ignores the next wakeup.
-	 * This is necessary for futex to be able to handle those conditions.
-	 */
-	bool sleep_composable;
-
-	/** Wait queue in which this thread sleeps. */
-	waitq_t *sleep_queue;
 
 	/**
@@ -216,5 +197,19 @@
 extern void thread_ready(thread_t *);
 extern void thread_exit(void) __attribute__((noreturn));
-extern void thread_interrupt(thread_t *, bool);
+extern void thread_interrupt(thread_t *);
+
+typedef enum {
+	THREAD_OK,
+	THREAD_TERMINATING,
+} thread_termination_state_t;
+
+typedef enum {
+	THREAD_WAIT_SUCCESS,
+	THREAD_WAIT_TIMEOUT,
+} thread_wait_result_t;
+
+extern thread_termination_state_t thread_wait_start(void);
+extern thread_wait_result_t thread_wait_finish(deadline_t);
+extern void thread_wakeup(thread_t *);
 
 static inline thread_t *thread_ref(thread_t *thread)
