[FIR] KTIJ-24156: Add test data

This commit is contained in:
aleksandrina-streltsova
2023-01-09 13:26:13 +02:00
committed by Space Team
parent af414cfb5e
commit 3a6e3290aa
9 changed files with 65 additions and 2 deletions
@@ -13,8 +13,18 @@ internal class FirThreadSafeCache<K : Any, V, CONTEXT>(
private val createValue: (K, CONTEXT) -> V
) : FirCache<K, V, CONTEXT>() {
private val updating: ThreadLocal<Boolean> = ThreadLocal.withInitial { false }
override fun getValue(key: K, context: CONTEXT): V =
map.getOrPutWithNullableValue(key) { createValue(it, context) }
map.getOrPutWithNullableValue(key) {
if (updating.get()) error("Recursive update")
try {
updating.set(true)
createValue(it, context)
} finally {
updating.set(false)
}
}
override fun getValueIfComputed(key: K): V? =
map[key]?.nullValueToNull()