diff --git a/runtime/src/main/cpp/Atomic.cpp b/runtime/src/main/cpp/Atomic.cpp index 8b7b24be27e..4ec1f685f92 100644 --- a/runtime/src/main/cpp/Atomic.cpp +++ b/runtime/src/main/cpp/Atomic.cpp @@ -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(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" \ No newline at end of file +} // extern "C"