From e3b7f6d698161ea2f6bbdf6aeb21ea731eaa9606 Mon Sep 17 00:00:00 2001 From: "Pavel V. Talanov" Date: Thu, 24 Aug 2017 20:35:32 +0300 Subject: [PATCH] Prevent multiple concurrent 'checkHideNonConfiguredNotifications' calls --- .../ConfigureKotlinNotificationManager.kt | 22 +++++++++++++------ 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/idea/src/org/jetbrains/kotlin/idea/configuration/ConfigureKotlinNotificationManager.kt b/idea/src/org/jetbrains/kotlin/idea/configuration/ConfigureKotlinNotificationManager.kt index 7dbc33c404a..e0ad5899781 100644 --- a/idea/src/org/jetbrains/kotlin/idea/configuration/ConfigureKotlinNotificationManager.kt +++ b/idea/src/org/jetbrains/kotlin/idea/configuration/ConfigureKotlinNotificationManager.kt @@ -23,6 +23,7 @@ import com.intellij.openapi.module.Module import com.intellij.openapi.project.DumbService import com.intellij.openapi.project.Project import org.jetbrains.kotlin.idea.configuration.ui.notifications.ConfigureKotlinNotification +import java.util.concurrent.atomic.AtomicBoolean import kotlin.reflect.KClass object ConfigureKotlinNotificationManager: KotlinSingleNotificationManager { @@ -66,16 +67,23 @@ interface KotlinSingleNotificationManager { } } +private val checkInProgress = AtomicBoolean(false) fun checkHideNonConfiguredNotifications(project: Project) { - if (ConfigureKotlinNotificationManager.getVisibleNotifications(project).isNotEmpty()) { - ApplicationManager.getApplication().executeOnPooledThread { - DumbService.getInstance(project).waitForSmartMode() - if (getConfigurableModulesWithKotlinFiles(project).all(::isModuleConfigured)) { - ApplicationManager.getApplication().invokeLater { - ConfigureKotlinNotificationManager.expireOldNotifications(project) - } + if (checkInProgress.get() || ConfigureKotlinNotificationManager.getVisibleNotifications(project).isEmpty()) return + + ApplicationManager.getApplication().executeOnPooledThread { + if (!checkInProgress.compareAndSet(false, true)) return@executeOnPooledThread + + DumbService.getInstance(project).waitForSmartMode() + if (getConfigurableModulesWithKotlinFiles(project).all(::isModuleConfigured)) { + ApplicationManager.getApplication().invokeLater { + ConfigureKotlinNotificationManager.expireOldNotifications(project) + checkInProgress.set(false) } } + else { + checkInProgress.set(false) + } } }