Index: generic/src/synch/futex.c
===================================================================
--- generic/src/synch/futex.c	(revision 448743faad429fa6c2d3aee5cedc3d677ca2ff1b)
+++ generic/src/synch/futex.c	(revision a9ef68bfb5a4d2d85ccd7edf79d3fcc2f7c9d108)
@@ -54,4 +54,5 @@
 static void futex_initialize(futex_t *futex);
 
+static futex_t *futex_find(__address paddr);
 static index_t futex_ht_hash(__native *key);
 static bool futex_ht_compare(__native *key, count_t keys, link_t *item);
@@ -102,5 +103,4 @@
 	futex_t *futex;
 	__address paddr;
-	link_t *item;
 	pte_t *t;
 	ipl_t ipl;
@@ -123,4 +123,60 @@
 	interrupts_restore(ipl);	
 
+	futex = futex_find(paddr);
+	
+	return (__native) waitq_sleep_timeout(&futex->wq, usec, trydown);
+}
+
+/** Wakeup one thread waiting in futex wait queue.
+ *
+ * @param uaddr Userspace address of the futex counter.
+ *
+ * @return ENOENT if there is no futex associated with the address
+ *	   or if there is no physical mapping for uaddr.
+ */
+__native sys_futex_wakeup(__address uaddr)
+{
+	futex_t *futex;
+	__address paddr;
+	pte_t *t;
+	ipl_t ipl;
+	
+	ipl = interrupts_disable();
+	
+	/*
+	 * Find physical address of futex counter.
+	 */
+	page_table_lock(AS, true);
+	t = page_mapping_find(AS, ALIGN_DOWN(uaddr, PAGE_SIZE));
+	if (!t || !PTE_VALID(t) || !PTE_PRESENT(t)) {
+		page_table_unlock(AS, true);
+		interrupts_restore(ipl);
+		return (__native) ENOENT;
+	}
+	paddr = PFN2ADDR(PTE_GET_FRAME(t)) + (uaddr - ALIGN_DOWN(uaddr, PAGE_SIZE));
+	page_table_unlock(AS, true);
+	
+	interrupts_restore(ipl);
+
+	futex = futex_find(paddr);
+		
+	waitq_wakeup(&futex->wq, WAKEUP_FIRST);
+	
+	return 0;
+}
+
+/** Find kernel address of the futex structure corresponding to paddr.
+ *
+ * If the structure does not exist alreay, a new one is created.
+ *
+ * @param paddr Physical address of the userspace futex counter.
+ *
+ * @return Address of the kernel futex structure.
+ */
+futex_t *futex_find(__address paddr)
+{
+	link_t *item;
+	futex_t *futex;
+	
 	/*
 	 * Find the respective futex structure
@@ -142,5 +198,5 @@
 		rwlock_write_lock(&futex_ht_lock);
 		/*
-		 * Detect possible race condition by searching
+		 * Avoid possible race condition by searching
 		 * the hash table once again with write access.
 		 */
@@ -158,55 +214,5 @@
 	}
 	
-	return (__native) waitq_sleep_timeout(&futex->wq, usec, trydown);
-}
-
-/** Wakeup one thread waiting in futex wait queue.
- *
- * @param uaddr Userspace address of the futex counter.
- *
- * @return ENOENT if there is no futex associated with the address
- *	   or if there is no physical mapping for uaddr.
- */
-__native sys_futex_wakeup(__address uaddr)
-{
-	futex_t *futex = NULL;
-	__address paddr;
-	link_t *item;
-	pte_t *t;
-	ipl_t ipl;
-	
-	ipl = interrupts_disable();
-	
-	/*
-	 * Find physical address of futex counter.
-	 */
-	page_table_lock(AS, true);
-	t = page_mapping_find(AS, ALIGN_DOWN(uaddr, PAGE_SIZE));
-	if (!t || !PTE_VALID(t) || !PTE_PRESENT(t)) {
-		page_table_unlock(AS, true);
-		interrupts_restore(ipl);
-		return (__native) ENOENT;
-	}
-	paddr = PFN2ADDR(PTE_GET_FRAME(t)) + (uaddr - ALIGN_DOWN(uaddr, PAGE_SIZE));
-	page_table_unlock(AS, true);
-	
-	interrupts_restore(ipl);
-
-	/*
-	 * Find the respective futex structure.
-	 */
-	rwlock_read_lock(&futex_ht_lock);
-	item = hash_table_find(&futex_ht, &paddr);
-	if (item) {
-		futex = hash_table_get_instance(item, futex_t, ht_link);
-	}
-	rwlock_read_unlock(&futex_ht_lock);
-
-	if (!futex)
-		return (__native) ENOENT;	
-		
-	waitq_wakeup(&futex->wq, WAKEUP_FIRST);
-	
-	return 0;
+	return futex;
 }
 
