[K2, MPP] Actualize value class representation

^KT-63638 fixed
This commit is contained in:
Nikita Nazarov
2023-12-03 21:08:53 +01:00
committed by Space Cloud
parent 0bd6ea764e
commit 438b2dd164
7 changed files with 74 additions and 4 deletions
@@ -0,0 +1,39 @@
// ISSUE: KT-63638
// !LANGUAGE: +MultiPlatformProjects
// TARGET_BACKEND: JVM_IR
// WITH_STDLIB
// MODULE: common
// TARGET_PLATFORM: Common
// FILE: expect.kt
import kotlin.jvm.JvmInline
class Session<T>(val value: T)
@JvmInline
value class SessionMutex<T> private constructor(
private val currentSessionHolder: AtomicReference<Session<T>?>
) {
constructor() : this(AtomicReference(null))
val currentSession: T?
get() = currentSessionHolder.get()?.value
}
expect class AtomicReference<V>(value: V) {
fun get(): V
fun set(value: V)
fun getAndSet(value: V): V
fun compareAndSet(expect: V, newValue: V): Boolean
}
// MODULE: main()()(common)
// FILE: actual.kt
internal actual typealias AtomicReference<V> = java.util.concurrent.atomic.AtomicReference<V>
fun box(): String {
val mutex = SessionMutex<Int>()
return "OK"
}