Do not hold a lock during loading script templates from dependencies
^KT-40383 Fixed
This commit is contained in:
+7
-18
@@ -22,6 +22,7 @@ import org.jetbrains.kotlin.scripting.definitions.SCRIPT_DEFINITION_MARKERS_EXTE
|
|||||||
import org.jetbrains.kotlin.scripting.definitions.ScriptDefinition
|
import org.jetbrains.kotlin.scripting.definitions.ScriptDefinition
|
||||||
import org.jetbrains.kotlin.scripting.definitions.getEnvironment
|
import org.jetbrains.kotlin.scripting.definitions.getEnvironment
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
import java.util.concurrent.atomic.AtomicBoolean
|
||||||
import java.util.concurrent.locks.ReentrantLock
|
import java.util.concurrent.locks.ReentrantLock
|
||||||
import kotlin.concurrent.withLock
|
import kotlin.concurrent.withLock
|
||||||
import kotlin.script.experimental.host.ScriptingHostConfiguration
|
import kotlin.script.experimental.host.ScriptingHostConfiguration
|
||||||
@@ -68,12 +69,8 @@ class ScriptTemplatesFromDependenciesProvider(private val project: Project) : Sc
|
|||||||
if (!forceStartUpdate && _definitions != null) return
|
if (!forceStartUpdate && _definitions != null) return
|
||||||
}
|
}
|
||||||
|
|
||||||
inProgressLock.withLock {
|
if (inProgress.compareAndSet(false, true)) {
|
||||||
if (!inProgress) {
|
loadScriptDefinitions()
|
||||||
inProgress = true
|
|
||||||
|
|
||||||
loadScriptDefinitions()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -88,8 +85,7 @@ class ScriptTemplatesFromDependenciesProvider(private val project: Project) : Sc
|
|||||||
val classpath: List<File>,
|
val classpath: List<File>,
|
||||||
)
|
)
|
||||||
|
|
||||||
private var inProgress = false
|
private val inProgress = AtomicBoolean(false)
|
||||||
private val inProgressLock = ReentrantLock()
|
|
||||||
|
|
||||||
@Volatile
|
@Volatile
|
||||||
private var forceStartUpdate = false
|
private var forceStartUpdate = false
|
||||||
@@ -121,10 +117,7 @@ class ScriptTemplatesFromDependenciesProvider(private val project: Project) : Sc
|
|||||||
|
|
||||||
val newTemplates = TemplatesWithCp(templates.toList(), classpath.toList())
|
val newTemplates = TemplatesWithCp(templates.toList(), classpath.toList())
|
||||||
if (newTemplates == oldTemplates) {
|
if (newTemplates == oldTemplates) {
|
||||||
inProgressLock.withLock {
|
inProgress.set(false)
|
||||||
inProgress = false
|
|
||||||
}
|
|
||||||
|
|
||||||
return@onSuccess
|
return@onSuccess
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -164,9 +157,7 @@ class ScriptTemplatesFromDependenciesProvider(private val project: Project) : Sc
|
|||||||
ScriptDefinitionsManager.getInstance(project).reloadDefinitionsBy(this@ScriptTemplatesFromDependenciesProvider)
|
ScriptDefinitionsManager.getInstance(project).reloadDefinitionsBy(this@ScriptTemplatesFromDependenciesProvider)
|
||||||
}
|
}
|
||||||
|
|
||||||
inProgressLock.withLock {
|
inProgress.set(false)
|
||||||
inProgress = false
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -174,9 +165,7 @@ class ScriptTemplatesFromDependenciesProvider(private val project: Project) : Sc
|
|||||||
definitionsLock.withLock {
|
definitionsLock.withLock {
|
||||||
_definitions = emptyList()
|
_definitions = emptyList()
|
||||||
}
|
}
|
||||||
inProgressLock.withLock {
|
inProgress.set(false)
|
||||||
inProgress = false
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// public for tests
|
// public for tests
|
||||||
|
|||||||
Reference in New Issue
Block a user