darwinMain.com.adeo.kviewmodel.odyssey.ConcurrentHashMap.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of kviewmodel-odyssey Show documentation
Show all versions of kviewmodel-odyssey Show documentation
ViewModel for Multiplatform
package com.adeo.kviewmodel.odyssey
import kotlinx.atomicfu.locks.SynchronizedObject
import kotlinx.atomicfu.locks.synchronized
actual class ConcurrentHashMap(
private val delegate: HashMap = HashMap()
) : MutableMap by delegate {
actual constructor() : this(HashMap())
private val sync = SynchronizedObject()
override val size: Int
get() = synchronized(sync) { delegate.size }
override fun get(key: K): V? = synchronized(sync) { delegate.get(key) }
override fun put(key: K, value: V): V? = synchronized(sync) { delegate.put(key, value) }
override fun remove(key: K): V? = synchronized(sync) { delegate.remove(key) }
}