Index: generic/src/synch/futex.c
===================================================================
--- generic/src/synch/futex.c	(revision 9aa72b42058acb9ec55cd96d960e524465201dc6)
+++ generic/src/synch/futex.c	(revision 9cbd27bda027a69ffbcba03ec98a8179d37e83f0)
@@ -30,13 +30,14 @@
  * Kernel backend for futexes.
  * Deallocation of orphaned kernel-side futex structures is not currently implemented.
- * Timeouting futexes are currently not implemented.
  */
 
 #include <synch/futex.h>
 #include <synch/rwlock.h>
+#include <synch/spinlock.h>
 #include <synch/synch.h>
 #include <mm/frame.h>
 #include <mm/page.h>
 #include <mm/slab.h>
+#include <proc/thread.h>
 #include <genarch/mm/page_pt.h>
 #include <genarch/mm/page_ht.h>
@@ -91,9 +92,11 @@
  *
  * @param uaddr Userspace address of the futex counter.
- *
- * @return One of ESYNCH_OK_ATOMIC and ESYNCH_OK_BLOCKED. See synch.h.
+ * @param usec If non-zero, number of microseconds this thread is willing to sleep.
+ * @param trydown If usec is zero and trydown is non-zero, conditional operation will be attempted.
+ *
+ * @return One of ESYNCH_TIMEOUT, ESYNCH_OK_ATOMIC and ESYNCH_OK_BLOCKED. See synch.h.
  *	   If there is no physical mapping for uaddr ENOENT is returned.
  */
-__native sys_futex_sleep(__address uaddr)
+__native sys_futex_sleep_timeout(__address uaddr, __u32 usec, int trydown)
 {
 	futex_t *futex;
@@ -101,5 +104,8 @@
 	link_t *item;
 	pte_t *t;
-	
+	ipl_t ipl;
+	
+	ipl = interrupts_disable();
+
 	/*
 	 * Find physical address of futex counter.
@@ -109,4 +115,5 @@
 	if (!t || !PTE_VALID(t) || !PTE_PRESENT(t)) {
 		page_table_unlock(AS, true);
+		interrupts_restore(ipl);
 		return (__native) ENOENT;
 	}
@@ -114,4 +121,6 @@
 	page_table_unlock(AS, true);
 	
+	interrupts_restore(ipl);	
+
 	/*
 	 * Find the respective futex structure
@@ -149,5 +158,5 @@
 	}
 	
-	return (__native) waitq_sleep(&futex->wq);
+	return (__native) waitq_sleep_timeout(&futex->wq, usec, trydown);
 }
 
@@ -165,4 +174,7 @@
 	link_t *item;
 	pte_t *t;
+	ipl_t ipl;
+	
+	ipl = interrupts_disable();
 	
 	/*
@@ -173,4 +185,5 @@
 	if (!t || !PTE_VALID(t) || !PTE_PRESENT(t)) {
 		page_table_unlock(AS, true);
+		interrupts_restore(ipl);
 		return (__native) ENOENT;
 	}
@@ -178,4 +191,6 @@
 	page_table_unlock(AS, true);
 	
+	interrupts_restore(ipl);
+
 	/*
 	 * Find the respective futex structure.
@@ -187,5 +202,5 @@
 	}
 	rwlock_read_unlock(&futex_ht_lock);
-	
+
 	if (!futex)
 		return (__native) ENOENT;	
