CacheUpdateRunner: processInReadAction is always true

This commit is contained in:
peter
2017-09-15 15:33:10 +02:00
parent 5f86598a69
commit 0a4527f77d
4 changed files with 10 additions and 22 deletions
@@ -158,6 +158,6 @@ public class FileBasedIndexProjectHandler implements IndexableFileSet, Disposabl
Collection<VirtualFile> 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));
}
}
@@ -106,7 +106,7 @@ public class UnindexedFilesUpdater extends DumbModeTask {
}
private void indexFiles(ProgressIndicator indicator, List<VirtualFile> files) {
CacheUpdateRunner.processFiles(indicator, true, files, myProject, content -> myIndex.indexFileContent(myProject, content));
CacheUpdateRunner.processFiles(indicator, files, myProject, content -> myIndex.indexFileContent(myProject, content));
}
@Override
@@ -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<VirtualFile> files,
Project project, Consumer<FileContent> processor) {
public static void processFiles(ProgressIndicator indicator, Collection<VirtualFile> files, Project project, Consumer<FileContent> 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<FileContent> 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<FileContent> myProcessor;
@@ -194,14 +189,12 @@ public class CacheUpdateRunner {
@NotNull FileContentQueue queue,
@NotNull AtomicBoolean finished,
@NotNull ProgressUpdater progressUpdater,
boolean processInReadAction,
@NotNull Project project,
@NotNull Consumer<FileContent> 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)
@@ -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<Boolean> future : futures) {