[LL FIR] allow recursive access to the same FirThreadSafeCache
^KT-56721 fixed
This commit is contained in:
committed by
Space Team
parent
d670e5a695
commit
c60fd38e05
+1
-9
@@ -13,17 +13,9 @@ 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) {
|
||||
if (updating.get()) error("Recursive update")
|
||||
try {
|
||||
updating.set(true)
|
||||
createValue(it, context)
|
||||
} finally {
|
||||
updating.set(false)
|
||||
}
|
||||
createValue(it, context)
|
||||
}
|
||||
|
||||
override fun getValueIfComputed(key: K): V? =
|
||||
|
||||
+1
-1
@@ -19,6 +19,6 @@ internal inline fun <KEY : Any, RESULT> ConcurrentMap<KEY, Any>.getOrPutWithNull
|
||||
key: KEY,
|
||||
crossinline compute: (KEY) -> Any?
|
||||
): RESULT {
|
||||
val value = computeIfAbsent(key) { compute(key) ?: NullValue }
|
||||
val value = getOrPut(key) { compute(key) ?: NullValue }
|
||||
return value.nullValueToNull()
|
||||
}
|
||||
Reference in New Issue
Block a user