mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Fixes a potential CCE in the PDOMManager.
This commit is contained in:
parent
7cbba4df75
commit
c0244a5073
4 changed files with 39 additions and 20 deletions
|
@ -1,5 +1,5 @@
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* Copyright (c) 2006 Wind River Systems, Inc. and others.
|
* Copyright (c) 2006, 2007 Wind River Systems, Inc. and others.
|
||||||
* All rights reserved. This program and the accompanying materials
|
* All rights reserved. This program and the accompanying materials
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
* which accompanies this distribution, and is available at
|
* which accompanies this distribution, and is available at
|
||||||
|
@ -17,6 +17,9 @@ import org.eclipse.core.runtime.CoreException;
|
||||||
|
|
||||||
public interface IWritableIndexManager extends IIndexManager {
|
public interface IWritableIndexManager extends IIndexManager {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a writable index or <code>null</code> if the project does not exist or is not yet
|
||||||
|
* registered with the pdom manager.
|
||||||
|
*/
|
||||||
IWritableIndex getWritableIndex(ICProject project) throws CoreException;
|
IWritableIndex getWritableIndex(ICProject project) throws CoreException;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,6 +27,7 @@ import org.eclipse.cdt.internal.core.index.IWritableIndexManager;
|
||||||
import org.eclipse.cdt.internal.core.pdom.IndexerProgress;
|
import org.eclipse.cdt.internal.core.pdom.IndexerProgress;
|
||||||
import org.eclipse.cdt.internal.core.pdom.PDOMManager;
|
import org.eclipse.cdt.internal.core.pdom.PDOMManager;
|
||||||
import org.eclipse.cdt.internal.core.pdom.WritablePDOM;
|
import org.eclipse.cdt.internal.core.pdom.WritablePDOM;
|
||||||
|
import org.eclipse.core.resources.IProject;
|
||||||
import org.eclipse.core.runtime.CoreException;
|
import org.eclipse.core.runtime.CoreException;
|
||||||
import org.eclipse.core.runtime.IProgressMonitor;
|
import org.eclipse.core.runtime.IProgressMonitor;
|
||||||
import org.eclipse.osgi.util.NLS;
|
import org.eclipse.osgi.util.NLS;
|
||||||
|
@ -58,13 +59,19 @@ public class PDOMRebuildTask implements IPDOMIndexerTask {
|
||||||
monitor.subTask(NLS.bind(Messages.PDOMIndexerTask_collectingFilesTask,
|
monitor.subTask(NLS.bind(Messages.PDOMIndexerTask_collectingFilesTask,
|
||||||
fIndexer.getProject().getElementName()));
|
fIndexer.getProject().getElementName()));
|
||||||
|
|
||||||
ICProject project= fIndexer.getProject();
|
ICProject cproject= fIndexer.getProject();
|
||||||
if (project.getProject().isOpen()) {
|
IProject project= cproject.getProject();
|
||||||
|
if (project.isOpen() && project.exists()) {
|
||||||
try {
|
try {
|
||||||
clearIndex(project);
|
IWritableIndex index= ((IWritableIndexManager) CCorePlugin.getIndexManager()).getWritableIndex(cproject);
|
||||||
if (!IPDOMManager.ID_NO_INDEXER.equals(fIndexer.getID())) {
|
if (index != null) {
|
||||||
createDelegate(project, monitor);
|
clearIndex(cproject, index);
|
||||||
|
if (!IPDOMManager.ID_NO_INDEXER.equals(fIndexer.getID())) {
|
||||||
|
createDelegate(cproject, monitor);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
// remove task-tags.
|
||||||
|
TodoTaskUpdater.removeTasksFor(project);
|
||||||
} catch (CoreException e) {
|
} catch (CoreException e) {
|
||||||
CCorePlugin.log(e);
|
CCorePlugin.log(e);
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
|
@ -76,8 +83,7 @@ public class PDOMRebuildTask implements IPDOMIndexerTask {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void clearIndex(ICProject project) throws CoreException, InterruptedException {
|
private void clearIndex(ICProject project, IWritableIndex index) throws CoreException, InterruptedException {
|
||||||
IWritableIndex index= ((IWritableIndexManager) CCorePlugin.getIndexManager()).getWritableIndex(project);
|
|
||||||
// First clear the pdom
|
// First clear the pdom
|
||||||
index.acquireWriteLock(0);
|
index.acquireWriteLock(0);
|
||||||
try {
|
try {
|
||||||
|
@ -90,8 +96,6 @@ public class PDOMRebuildTask implements IPDOMIndexerTask {
|
||||||
finally {
|
finally {
|
||||||
index.releaseWriteLock(0);
|
index.releaseWriteLock(0);
|
||||||
}
|
}
|
||||||
// remove task-tags.
|
|
||||||
TodoTaskUpdater.removeTasksFor(project.getProject());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private synchronized void createDelegate(ICProject project, IProgressMonitor monitor) throws CoreException {
|
private synchronized void createDelegate(ICProject project, IProgressMonitor monitor) throws CoreException {
|
||||||
|
|
|
@ -6,8 +6,8 @@
|
||||||
* http://www.eclipse.org/legal/epl-v10.html
|
* http://www.eclipse.org/legal/epl-v10.html
|
||||||
*
|
*
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* QNX - Initial API and implementation
|
* QNX - Initial API and implementation
|
||||||
* Markus Schorn (Wind River Systems)
|
* Markus Schorn (Wind River Systems)
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
|
|
||||||
package org.eclipse.cdt.internal.core.pdom.indexer.fast;
|
package org.eclipse.cdt.internal.core.pdom.indexer.fast;
|
||||||
|
@ -79,7 +79,9 @@ class PDOMFastIndexerTask extends PDOMIndexerTask implements CallbackHandler {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
setupIndexAndReaderFactory();
|
if (!setupIndexAndReaderFactory()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
fIndex.acquireReadLock();
|
fIndex.acquireReadLock();
|
||||||
try {
|
try {
|
||||||
registerTUsInReaderFactory(sources);
|
registerTUsInReaderFactory(sources);
|
||||||
|
@ -114,12 +116,16 @@ class PDOMFastIndexerTask extends PDOMIndexerTask implements CallbackHandler {
|
||||||
traceEnd(start, fIndex);
|
traceEnd(start, fIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setupIndexAndReaderFactory() throws CoreException {
|
private boolean setupIndexAndReaderFactory() throws CoreException {
|
||||||
fIndex= ((IWritableIndexManager) CCorePlugin.getIndexManager()).getWritableIndex(getProject());
|
fIndex= ((IWritableIndexManager) CCorePlugin.getIndexManager()).getWritableIndex(getProject());
|
||||||
|
if (fIndex == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
fIndex.resetCacheCounters();
|
fIndex.resetCacheCounters();
|
||||||
fIflCache = new HashMap/*<String,IIndexFileLocation>*/();
|
fIflCache = new HashMap/*<String,IIndexFileLocation>*/();
|
||||||
fCodeReaderFactory = new IndexBasedCodeReaderFactory(getCProject(), fIndex, fIflCache);
|
fCodeReaderFactory = new IndexBasedCodeReaderFactory(getCProject(), fIndex, fIflCache);
|
||||||
fCodeReaderFactory.setCallbackHandler(this);
|
fCodeReaderFactory.setCallbackHandler(this);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void registerTUsInReaderFactory(Collection tus) throws CoreException {
|
private void registerTUsInReaderFactory(Collection tus) throws CoreException {
|
||||||
|
|
|
@ -6,8 +6,8 @@
|
||||||
* http://www.eclipse.org/legal/epl-v10.html
|
* http://www.eclipse.org/legal/epl-v10.html
|
||||||
*
|
*
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* QNX - Initial API and implementation
|
* QNX - Initial API and implementation
|
||||||
* Markus Schorn (Wind River Systems)
|
* Markus Schorn (Wind River Systems)
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
|
|
||||||
package org.eclipse.cdt.internal.core.pdom.indexer.full;
|
package org.eclipse.cdt.internal.core.pdom.indexer.full;
|
||||||
|
@ -86,10 +86,12 @@ class PDOMFullIndexerTask extends PDOMIndexerTask {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
setupIndex();
|
if (!setupIndex()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
registerTUsInReaderFactory(sources);
|
registerTUsInReaderFactory(sources);
|
||||||
registerTUsInReaderFactory(headers);
|
registerTUsInReaderFactory(headers);
|
||||||
|
|
||||||
Iterator i= fRemoved.iterator();
|
Iterator i= fRemoved.iterator();
|
||||||
while (i.hasNext()) {
|
while (i.hasNext()) {
|
||||||
if (monitor.isCanceled())
|
if (monitor.isCanceled())
|
||||||
|
@ -118,12 +120,16 @@ class PDOMFullIndexerTask extends PDOMIndexerTask {
|
||||||
traceEnd(start, fIndex);
|
traceEnd(start, fIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setupIndex() throws CoreException {
|
private boolean setupIndex() throws CoreException {
|
||||||
// there is no mechanism to clear dirty files from the cache, so flush it.
|
// there is no mechanism to clear dirty files from the cache, so flush it.
|
||||||
SavedCodeReaderFactory.getInstance().getCodeReaderCache().flush();
|
SavedCodeReaderFactory.getInstance().getCodeReaderCache().flush();
|
||||||
|
|
||||||
fIndex = ((IWritableIndexManager) CCorePlugin.getIndexManager()).getWritableIndex(getProject());
|
fIndex = ((IWritableIndexManager) CCorePlugin.getIndexManager()).getWritableIndex(getProject());
|
||||||
|
if (fIndex == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
fIndex.resetCacheCounters();
|
fIndex.resetCacheCounters();
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void registerTUsInReaderFactory(Collection/*<ITranslationUnit>*/ sources)
|
private void registerTUsInReaderFactory(Collection/*<ITranslationUnit>*/ sources)
|
||||||
|
|
Loading…
Add table
Reference in a new issue