Wrapper around kotlinx.cinterop.NativePtr with atomic synchronized operations.
Wrapper around Kotlin object with atomic operations.
class Continuation0 : () -> Unit
class Continuation1<T1> : (T1) -> Unit
class Continuation2<T1, T2> : (T1, T2) -> Unit
Detached object graph encapsulates transferrable detached subgraph which cannot be accessed externally, until it is attached with the attach extension function.
Note: this class is useful only with legacy memory manager. Please use AtomicReference instead.
Exception thrown whenever freezing is not possible.
class FreezingException : RuntimeException
State of the future object.
enum class FutureState
Exception thrown whenever we attempt to mutate frozen objects.
class InvalidMutabilityException : RuntimeException
Mutable concurrently accessible data buffer. Could be accessed from several workers simulteniously.
Note: modern Kotlin/Native memory manager allows to share objects between threads without additional ceremonies, so TransferMode has effect only in legacy memory manager.
enum class TransferMode
A shared reference to a Kotlin object that doesn't freeze the referred object when it gets frozen itself.
class WorkerBoundReference<out T : Any>
Note: this annotation has effect only in Kotlin/Native with legacy memory manager.
annotation class SharedImmutable
Marks a top level property with a backing field or an object as thread local. The object remains mutable and it is possible to change its state, but every thread will have a distinct copy of this object, so changes in one thread are not reflected in another.
annotation class ThreadLocal
Checks if given object is null or frozen or permanent (i.e. instantiated at compile-time).
val Any?.isFrozen: Boolean
Atomic lazy initializer, could be used in frozen objects, freezes initializing lambda,
so use very carefully. Also, as with other uses of an AtomicReference may potentially
leak memory, so it is recommended to use
atomicLazy in cases of objects living forever,
such as object signletons, or in cases where it's guaranteed not to have cyclical garbage.
fun <T> atomicLazy(initializer: () -> T): Lazy<T>
Attaches previously detached object subgraph created by DetachedObjectGraph. Please note, that once object graph is attached, the DetachedObjectGraph.stable pointer does not make sense anymore, and shall be discarded, so attach of one DetachedObjectGraph object can only happen once.
fun <T> DetachedObjectGraph<T>.attach(): T
This function ensures that if we see such an object during freezing attempt - freeze fails and FreezingException is thrown.
Freezes object subgraph reachable from this object. Frozen objects can be freely shared between threads/workers.
fun <T> T.freeze(): T
Executes block with new Worker as resource, by starting the new worker, calling provided block (in current context) with newly started worker as this and terminating worker after the block completes. Note that this operation is pretty heavyweight, use preconfigured worker or worker pool if need to execute it frequently.
fun <R> withWorker(
name: String? = null,
errorReporting: Boolean = true,
block: Worker.() -> R