commonMain.ch.softappeal.yass2.remote.session.Sync.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of yass2-jvm Show documentation
Show all versions of yass2-jvm Show documentation
Yet Another Service Solution
package ch.softappeal.yass2.remote.session
import kotlinx.coroutines.sync.*
internal class AtomicBoolean(private var value: Boolean) {
private val mutex = Mutex()
suspend fun get(): Boolean = mutex.withLock { value }
suspend fun getAndSet(value: Boolean): Boolean = mutex.withLock {
val oldValue = this.value
this.value = value
oldValue
}
}
internal class AtomicInteger(private var value: Int) {
private val mutex = Mutex()
suspend fun incrementAndGet(): Int = mutex.withLock { ++value }
}
internal class ThreadSafeMap(initialCapacity: Int) {
private val mutex = Mutex()
private val map = HashMap(initialCapacity)
suspend fun put(key: K, value: V): Unit = mutex.withLock { map[key] = value }
suspend fun remove(key: K): V? = mutex.withLock { map.remove(key) }
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy