FIR IDE: fix deadlock in symbol providers

This commit is contained in:
Ilya Kirillov
2021-04-04 17:38:26 +02:00
parent 266daed2cb
commit 790cafa671
3 changed files with 4 additions and 4 deletions
@@ -14,7 +14,7 @@ internal class FirThreadSafeCache<K : Any, V, CONTEXT>(
private val map = ConcurrentHashMap<K, Any>()
override fun getValue(key: K, context: CONTEXT): V =
map.computeIfAbsentWithNullableValue(key) { createValue(it, context) }
map.getOrPutWithNullableValue(key) { createValue(it, context) }
override fun getValueIfComputed(key: K): V? =
map[key]?.nullValueToNull()
@@ -16,7 +16,7 @@ internal class FirThreadSafeCacheWithPostCompute<K : Any, V, CONTEXT, DATA>(
@Suppress("UNCHECKED_CAST")
override fun getValue(key: K, context: CONTEXT): V =
map.computeIfAbsent(key) {
map.getOrPut(key) {
ValueWithPostCompute(
key,
calculate = { createValue(it, context) },
@@ -15,10 +15,10 @@ internal inline fun <VALUE> Any.nullValueToNull(): VALUE = when (this) {
else -> this
} as VALUE
internal inline fun <KEY : Any, RESULT> ConcurrentMap<KEY, Any>.computeIfAbsentWithNullableValue(
internal inline fun <KEY : Any, RESULT> ConcurrentMap<KEY, Any>.getOrPutWithNullableValue(
key: KEY,
crossinline compute: (KEY) -> Any?
): RESULT {
val value = computeIfAbsent(key) { k -> compute(k) ?: NullValue }
val value = getOrPut(key) { compute(key) ?: NullValue }
return value.nullValueToNull()
}