Fix Arm32 atomics

This commit is contained in:
Mattia Iavarone
2021-10-21 17:26:49 +02:00
committed by Alexander Shabalin
parent 489c9ae11f
commit 64a0d492b9
2 changed files with 16 additions and 5 deletions
+1 -1
View File
@@ -770,7 +770,7 @@ clangNooptFlags.android_arm32 = -O1
targetSysRoot.android_arm32 = target-sysroot-1-android_ndk
linkerKonanFlags.android_arm32 = -lm -lc++_static -lc++abi -landroid -llog -latomic
runtimeDefinitions.android_arm32 = __ANDROID__ USE_GCC_UNWIND=1 USE_ELF_SYMBOLS=1 ELFSIZE=32 \
KONAN_ANDROID=1 KONAN_ARM32=1 KONAN_NO_UNALIGNED_ACCESS=1
KONAN_ANDROID=1 KONAN_ARM32=1 KONAN_NO_UNALIGNED_ACCESS=1 KONAN_NO_64BIT_ATOMIC=1
# Android ARM64, based on NDK.
targetToolchain.macos_x64-android_arm64 = target-toolchain-2-osx-android_ndk
+15 -4
View File
@@ -92,14 +92,25 @@ KInt Kotlin_AtomicInt_get(KRef thiz) {
return getImpl<KInt>(thiz);
}
KLong Kotlin_AtomicLong_addAndGet(KRef thiz, KLong delta) {
return addAndGetImpl(thiz, delta);
}
#if KONAN_NO_64BIT_ATOMIC
static int lock64 = 0;
#endif
KLong Kotlin_AtomicLong_addAndGet(KRef thiz, KLong delta) {
#if KONAN_NO_64BIT_ATOMIC
// Potentially huge performance penalty, but correct.
while (compareAndSwap(&lock64, 0, 1) != 0);
volatile KLong* address = getValueLocation<KLong>(thiz);
KLong old = *address;
KLong newValue = old + delta;
*address = newValue;
compareAndSwap(&lock64, 1, 0);
return newValue;
#else
return addAndGetImpl(thiz, delta);
#endif
}
KLong Kotlin_AtomicLong_compareAndSwap(KRef thiz, KLong expectedValue, KLong newValue) {
#if KONAN_NO_64BIT_ATOMIC
// Potentially huge performance penalty, but correct.