All Downloads are FREE. Search and download functionalities are using the official Maven repository.

nativeCommonMain.co.touchlab.stately.concurrency.ThreadRef.kt Maven / Gradle / Ivy

There is a newer version: 2.1.0
Show newest version
package co.touchlab.stately.concurrency

import kotlin.native.concurrent.AtomicInt

@ThreadLocal
private var localThreadId: Int = 0

@SharedImmutable
private val threadIdCounter = AtomicInt(1)

private fun currentThreadId(): Int {
    if (localThreadId == 0) {
        localThreadId = threadIdCounter.addAndGet(1)
    }
    return localThreadId
}

actual class ThreadRef actual constructor() {
    private val threadId: Int = currentThreadId()

    actual fun same(): Boolean = threadId == currentThreadId()
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy