Skip to content

Commit

Permalink
Update Kotlin atomic usage
Browse files Browse the repository at this point in the history
  • Loading branch information
nomisRev committed Sep 12, 2023
1 parent 0ef8634 commit 7bfd815
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -22,7 +23,7 @@ public actual class Atomic<V> 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
}
}
}
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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
}
}
}
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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)
Expand All @@ -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
}
}
}
Expand Down

0 comments on commit 7bfd815

Please sign in to comment.