Fix freeze during script definitions update (KT-32513)

loadScriptDefinitions is a long running operation, so it shouldn't be called under write lock.
This may cause a freeze when someone else wants to get definitions from the same loader during loading process

^KT-32513 Fixed
This commit is contained in:
Natalia Selezneva
2019-09-18 15:06:48 +03:00
parent 1b64583855
commit 3ac099fc9a
@@ -76,10 +76,15 @@ abstract class AsyncScriptDefinitionsContributor(protected val project: Project)
shouldStartNewUpdate = false
}
val wasRunning = definitionsLock.isWriteLocked
val previousDefinitions = definitionsLock.read {
if (!forceStartUpdate && _definitions != null) return
_definitions
}
val newDefinitions = loadScriptDefinitions(previousDefinitions)
val needReload = definitionsLock.write {
if (wasRunning && !forceStartUpdate && _definitions != null) return@write false
val newDefinitions = loadScriptDefinitions(_definitions)
if (newDefinitions != _definitions) {
_definitions = newDefinitions
return@write true