Index: kernel/generic/src/proc/scheduler.c
===================================================================
--- kernel/generic/src/proc/scheduler.c	(revision 6f4495f5c6915097f277fabc29a874343f77e88a)
+++ kernel/generic/src/proc/scheduler.c	(revision 0b3a78fec9fcd0f2d1ba2ad32efec95c4ad2cfdf)
@@ -45,4 +45,5 @@
 #include <mm/page.h>
 #include <mm/as.h>
+#include <time/timeout.h>
 #include <time/delay.h>
 #include <arch/asm.h>
@@ -53,9 +54,9 @@
 #include <config.h>
 #include <context.h>
+#include <fpu_context.h>
 #include <func.h>
 #include <arch.h>
 #include <adt/list.h>
 #include <panic.h>
-#include <typedefs.h>
 #include <cpu.h>
 #include <print.h>
Index: kernel/generic/src/proc/task.c
===================================================================
--- kernel/generic/src/proc/task.c	(revision 6f4495f5c6915097f277fabc29a874343f77e88a)
+++ kernel/generic/src/proc/task.c	(revision 0b3a78fec9fcd0f2d1ba2ad32efec95c4ad2cfdf)
@@ -364,5 +364,5 @@
 		
 		if (sleeping)
-			waitq_interrupt_sleep(thr);
+			thread_interrupt_sleep(thr);
 	}
 	
Index: kernel/generic/src/proc/the.c
===================================================================
--- kernel/generic/src/proc/the.c	(revision 6f4495f5c6915097f277fabc29a874343f77e88a)
+++ kernel/generic/src/proc/the.c	(revision 0b3a78fec9fcd0f2d1ba2ad32efec95c4ad2cfdf)
@@ -43,5 +43,4 @@
 
 #include <arch.h>
-#include <typedefs.h>
 
 
Index: kernel/generic/src/proc/thread.c
===================================================================
--- kernel/generic/src/proc/thread.c	(revision 6f4495f5c6915097f277fabc29a874343f77e88a)
+++ kernel/generic/src/proc/thread.c	(revision 0b3a78fec9fcd0f2d1ba2ad32efec95c4ad2cfdf)
@@ -54,6 +54,6 @@
 #include <adt/btree.h>
 #include <adt/list.h>
-#include <typedefs.h>
 #include <time/clock.h>
+#include <time/timeout.h>
 #include <config.h>
 #include <arch/interrupt.h>
@@ -679,4 +679,57 @@
 }
 
+/** Interrupt sleeping thread.
+ *
+ * This routine attempts to interrupt a thread from its sleep in a waitqueue.
+ * If the thread is not found sleeping, no action is taken.
+ *
+ * @param t Thread to be interrupted.
+ */
+void thread_interrupt_sleep(thread_t *t)
+{
+	waitq_t *wq;
+	bool do_wakeup = false;
+	ipl_t ipl;
+
+	ipl = interrupts_disable();
+	spinlock_lock(&threads_lock);
+	if (!thread_exists(t))
+		goto out;
+
+grab_locks:
+	spinlock_lock(&t->lock);
+	if ((wq = t->sleep_queue)) {		/* assignment */
+		if (!(t->sleep_interruptible)) {
+			/*
+			 * The sleep cannot be interrupted.
+			 */
+			spinlock_unlock(&t->lock);
+			goto out;
+		}
+			
+		if (!spinlock_trylock(&wq->lock)) {
+			spinlock_unlock(&t->lock);
+			goto grab_locks;	/* avoid deadlock */
+		}
+
+		if (t->timeout_pending && timeout_unregister(&t->sleep_timeout))
+			t->timeout_pending = false;
+
+		list_remove(&t->wq_link);
+		t->saved_context = t->sleep_interruption_context;
+		do_wakeup = true;
+		t->sleep_queue = NULL;
+		spinlock_unlock(&wq->lock);
+	}
+	spinlock_unlock(&t->lock);
+
+	if (do_wakeup)
+		thread_ready(t);
+
+out:
+	spinlock_unlock(&threads_lock);
+	interrupts_restore(ipl);
+}
+
 /** @}
  */
