Index: uspace/lib/c/include/adt/list.h
===================================================================
--- uspace/lib/c/include/adt/list.h	(revision c072a292c19db94ad89515ef948e5fabe05dc9f1)
+++ uspace/lib/c/include/adt/list.h	(revision 5e3fa9dbfffc978cdcfdaaea9fc6a50dbb0bca1a)
@@ -58,5 +58,23 @@
  */
 #define LIST_INITIALIZE(name) \
-	list_t name = { \
+	list_t name = LIST_INITIALIZER(name)
+
+/** Initializer for statically allocated list.
+ * 
+ * @code
+ * struct named_list {
+ *     const char *name;
+ *     list_t list;
+ * } var = { 
+ *     .name = "default name", 
+ *     .list = LIST_INITIALIZER(name_list.list) 
+ * };
+ * @endcode
+ *
+ * @param name Name of the new statically allocated list.
+ *
+ */
+#define LIST_INITIALIZER(name) \
+	{ \
 		.head = { \
 			.prev = &(name).head, \
Index: uspace/lib/c/include/compiler/barrier.h
===================================================================
--- uspace/lib/c/include/compiler/barrier.h	(revision 5e3fa9dbfffc978cdcfdaaea9fc6a50dbb0bca1a)
+++ uspace/lib/c/include/compiler/barrier.h	(revision 5e3fa9dbfffc978cdcfdaaea9fc6a50dbb0bca1a)
@@ -0,0 +1,43 @@
+/*
+ * Copyright (c) 2012 Adam Hraska
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @addtogroup libc
+ * @{
+ */
+/** @file
+ */
+
+#ifndef LIBC_COMPILER_BARRIER_H_
+#define LIBC_COMPILER_BARRIER_H_
+
+#define compiler_barrier() asm volatile ("" ::: "memory")
+
+/** Forces the compiler to access (ie load/store) the variable only once. */
+#define ACCESS_ONCE(var) (*((volatile typeof(var)*)&(var)))
+
+#endif /* LIBC_COMPILER_BARRIER_H_ */
Index: uspace/lib/c/include/futex.h
===================================================================
--- uspace/lib/c/include/futex.h	(revision c072a292c19db94ad89515ef948e5fabe05dc9f1)
+++ uspace/lib/c/include/futex.h	(revision 5e3fa9dbfffc978cdcfdaaea9fc6a50dbb0bca1a)
@@ -38,13 +38,115 @@
 #include <atomic.h>
 #include <sys/types.h>
+#include <libc.h>
 
-#define FUTEX_INITIALIZER  {1}
+typedef struct futex {
+	atomic_t val;
+#ifdef FUTEX_UPGRADABLE
+	int upgraded;
+#endif
+} futex_t;
 
-typedef atomic_t futex_t;
 
 extern void futex_initialize(futex_t *futex, int value);
-extern int futex_down(futex_t *futex);
-extern int futex_trydown(futex_t *futex);
-extern int futex_up(futex_t *futex);
+
+#ifdef FUTEX_UPGRADABLE
+#include <rcu.h>
+
+#define FUTEX_INITIALIZE(val) {{ (val) }, 0}
+
+#define futex_lock(fut) \
+({ \
+	rcu_read_lock(); \
+	(fut)->upgraded = rcu_access(_upgrade_futexes); \
+	if ((fut)->upgraded) \
+		(void) futex_down((fut)); \
+})
+
+#define futex_trylock(fut) \
+({ \
+	rcu_read_lock(); \
+	int _upgraded = rcu_access(_upgrade_futexes); \
+	if (_upgraded) { \
+		int _acquired = futex_trydown((fut)); \
+		if (!_acquired) { \
+			rcu_read_unlock(); \
+		} else { \
+			(fut)->upgraded = true; \
+		} \
+		_acquired; \
+	} else { \
+		(fut)->upgraded = false; \
+		1; \
+	} \
+})
+		
+#define futex_unlock(fut) \
+({ \
+	if ((fut)->upgraded) \
+		(void) futex_up((fut)); \
+	rcu_read_unlock(); \
+})
+
+extern int _upgrade_futexes;
+
+extern void futex_upgrade_all_and_wait(void);
+		
+#else
+
+#define FUTEX_INITIALIZE(val) {{ (val) }}
+
+#define futex_lock(fut)     (void) futex_down((fut))
+#define futex_trylock(fut)  futex_trydown((fut))
+#define futex_unlock(fut)   (void) futex_up((fut))
+		
+#endif
+
+#define FUTEX_INITIALIZER     FUTEX_INITIALIZE(1)
+
+/** Try to down the futex.
+ *
+ * @param futex Futex.
+ *
+ * @return Non-zero if the futex was acquired.
+ * @return Zero if the futex was not acquired.
+ *
+ */
+static inline int futex_trydown(futex_t *futex)
+{
+	return cas(&futex->val, 1, 0);
+}
+
+/** Down the futex.
+ *
+ * @param futex Futex.
+ *
+ * @return ENOENT if there is no such virtual address.
+ * @return Zero in the uncontended case.
+ * @return Otherwise one of ESYNCH_OK_ATOMIC or ESYNCH_OK_BLOCKED.
+ *
+ */
+static inline int futex_down(futex_t *futex)
+{
+	if ((atomic_signed_t) atomic_predec(&futex->val) < 0)
+		return __SYSCALL1(SYS_FUTEX_SLEEP, (sysarg_t) &futex->val.count);
+	
+	return 0;
+}
+
+/** Up the futex.
+ *
+ * @param futex Futex.
+ *
+ * @return ENOENT if there is no such virtual address.
+ * @return Zero in the uncontended case.
+ *
+ */
+static inline int futex_up(futex_t *futex)
+{
+	if ((atomic_signed_t) atomic_postinc(&futex->val) < 0)
+		return __SYSCALL1(SYS_FUTEX_WAKEUP, (sysarg_t) &futex->val.count);
+	
+	return 0;
+}
 
 #endif
Index: uspace/lib/c/include/ipc/common.h
===================================================================
--- uspace/lib/c/include/ipc/common.h	(revision c072a292c19db94ad89515ef948e5fabe05dc9f1)
+++ uspace/lib/c/include/ipc/common.h	(revision 5e3fa9dbfffc978cdcfdaaea9fc6a50dbb0bca1a)
@@ -40,4 +40,5 @@
 #include <atomic.h>
 #include <abi/proc/task.h>
+#include <futex.h>
 
 #define IPC_FLAG_BLOCKING  0x01
@@ -51,5 +52,5 @@
 typedef sysarg_t ipc_callid_t;
 
-extern atomic_t async_futex;
+extern futex_t async_futex;
 
 #endif
Index: uspace/lib/c/include/malloc.h
===================================================================
--- uspace/lib/c/include/malloc.h	(revision c072a292c19db94ad89515ef948e5fabe05dc9f1)
+++ uspace/lib/c/include/malloc.h	(revision 5e3fa9dbfffc978cdcfdaaea9fc6a50dbb0bca1a)
@@ -48,4 +48,5 @@
 extern void *heap_check(void);
 
+extern void malloc_enable_multithreaded(void);
 #endif
 
Index: uspace/lib/c/include/rwlock.h
===================================================================
--- uspace/lib/c/include/rwlock.h	(revision c072a292c19db94ad89515ef948e5fabe05dc9f1)
+++ uspace/lib/c/include/rwlock.h	(revision 5e3fa9dbfffc978cdcfdaaea9fc6a50dbb0bca1a)
@@ -49,8 +49,8 @@
 
 #define rwlock_initialize(rwlock)	futex_initialize((rwlock), 1)
-#define rwlock_read_lock(rwlock)	futex_down((rwlock))
-#define rwlock_write_lock(rwlock)	futex_down((rwlock))
-#define rwlock_read_unlock(rwlock)	futex_up((rwlock))
-#define rwlock_write_unlock(rwlock)	futex_up((rwlock))
+#define rwlock_read_lock(rwlock)	futex_lock((rwlock))
+#define rwlock_write_lock(rwlock)	futex_lock((rwlock))
+#define rwlock_read_unlock(rwlock)	futex_unlock((rwlock))
+#define rwlock_write_unlock(rwlock)	futex_unlock((rwlock))
 
 #endif
Index: uspace/lib/c/include/smp_memory_barrier.h
===================================================================
--- uspace/lib/c/include/smp_memory_barrier.h	(revision 5e3fa9dbfffc978cdcfdaaea9fc6a50dbb0bca1a)
+++ uspace/lib/c/include/smp_memory_barrier.h	(revision 5e3fa9dbfffc978cdcfdaaea9fc6a50dbb0bca1a)
@@ -0,0 +1,43 @@
+/*
+ * Copyright (c) 2012 Adam Hraska
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @addtogroup libc
+ * @{
+ */
+/** @file
+ */
+
+#ifndef LIBC_SMP_MEM_BAR_H_
+#define LIBC_SMP_MEM_BAR_H_
+
+extern void smp_memory_barrier(void);
+
+#endif
+
+/** @}
+ */
Index: uspace/lib/c/include/sys/time.h
===================================================================
--- uspace/lib/c/include/sys/time.h	(revision c072a292c19db94ad89515ef948e5fabe05dc9f1)
+++ uspace/lib/c/include/sys/time.h	(revision 5e3fa9dbfffc978cdcfdaaea9fc6a50dbb0bca1a)
@@ -79,4 +79,5 @@
 
 extern void udelay(useconds_t);
+extern int usleep(useconds_t);
 
 extern time_t mktime(struct tm *tm);
