Fix MIPS atomics.
This commit is contained in:
committed by
Pavel Punegov
parent
96b0d10746
commit
d50c16456e
@@ -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"
|
||||
|
||||
Reference in New Issue
Block a user