Fix MIPS atomics.

This commit is contained in:
Nikolay Igotti
2018-07-04 02:55:47 +03:00
committed by Pavel Punegov
parent 96b0d10746
commit d50c16456e
+15 -1
View File
@@ -58,7 +58,21 @@ KLong Kotlin_AtomicLong_addAndGet(KRef thiz, KLong delta) {
}
KLong Kotlin_AtomicLong_compareAndSwap(KRef thiz, KLong expectedValue, KLong newValue) {
#ifdef __mips
// Potentially huge performance penalty, but correct.
// TODO: reconsider, once target MIPS can do proper 64-bit CAS.
static int lock = 0;
while (compareAndSwap(&lock, 0, 1) != 0);
KLong* address = reinterpret_cast<KLong*>(thiz + 1);
KLong old = *address;
if (old == expectedValue) {
*address = newValue;
}
compareAndSwap(&lock, 1, 0);
return old;
#else
return compareAndSwapImpl(thiz, expectedValue, newValue);
#endif
}
KNativePtr Kotlin_AtomicNativePtr_compareAndSwap(KRef thiz, KNativePtr expectedValue, KNativePtr newValue) {
@@ -87,4 +101,4 @@ OBJ_GETTER(Kotlin_AtomicReference_get, KRef thiz) {
RETURN_RESULT_OF(ReadRefLocked, &ref->value_, &ref->lock_);
}
} // extern "C"
} // extern "C"