From 7bfd815b9fa61f0c35a34c1332156d3b83c0f73f Mon Sep 17 00:00:00 2001 From: Simon Vergauwen Date: Tue, 12 Sep 2023 08:00:55 +0200 Subject: [PATCH] Update Kotlin atomic usage --- .../src/nativeMain/kotlin/arrow/atomic/Atomic.kt | 5 +++-- .../src/nativeMain/kotlin/arrow/atomic/AtomicInt.kt | 4 ++-- .../src/nativeMain/kotlin/arrow/atomic/AtomicLong.kt | 8 ++++---- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/arrow-libs/core/arrow-atomic/src/nativeMain/kotlin/arrow/atomic/Atomic.kt b/arrow-libs/core/arrow-atomic/src/nativeMain/kotlin/arrow/atomic/Atomic.kt index 8ec8c45588c..44968d70ffe 100644 --- a/arrow-libs/core/arrow-atomic/src/nativeMain/kotlin/arrow/atomic/Atomic.kt +++ b/arrow-libs/core/arrow-atomic/src/nativeMain/kotlin/arrow/atomic/Atomic.kt @@ -1,7 +1,8 @@ @file:OptIn(FreezingIsDeprecated::class) + package arrow.atomic -import kotlin.native.concurrent.AtomicReference +import kotlin.concurrent.AtomicReference import kotlin.native.concurrent.freeze import kotlin.native.concurrent.isFrozen @@ -22,7 +23,7 @@ public actual class Atomic actual constructor(initialValue: V) { while (true) { val cur = inner.value if (cur === value) return cur - if (inner.compareAndSwap(cur, value) === cur) return cur + if (inner.compareAndSet(cur, value)) return cur } } } diff --git a/arrow-libs/core/arrow-atomic/src/nativeMain/kotlin/arrow/atomic/AtomicInt.kt b/arrow-libs/core/arrow-atomic/src/nativeMain/kotlin/arrow/atomic/AtomicInt.kt index c94040a9dc6..a6a4abc1c26 100644 --- a/arrow-libs/core/arrow-atomic/src/nativeMain/kotlin/arrow/atomic/AtomicInt.kt +++ b/arrow-libs/core/arrow-atomic/src/nativeMain/kotlin/arrow/atomic/AtomicInt.kt @@ -1,6 +1,6 @@ package arrow.atomic -import kotlin.native.concurrent.AtomicInt +import kotlin.concurrent.AtomicInt import kotlin.native.concurrent.freeze import kotlin.native.concurrent.isFrozen @@ -30,7 +30,7 @@ public actual class AtomicInt actual constructor(initialValue: Int) { while (true) { val cur = inner.value if (cur == value) return cur - if (inner.compareAndSwap(cur, value) == cur) return cur + if (inner.compareAndSet(cur, value)) return cur } } } diff --git a/arrow-libs/core/arrow-atomic/src/nativeMain/kotlin/arrow/atomic/AtomicLong.kt b/arrow-libs/core/arrow-atomic/src/nativeMain/kotlin/arrow/atomic/AtomicLong.kt index ea370e5724f..b8eac91280c 100644 --- a/arrow-libs/core/arrow-atomic/src/nativeMain/kotlin/arrow/atomic/AtomicLong.kt +++ b/arrow-libs/core/arrow-atomic/src/nativeMain/kotlin/arrow/atomic/AtomicLong.kt @@ -1,6 +1,6 @@ package arrow.atomic -import kotlin.native.concurrent.AtomicLong +import kotlin.concurrent.AtomicLong import kotlin.native.concurrent.freeze import kotlin.native.concurrent.isFrozen @@ -14,10 +14,10 @@ public actual class AtomicLong actual constructor(initialValue: Long) { } public actual fun incrementAndGet(): Long = - inner.addAndGet(1) + inner.addAndGet(1L) public actual fun decrementAndGet(): Long = - inner.addAndGet(-1) + inner.addAndGet(-1L) public actual fun addAndGet(delta: Long): Long = inner.addAndGet(delta) @@ -30,7 +30,7 @@ public actual class AtomicLong actual constructor(initialValue: Long) { while (true) { val cur = inner.value if (cur == value) return cur - if (inner.compareAndSwap(cur, value) == cur) return cur + if (inner.compareAndSet(cur, value)) return cur } } }