summaryrefslogtreecommitdiffstats
path: root/libstdc++/src/one_time_construction.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'libstdc++/src/one_time_construction.cpp')
-rw-r--r--libstdc++/src/one_time_construction.cpp19
1 files changed, 12 insertions, 7 deletions
diff --git a/libstdc++/src/one_time_construction.cpp b/libstdc++/src/one_time_construction.cpp
index 304afb8..2a44c79 100644
--- a/libstdc++/src/one_time_construction.cpp
+++ b/libstdc++/src/one_time_construction.cpp
@@ -10,10 +10,8 @@
#include <stddef.h>
#include <sys/atomics.h>
-
-extern "C" int __futex_wait(volatile void *ftx, int val, const struct timespec *timeout);
-extern "C" int __futex_wake(volatile void *ftx, int count);
-
+#include <bionic_futex.h>
+#include <bionic_atomic_inline.h>
extern "C" int __cxa_guard_acquire(int volatile * gv)
{
@@ -22,13 +20,17 @@ extern "C" int __cxa_guard_acquire(int volatile * gv)
// 6 untouched, wait and return 0
// 1 untouched, return 0
retry:
- if (__atomic_cmpxchg(0, 0x2, gv) == 0)
+ if (__atomic_cmpxchg(0, 0x2, gv) == 0) {
+ ANDROID_MEMBAR_FULL();
return 1;
-
+ }
__atomic_cmpxchg(0x2, 0x6, gv); // Indicate there is a waiter
__futex_wait(gv, 0x6, NULL);
+
if(*gv != 1) // __cxa_guard_abort was called, let every thread try since there is no return code for this condition
goto retry;
+
+ ANDROID_MEMBAR_FULL();
return 0;
}
@@ -36,8 +38,10 @@ extern "C" void __cxa_guard_release(int volatile * gv)
{
// 2 -> 1
// 6 -> 1, and wake
- if (__atomic_cmpxchg(0x2, 0x1, gv) == 0)
+ ANDROID_MEMBAR_FULL();
+ if (__atomic_cmpxchg(0x2, 0x1, gv) == 0) {
return;
+ }
*gv = 0x1;
__futex_wake(gv, 0x7fffffff);
@@ -45,6 +49,7 @@ extern "C" void __cxa_guard_release(int volatile * gv)
extern "C" void __cxa_guard_abort(int volatile * gv)
{
+ ANDROID_MEMBAR_FULL();
*gv = 0;
__futex_wake(gv, 0x7fffffff);
}