mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-03-22 15:19:59 +07:00
[json] IJ-CR-124164 Support concurrent properties map modification via employing atomic reference paired with a persistent map
GitOrigin-RevId: 6129515c562ae2fd1f9df79d6919f3baa93d4d5e
This commit is contained in:
committed by
intellij-monorepo-bot
parent
69e995a22a
commit
90f7a06e75
@@ -14,6 +14,7 @@ import com.jetbrains.jsonSchema.impl.light.legacy.JsonSchemaObjectReadingUtils
|
||||
import com.jetbrains.jsonSchema.impl.light.legacy.isOldParserAwareOfFieldName
|
||||
import com.jetbrains.jsonSchema.impl.light.legacy.tryReadEnumMetadata
|
||||
import java.util.*
|
||||
import java.util.concurrent.atomic.AtomicReference
|
||||
|
||||
private val ONE_OF_KEY = Key<List<JsonSchemaObject>>("oneOf")
|
||||
private val ANY_OF_KEY = Key<List<JsonSchemaObject>>("anyOf")
|
||||
@@ -31,13 +32,24 @@ internal abstract class JsonSchemaObjectBackedByJacksonBase(
|
||||
|
||||
abstract fun getRootSchemaObject(): RootJsonSchemaObjectBackedByJackson
|
||||
|
||||
private var myCompositeObjectsCache = KeyFMap.EMPTY_MAP
|
||||
private var myCompositeObjectsCache = AtomicReference(KeyFMap.EMPTY_MAP)
|
||||
|
||||
protected fun <V : Any> getOrComputeValue(key: Key<V>, computation: () -> V): V {
|
||||
val existingValue = myCompositeObjectsCache.get(key)
|
||||
if (existingValue != null) return existingValue
|
||||
val newValue = computation()
|
||||
myCompositeObjectsCache = myCompositeObjectsCache.plus(key, newValue)
|
||||
var existingMap: KeyFMap
|
||||
var newValue: V?
|
||||
|
||||
do {
|
||||
existingMap = myCompositeObjectsCache.get()
|
||||
newValue = existingMap[key]
|
||||
if (newValue == null) {
|
||||
val mapWithNewValue = existingMap.plus(key, computation())
|
||||
if (myCompositeObjectsCache.compareAndSet(existingMap, mapWithNewValue)) {
|
||||
newValue = mapWithNewValue.get(key)
|
||||
}
|
||||
}
|
||||
}
|
||||
while (newValue == null)
|
||||
|
||||
return newValue
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user