[threading] IJPL-190260: Remove blockingContext #6

GitOrigin-RevId: e1569f3038c1d1e6fa43c2254267e8819ac84268
This commit is contained in:
Konstantin Nisht
2025-06-04 10:18:26 +02:00
committed by intellij-monorepo-bot
parent 2d5aaf391b
commit 3ae5076fd0
11 changed files with 54 additions and 84 deletions

View File

@@ -10,7 +10,6 @@ import com.intellij.openapi.compiler.CompilerManager
import com.intellij.openapi.diagnostic.thisLogger
import com.intellij.openapi.extensions.ExtensionNotApplicableException
import com.intellij.openapi.progress.ProgressManager
import com.intellij.openapi.progress.blockingContext
import com.intellij.openapi.progress.coroutineToIndicator
import com.intellij.openapi.project.Project
import com.intellij.openapi.startup.ProjectActivity
@@ -31,9 +30,7 @@ internal class IsUpToDateCheckStartupActivity : ProjectActivity {
override suspend fun execute(project: Project) {
val logger = thisLogger()
val isUpToDateConsumers = blockingContext {
IsUpToDateCheckConsumer.EP_NAME.extensionList.filter { it.isApplicable(project) }
}
val isUpToDateConsumers = IsUpToDateCheckConsumer.EP_NAME.extensionList.filter { it.isApplicable(project) }
if (isUpToDateConsumers.isEmpty()) {
logger.info("suitable consumer is not found")
return

View File

@@ -3,7 +3,6 @@ package com.intellij.util.indexing.internal
import com.intellij.openapi.components.Service
import com.intellij.openapi.progress.ProgressManager
import com.intellij.openapi.progress.blockingContext
import com.intellij.openapi.project.Project
import com.intellij.openapi.project.UnindexedFilesScannerExecutor
import com.intellij.platform.ide.progress.withBackgroundProgress
@@ -40,12 +39,10 @@ internal class InternalIndexingActionsService(private val project: Project, priv
val activityName = "From InternalIndexingActionsService"
withBackgroundProgress(project, activityName) {
blockingContext {
UnindexedFilesScannerExecutor.getInstance(project).suspendScanningAndIndexingThenRun(activityName) {
while (true) {
ProgressManager.checkCanceled()
Thread.sleep(100)
}
UnindexedFilesScannerExecutor.getInstance(project).suspendScanningAndIndexingThenRun(activityName) {
while (true) {
ProgressManager.checkCanceled()
Thread.sleep(100)
}
}
}

View File

@@ -9,7 +9,6 @@ import com.intellij.openapi.application.EDT
import com.intellij.openapi.application.ModalityState
import com.intellij.openapi.application.asContextElement
import com.intellij.openapi.components.ComponentManagerEx
import com.intellij.openapi.progress.blockingContext
import com.intellij.openapi.util.Disposer
import com.intellij.ui.JBColor
import com.intellij.ui.components.JBLayeredPane
@@ -149,9 +148,7 @@ open class LoadingDecorator @JvmOverloads constructor(
startRequestJob = (ApplicationManager.getApplication() as ComponentManagerEx).getCoroutineScope().launch {
delay((startDelayMs - (System.currentTimeMillis() - scheduledTime)).coerceAtLeast(0))
withContext(Dispatchers.EDT + ModalityState.any().asContextElement()) {
blockingContext {
doStartLoading(takeSnapshot)
}
doStartLoading(takeSnapshot)
}
}
}

View File

@@ -9,7 +9,6 @@ import com.intellij.openapi.application.ReadConstraint
import com.intellij.openapi.application.ex.ApplicationEx
import com.intellij.openapi.application.impl.getGlobalThreadingSupport
import com.intellij.openapi.application.isLockStoredInContext
import com.intellij.openapi.progress.blockingContext
import kotlinx.coroutines.*
import kotlin.coroutines.coroutineContext
import kotlin.coroutines.resume
@@ -31,10 +30,7 @@ internal class InternalReadAction<T>(
check(unsatisfiedConstraint == null) {
"Cannot suspend until constraints are satisfied while holding the read lock: $unsatisfiedConstraint"
}
return blockingContext {
// To copy permit from context to thread local
ReadAction.compute<T, Throwable>(action)
}
return ReadAction.compute<T, Throwable>(action)
}
coroutineScope {
readLoop()
@@ -93,13 +89,11 @@ internal class InternalReadAction<T>(
}
private suspend fun tryReadBlocking(): ReadResult<T> {
return blockingContext {
var result: ReadResult<T>? = null
application.tryRunReadAction {
result = insideReadAction()
}
result ?: ReadResult.WritePending
var result: ReadResult<T>? = null
application.tryRunReadAction {
result = insideReadAction()
}
return result ?: ReadResult.WritePending
}
private suspend fun tryReadCancellable(): ReadResult<T> = try {

View File

@@ -4,7 +4,6 @@ package com.intellij.openapi.project
import com.intellij.openapi.components.Service
import com.intellij.openapi.diagnostic.debug
import com.intellij.openapi.diagnostic.logger
import com.intellij.openapi.progress.blockingContext
import com.intellij.openapi.roots.ex.ProjectRootManagerEx
import com.intellij.openapi.vfs.newvfs.RefreshQueue
import com.intellij.openapi.vfs.newvfs.monitoring.VfsUsageCollector
@@ -47,9 +46,7 @@ class InitialVfsRefreshService(private val project: Project, private val corouti
coroutineScope.awaitCancellationAndInvoke { session.cancel() }
session.addAllFiles(roots)
val t = System.nanoTime()
blockingContext {
session.launch()
}
session.launch()
val duration = TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - t)
logger.info("${projectId}: initial VFS refresh finished in ${duration} ms")
VfsUsageCollector.logInitialRefresh(project, duration)

View File

@@ -8,7 +8,6 @@ import com.intellij.openapi.application.ex.PathManagerEx
import com.intellij.openapi.module.ConfigurationErrorDescription
import com.intellij.openapi.module.ModuleManager
import com.intellij.openapi.module.impl.ProjectLoadingErrorsHeadlessNotifier
import com.intellij.openapi.progress.blockingContext
import com.intellij.openapi.project.Project
import com.intellij.openapi.roots.libraries.LibraryTablesRegistrar
import com.intellij.openapi.util.io.FileUtil
@@ -160,9 +159,7 @@ class LoadInvalidProjectTest {
}
private suspend fun checkUntrustedModuleIsNotLoaded(project: Project, moduleName: String) {
val moduleEntities = blockingContext {
WorkspaceModel.getInstance(project).currentSnapshot.entities(ModuleEntity::class.java)
}
val moduleEntities = WorkspaceModel.getInstance(project).currentSnapshot.entities(ModuleEntity::class.java)
assertThat(moduleEntities.find { module -> module.name == moduleName }).isNull()
}

View File

@@ -2,7 +2,6 @@
package git4idea.instant
import com.intellij.openapi.extensions.ExtensionPointName
import com.intellij.openapi.progress.blockingContext
import org.jetbrains.annotations.ApiStatus.Experimental
import org.jetbrains.annotations.ApiStatus.Internal
@@ -27,6 +26,6 @@ interface InstantGitTokenProvider {
}
suspend fun getAuthHeaders(): Map<String, String>? {
return (getAuthToken() ?: blockingContext { getToken() })?.let { mapOf("Authorization" to "Bearer $it") }
return (getAuthToken() ?: getToken())?.let { mapOf("Authorization" to "Bearer $it") }
}
}

View File

@@ -7,7 +7,6 @@ import com.intellij.notification.NotificationType
import com.intellij.openapi.Disposable
import com.intellij.openapi.components.Service
import com.intellij.openapi.components.service
import com.intellij.openapi.progress.blockingContext
import com.intellij.openapi.project.Project
import com.intellij.openapi.project.guessProjectDir
import com.intellij.openapi.startup.ProjectActivity
@@ -27,9 +26,9 @@ import org.jetbrains.kotlin.konan.library.KONAN_STDLIB_NAME
/** TODO: merge [KotlinNativeABICompatibilityChecker] in the future with [UnsupportedAbiVersionNotificationPanelProvider], KT-34525 */
@K1ModeProjectStructureApi
internal class KotlinNativeABICompatibilityChecker : ProjectActivity {
override suspend fun execute(project: Project) : Unit = blockingContext {
KotlinNativeABICompatibilityCheckerService.getInstance(project).runActivity()
}
override suspend fun execute(project: Project) {
KotlinNativeABICompatibilityCheckerService.getInstance(project).runActivity()
}
}
@Service(Service.Level.PROJECT)

View File

@@ -1,7 +1,6 @@
// Copyright 2000-2025 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package org.jetbrains.kotlin.gradle.scripting.k1
import com.intellij.openapi.progress.blockingContext
import com.intellij.platform.workspace.storage.MutableEntityStorage
import org.gradle.tooling.model.kotlin.dsl.KotlinDslScriptsModel
import org.jetbrains.kotlin.gradle.scripting.shared.importing.kotlinDslSyncListenerInstance
@@ -20,24 +19,22 @@ class KotlinDslScriptSyncContributor : GradleSyncContributor {
val tasks = kotlinDslSyncListenerInstance?.tasks ?: return
val sync = synchronized(tasks) { tasks[taskId] }
blockingContext {
for (buildModel in context.allBuilds) {
for (projectModel in buildModel.projects) {
val projectIdentifier = projectModel.projectIdentifier.projectPath
if (projectIdentifier == ":") {
if (kotlinDslScriptsModelImportSupported(context.projectGradleVersion)) {
val model = context.getProjectModel(projectModel, KotlinDslScriptsModel::class.java)
if (model != null) {
if (!processScriptModel(context, sync, model, projectIdentifier)) {
continue
}
}
for (buildModel in context.allBuilds) {
for (projectModel in buildModel.projects) {
val projectIdentifier = projectModel.projectIdentifier.projectPath
if (projectIdentifier == ":") {
if (kotlinDslScriptsModelImportSupported(context.projectGradleVersion)) {
val model = context.getProjectModel(projectModel, KotlinDslScriptsModel::class.java)
if (model != null) {
if (!processScriptModel(context, sync, model, projectIdentifier)) {
continue
}
saveGradleBuildEnvironment(context)
}
}
saveGradleBuildEnvironment(context)
}
}
}
}
}

View File

@@ -2,7 +2,6 @@
package org.jetbrains.kotlin.gradle.scripting.k2.importing
import com.intellij.openapi.application.readAction
import com.intellij.openapi.progress.blockingContext
import com.intellij.openapi.vfs.VirtualFileManager
import com.intellij.platform.workspace.storage.MutableEntityStorage
import com.intellij.psi.PsiManager
@@ -32,27 +31,25 @@ class KotlinDslScriptSyncContributor : GradleSyncContributor {
val tasks = kotlinDslSyncListenerInstance?.tasks ?: return
val sync = synchronized(tasks) { tasks[taskId] }
blockingContext {
for (buildModel in context.allBuilds) {
for (projectModel in buildModel.projects) {
val projectIdentifier = projectModel.projectIdentifier.projectPath
if (projectIdentifier == ":") {
if (kotlinDslScriptsModelImportSupported(context.projectGradleVersion)) {
val model = context.getProjectModel(projectModel, KotlinDslScriptsModel::class.java)
if (model != null) {
if (!processScriptModel(context, sync, model, projectIdentifier)) {
continue
}
}
}
saveGradleBuildEnvironment(context)
}
for (buildModel in context.allBuilds) {
for (projectModel in buildModel.projects) {
val projectIdentifier = projectModel.projectIdentifier.projectPath
if (projectIdentifier == ":") {
if (kotlinDslScriptsModelImportSupported(context.projectGradleVersion)) {
val model = context.getProjectModel(projectModel, KotlinDslScriptsModel::class.java)
if (model != null) {
if (!processScriptModel(context, sync, model, projectIdentifier)) {
continue
}
}
}
}
if (sync == null || sync.models.isEmpty()) return
saveGradleBuildEnvironment(context)
}
}
}
if (sync == null || sync.models.isEmpty()) return
GradleScriptDefinitionsStorage.getInstance(project).loadDefinitionsFromDisk(
sync.workingDir,

View File

@@ -3,7 +3,6 @@ package org.jetbrains.kotlin.idea.macros
import com.intellij.ide.util.PropertiesComponent
import com.intellij.openapi.extensions.ExtensionNotApplicableException
import com.intellij.openapi.progress.blockingContext
import com.intellij.openapi.project.Project
import com.intellij.openapi.startup.ProjectActivity
import com.intellij.openapi.vfs.JarFileSystem
@@ -30,17 +29,17 @@ internal class KotlinBundledRefresher : ProjectActivity {
}
}
override suspend fun execute(project: Project): Unit = blockingContext {
val propertiesComponent = PropertiesComponent.getInstance()
val installedKotlinVersion = propertiesComponent.getValue(INSTALLED_KOTLIN_VERSION)
override suspend fun execute(project: Project): Unit { // Force refresh jar handlers
val propertiesComponent = PropertiesComponent.getInstance()
val installedKotlinVersion = propertiesComponent.getValue(INSTALLED_KOTLIN_VERSION)
if (KotlinIdePlugin.version != installedKotlinVersion) {
// Force refresh jar handlers
requestKotlinDistRefresh(KotlinPluginLayout.kotlinc.toPath())
if (KotlinIdePlugin.version != installedKotlinVersion) {
// Force refresh jar handlers
requestKotlinDistRefresh(KotlinPluginLayout.kotlinc.toPath())
propertiesComponent.setValue(INSTALLED_KOTLIN_VERSION, KotlinIdePlugin.version)
}
}
propertiesComponent.setValue(INSTALLED_KOTLIN_VERSION, KotlinIdePlugin.version)
}
}
companion object {
private const val INSTALLED_KOTLIN_VERSION = "installed.kotlin.plugin.version"