From 0a4527f77d9634ba2981318c4f3ef8b68ba64fdb Mon Sep 17 00:00:00 2001 From: peter Date: Fri, 15 Sep 2017 13:46:42 +0200 Subject: [PATCH] CacheUpdateRunner: processInReadAction is always true --- .../FileBasedIndexProjectHandler.java | 2 +- .../util/indexing/UnindexedFilesUpdater.java | 2 +- .../openapi/project/CacheUpdateRunner.java | 26 +++++-------------- .../util/io/PersistenceStressTest.java | 2 +- 4 files changed, 10 insertions(+), 22 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/util/indexing/FileBasedIndexProjectHandler.java b/platform/lang-impl/src/com/intellij/util/indexing/FileBasedIndexProjectHandler.java index eb0834ae735d..4462a4c98d5c 100644 --- a/platform/lang-impl/src/com/intellij/util/indexing/FileBasedIndexProjectHandler.java +++ b/platform/lang-impl/src/com/intellij/util/indexing/FileBasedIndexProjectHandler.java @@ -158,6 +158,6 @@ public class FileBasedIndexProjectHandler implements IndexableFileSet, Disposabl Collection files, final Project project, final FileBasedIndexImpl index) { - CacheUpdateRunner.processFiles(indicator, true, files, project, content -> index.processRefreshedFile(project, content)); + CacheUpdateRunner.processFiles(indicator, files, project, content -> index.processRefreshedFile(project, content)); } } diff --git a/platform/lang-impl/src/com/intellij/util/indexing/UnindexedFilesUpdater.java b/platform/lang-impl/src/com/intellij/util/indexing/UnindexedFilesUpdater.java index 7ce9f1e38c94..7ee3a2d38a76 100644 --- a/platform/lang-impl/src/com/intellij/util/indexing/UnindexedFilesUpdater.java +++ b/platform/lang-impl/src/com/intellij/util/indexing/UnindexedFilesUpdater.java @@ -106,7 +106,7 @@ public class UnindexedFilesUpdater extends DumbModeTask { } private void indexFiles(ProgressIndicator indicator, List files) { - CacheUpdateRunner.processFiles(indicator, true, files, myProject, content -> myIndex.indexFileContent(myProject, content)); + CacheUpdateRunner.processFiles(indicator, files, myProject, content -> myIndex.indexFileContent(myProject, content)); } @Override diff --git a/platform/platform-impl/src/com/intellij/openapi/project/CacheUpdateRunner.java b/platform/platform-impl/src/com/intellij/openapi/project/CacheUpdateRunner.java index 3343c9cd206a..e477d6a41819 100644 --- a/platform/platform-impl/src/com/intellij/openapi/project/CacheUpdateRunner.java +++ b/platform/platform-impl/src/com/intellij/openapi/project/CacheUpdateRunner.java @@ -46,10 +46,7 @@ public class CacheUpdateRunner { private static final int PROC_COUNT = Runtime.getRuntime().availableProcessors(); public static final int DEFAULT_MAX_INDEXER_THREADS = 4; - public static void processFiles(final ProgressIndicator indicator, - boolean processInReadAction, - Collection files, - Project project, Consumer processor) { + public static void processFiles(ProgressIndicator indicator, Collection files, Project project, Consumer processor) { indicator.checkCanceled(); final FileContentQueue queue = new FileContentQueue(files, indicator); final double total = files.size(); @@ -86,7 +83,7 @@ public class CacheUpdateRunner { while (!project.isDisposed()) { indicator.checkCanceled(); // todo wait for the user... - if (processSomeFilesWhileUserIsInactive(queue, progressUpdater, processInReadAction, project, processor)) { + if (processSomeFilesWhileUserIsInactive(queue, progressUpdater, project, processor)) { break; } } @@ -104,7 +101,6 @@ public class CacheUpdateRunner { private static boolean processSomeFilesWhileUserIsInactive(@NotNull FileContentQueue queue, @NotNull ProgressUpdater progressUpdater, - final boolean processInReadAction, @NotNull Project project, @NotNull Consumer fileProcessor) { final ProgressIndicatorBase innerIndicator = new ProgressIndicatorBase() { @@ -126,7 +122,7 @@ public class CacheUpdateRunner { try { int threadsCount = indexingThreadCount(); if (threadsCount == 1 || application.isWriteAccessAllowed()) { - Runnable process = new MyRunnable(innerIndicator, queue, isFinished, progressUpdater, processInReadAction, project, fileProcessor); + Runnable process = new MyRunnable(innerIndicator, queue, isFinished, progressUpdater, project, fileProcessor); ProgressManager.getInstance().runProcess(process, innerIndicator); } else { @@ -135,7 +131,7 @@ public class CacheUpdateRunner { for (int i = 0; i < threadsCount; i++) { AtomicBoolean ref = new AtomicBoolean(); finishedRefs[i] = ref; - Runnable process = new MyRunnable(innerIndicator, queue, ref, progressUpdater, processInReadAction, project, fileProcessor); + Runnable process = new MyRunnable(innerIndicator, queue, ref, progressUpdater, project, fileProcessor); futures[i] = application.executeOnPooledThread(process); } isFinished.set(waitForAll(finishedRefs, futures)); @@ -186,7 +182,6 @@ public class CacheUpdateRunner { private final FileContentQueue myQueue; private final AtomicBoolean myFinished; private final ProgressUpdater myProgressUpdater; - private final boolean myProcessInReadAction; @NotNull private final Project myProject; @NotNull private final Consumer myProcessor; @@ -194,14 +189,12 @@ public class CacheUpdateRunner { @NotNull FileContentQueue queue, @NotNull AtomicBoolean finished, @NotNull ProgressUpdater progressUpdater, - boolean processInReadAction, @NotNull Project project, @NotNull Consumer fileProcessor) { myInnerIndicator = innerIndicator; myQueue = queue; myFinished = finished; myProgressUpdater = progressUpdater; - myProcessInReadAction = processInReadAction; myProject = project; myProcessor = fileProcessor; } @@ -241,14 +234,9 @@ public class CacheUpdateRunner { try { ProgressManager.getInstance().runProcess( () -> { - if (myProcessInReadAction) { - // in wait methods we don't want to deadlock by grabbing write lock (or having it in queue) and trying to run read action in separate thread - if (!ApplicationManagerEx.getApplicationEx().tryRunReadAction(action)) { - throw new ProcessCanceledException(); - } - } - else { - action.run(); + // in wait methods we don't want to deadlock by grabbing write lock (or having it in queue) and trying to run read action in separate thread + if (!ApplicationManagerEx.getApplicationEx().tryRunReadAction(action)) { + throw new ProcessCanceledException(); } }, ProgressWrapper.wrap(myInnerIndicator) diff --git a/platform/platform-tests/testSrc/com/intellij/util/io/PersistenceStressTest.java b/platform/platform-tests/testSrc/com/intellij/util/io/PersistenceStressTest.java index a832a1b441b7..79dede3d063c 100644 --- a/platform/platform-tests/testSrc/com/intellij/util/io/PersistenceStressTest.java +++ b/platform/platform-tests/testSrc/com/intellij/util/io/PersistenceStressTest.java @@ -121,7 +121,7 @@ public class PersistenceStressTest extends LightPlatformCodeInsightFixtureTestCa FileBasedIndexImpl index = (FileBasedIndexImpl)FileBasedIndex.getInstance(); while (ContainerUtil.find(futures, STILL_RUNNING) != null) { Thread.sleep(100); - CacheUpdateRunner.processFiles(new EmptyProgressIndicator(), true, files, getProject(), + CacheUpdateRunner.processFiles(new EmptyProgressIndicator(), files, getProject(), content -> index.indexFileContent(getProject(), content)); } for (Future future : futures) {