5c5367d377
The following updates in the JVM/IR plugin were made: * Lots of refactoring with preparation for K/N support: commonization of transformations. * Improved error handling (checks for visibility constraints, appending message about usage constraints in case of an error). * Explicit requirements for the visibility of atomic properties: to prevent leaking they should be private/internal or be members of private/internal classes. * Fixed visibility of generated properties: volatile properties are always private and atomic updaters have the same visibility as the original atomic property. * Volatile fields are generated from scratch and original atomic properties are removed. * Delegated properties support is fixed (only declaration in the same scope is allowed). * Non-inline atomic extensions are forbidden. * For top-level atomics: only one wrapper class per file (with corresponding visibility) is generated. * Bug fixes. The corresponding tickets: https://github.com/Kotlin/kotlinx-atomicfu/issues/322 KT-60528 Merge-request: KT-MR-10579 Merged-by: Maria Sokolova <maria.sokolova@jetbrains.com>
52 lines
1.4 KiB
Kotlin
Vendored
52 lines
1.4 KiB
Kotlin
Vendored
import kotlinx.atomicfu.*
|
|
import kotlin.test.*
|
|
|
|
class LoopTest {
|
|
private val a = atomic(10)
|
|
private val b = atomic(11)
|
|
private val c = atomic(12)
|
|
private val r = atomic<String>("aaa")
|
|
private val intArr = AtomicIntArray(10)
|
|
|
|
private inline fun AtomicInt.extensionEmbeddedLoops(to: Int): Int =
|
|
loop { cur1 ->
|
|
compareAndSet(cur1, to)
|
|
loop { cur2 ->
|
|
return cur2
|
|
}
|
|
}
|
|
|
|
private inline fun embeddedLoops(to: Int): Int =
|
|
a.loop { aValue ->
|
|
b.loop { bValue ->
|
|
if (b.compareAndSet(bValue, to)) return aValue + bValue
|
|
}
|
|
}
|
|
|
|
private inline fun embeddedUpdate(to: Int): Int =
|
|
a.loop { aValue ->
|
|
a.compareAndSet(aValue, to)
|
|
return a.updateAndGet { cur -> cur + 100 }
|
|
}
|
|
|
|
private inline fun AtomicRef<String>.extesntionEmbeddedRefUpdate(to: String): String =
|
|
loop { value ->
|
|
compareAndSet(value, to)
|
|
return updateAndGet { cur -> "${cur}AAA" }
|
|
}
|
|
|
|
fun test() {
|
|
assertEquals(21, embeddedLoops(12))
|
|
assertEquals(77, c.extensionEmbeddedLoops(77))
|
|
assertEquals(66, intArr[0].extensionEmbeddedLoops(66))
|
|
assertEquals(166, embeddedUpdate(66))
|
|
assertEquals("bbbAAA", r.extesntionEmbeddedRefUpdate("bbb"))
|
|
}
|
|
}
|
|
|
|
fun box(): String {
|
|
val testClass = LoopTest()
|
|
testClass.test()
|
|
return "OK"
|
|
}
|