From aa7ed7ba1902a3f33a92f42d627c8a8dad591474 Mon Sep 17 00:00:00 2001 From: Markus Schorn Date: Mon, 25 Feb 2008 10:03:31 +0000 Subject: [PATCH] IIndexManager manager operations can block too long, bug 220149. --- .../core/pdom/indexer/PDOMRebuildTask.java | 18 +++++++----- .../core/pdom/indexer/PDOMUpdateTask.java | 29 +++++++++---------- .../indexer/TranslationUnitCollector.java | 9 +++--- 3 files changed, 28 insertions(+), 28 deletions(-) diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/PDOMRebuildTask.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/PDOMRebuildTask.java index 23486bfcd7e..76d8878a386 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/PDOMRebuildTask.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/PDOMRebuildTask.java @@ -8,7 +8,6 @@ * Contributors: * Markus Schorn - initial API and implementation *******************************************************************************/ - package org.eclipse.cdt.internal.core.pdom.indexer; import java.util.ArrayList; @@ -101,19 +100,22 @@ public class PDOMRebuildTask implements IPDOMIndexerTask { } } - private synchronized void createDelegate(ICProject project, IProgressMonitor monitor) throws CoreException { + private void createDelegate(ICProject project, IProgressMonitor monitor) throws CoreException { boolean allFiles= TRUE.equals(fIndexer.getProperty(IndexerPreferences.KEY_INDEX_ALL_FILES)); List sources= new ArrayList(); List headers= allFiles ? sources : null; TranslationUnitCollector collector= new TranslationUnitCollector(sources, headers, monitor); project.accept(collector); ITranslationUnit[] tus= sources.toArray(new ITranslationUnit[sources.size()]); - fDelegate= fIndexer.createTask(tus, NO_TUS, NO_TUS); - if (fDelegate instanceof PDOMIndexerTask) { - final PDOMIndexerTask delegate = (PDOMIndexerTask) fDelegate; - delegate.setUpdateFlags(IIndexManager.UPDATE_ALL); - delegate.setParseUpFront(); - delegate.setWriteInfoToLog(); + IPDOMIndexerTask delegate= fIndexer.createTask(tus, NO_TUS, NO_TUS); + if (delegate instanceof PDOMIndexerTask) { + final PDOMIndexerTask pdomIndexerTask = (PDOMIndexerTask) delegate; + pdomIndexerTask.setUpdateFlags(IIndexManager.UPDATE_ALL); + pdomIndexerTask.setParseUpFront(); + pdomIndexerTask.setWriteInfoToLog(); + } + synchronized (this) { + fDelegate= delegate; } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/PDOMUpdateTask.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/PDOMUpdateTask.java index 8a51c72227e..1b471becb53 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/PDOMUpdateTask.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/PDOMUpdateTask.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007 Wind River Systems, Inc. and others. + * Copyright (c) 2007, 2008 Wind River Systems, Inc. and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -8,12 +8,10 @@ * Contributors: * Markus Schorn - initial API and implementation *******************************************************************************/ - package org.eclipse.cdt.internal.core.pdom.indexer; import java.util.ArrayList; import java.util.HashSet; -import java.util.Iterator; import java.util.List; import org.eclipse.cdt.core.CCorePlugin; @@ -39,7 +37,7 @@ public class PDOMUpdateTask implements IPDOMIndexerTask { private final IndexerProgress fProgress; private final int fUpdateOptions; private volatile IPDOMIndexerTask fDelegate; - private ArrayList fFilesAndFolders= null; + private ArrayList fFilesAndFolders= null; public PDOMUpdateTask(IPDOMIndexer indexer, int updateOptions) { fIndexer= indexer; @@ -77,33 +75,34 @@ public class PDOMUpdateTask implements IPDOMIndexerTask { } } - private synchronized void createDelegate(ICProject project, IProgressMonitor monitor) throws CoreException { - HashSet set= new HashSet(); + private void createDelegate(ICProject project, IProgressMonitor monitor) throws CoreException { + HashSet set= new HashSet(); TranslationUnitCollector collector= new TranslationUnitCollector(set, set, monitor); if (fFilesAndFolders == null) { project.accept(collector); } else { - for (Iterator iterator = fFilesAndFolders.iterator(); iterator.hasNext();) { - ICElement elem = (ICElement) iterator.next(); + for (ICElement elem : fFilesAndFolders) { elem.accept(collector); } } - ITranslationUnit[] tus= (ITranslationUnit[]) set.toArray(new ITranslationUnit[set.size()]); - fDelegate= fIndexer.createTask(tus, NO_TUS, NO_TUS); - if (fDelegate instanceof PDOMIndexerTask) { - final PDOMIndexerTask task = (PDOMIndexerTask) fDelegate; + ITranslationUnit[] tus= set.toArray(new ITranslationUnit[set.size()]); + IPDOMIndexerTask delegate= fIndexer.createTask(tus, NO_TUS, NO_TUS); + if (delegate instanceof PDOMIndexerTask) { + final PDOMIndexerTask task = (PDOMIndexerTask) delegate; task.setUpdateFlags(fUpdateOptions); } + synchronized (this) { + fDelegate= delegate; + } } - public synchronized IndexerProgress getProgressInformation() { return fDelegate != null ? fDelegate.getProgressInformation() : fProgress; } - public void setTranslationUnitSelection(List filesAndFolders) { - fFilesAndFolders= new ArrayList(filesAndFolders.size()); + public void setTranslationUnitSelection(List filesAndFolders) { + fFilesAndFolders= new ArrayList(filesAndFolders.size()); fFilesAndFolders.addAll(filesAndFolders); } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/TranslationUnitCollector.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/TranslationUnitCollector.java index 6fc2f314206..5def46b68ee 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/TranslationUnitCollector.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/TranslationUnitCollector.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007 Wind River Systems, Inc. and others. + * Copyright (c) 2007, 2008 Wind River Systems, Inc. and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -8,7 +8,6 @@ * Contributors: * Markus Schorn - initial API and implementation *******************************************************************************/ - package org.eclipse.cdt.internal.core.pdom.indexer; import java.util.Collection; @@ -20,11 +19,11 @@ import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IProgressMonitor; final class TranslationUnitCollector implements ICElementVisitor { - private final Collection fSources; - private final Collection fHeaders; + private final Collection fSources; + private final Collection fHeaders; private final IProgressMonitor fProgressMonitor; - public TranslationUnitCollector(Collection sources, Collection headers, IProgressMonitor pm) { + public TranslationUnitCollector(Collection sources, Collection headers, IProgressMonitor pm) { fSources= sources; fHeaders= headers; fProgressMonitor= pm;