Index: webrtc/sources/system_wrappers/source/android/cpu-features.c
===================================================================
--- webrtc.orig/sources/system_wrappers/source/android/cpu-features.c	2012-10-18 23:04:34.456154966 +0200
+++ webrtc/sources/system_wrappers/source/android/cpu-features.c	2012-10-18 23:05:01.716153826 +0200
@@ -18,6 +18,7 @@
 #include <stdlib.h>
 #include <fcntl.h>
 #include <errno.h>
+#include <unistd.h>
 
 static  pthread_once_t     g_once;
 static  AndroidCpuFamily   g_cpuFamily;
@@ -26,6 +27,58 @@
 
 static const int  android_cpufeatures_debug = 0;
 
+
+
+/* Adapted from bionic_atomic_inline.h */
+static inline void ANDROID_MEMBAR_FULL(void) {
+#if defined(__arm__) && __ARM_ARCH__ >= 7
+    __asm__ __volatile__ ("dmb" ::: "memory");
+#elif defined(__arm__) && __ARM_ARCH__ == 6
+    /*
+     * See "Accessing the Data Memory Barrier operation" :
+     * http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.ddi0211i/I1014942.html
+     *
+     * From: https://casper.berkeley.edu/svn/trunk/roach/sw/linux/include/asm-arm/system.h
+     */
+    __asm__ __volatile__ ("mcr p15, 0, %0, c7, c10, 5" :: "r" (0) : "memory");
+#elif (defined(__i386__) || defined(__x86_64__)) && defined(__SSE2__)
+    __asm__ __volatile__ ("mfence" ::: "memory");
+#else
+    /*
+     * Implementation not defined for this platform.  Hopefully we're building
+     * in uniprocessor mode.
+     *
+     * For example: MIPS, PowerPC, ARMv5, etc
+     */
+    __asm__ __volatile__ ("" ::: "memory");
+#endif
+}
+
+/* NOTE: this implementation doesn't support a init function that throws a C++ exception
+ *       or calls fork()
+ */
+int pthread_once( pthread_once_t*  once_control,  void (*init_routine)(void) )
+{
+    if( once_control == NULL || init_routine == NULL )
+        return EINVAL;
+    static pthread_mutex_t   once_lock = PTHREAD_RECURSIVE_MUTEX_INITIALIZER;
+    volatile pthread_once_t* ocptr = once_control;
+
+    pthread_once_t tmp = *ocptr;
+    ANDROID_MEMBAR_FULL();
+    if (tmp == PTHREAD_ONCE_INIT) {
+        pthread_mutex_lock( &once_lock );
+        if (*ocptr == PTHREAD_ONCE_INIT) {
+            (*init_routine)();
+            ANDROID_MEMBAR_FULL();
+            *ocptr = ~PTHREAD_ONCE_INIT;
+        }
+        pthread_mutex_unlock( &once_lock );
+    }
+    return 0;
+}
+
+
 #ifdef __arm__
 #  define DEFAULT_CPU_FAMILY  ANDROID_CPU_FAMILY_ARM
 #elif defined __i386__
