diff options
author | Sergey Prigogin | 2014-04-22 23:02:51 +0000 |
---|---|---|
committer | Sergey Prigogin | 2014-04-22 23:07:29 +0000 |
commit | 2724fbbe45994673ad6af70cab6137f0f4fcc19d (patch) | |
tree | a5b7bcb7aa57f4fb1cb2a84fc7b6c3e3b1f01a3d | |
parent | 185074996d9538b91fbf2fb2ff398637fbf4c7b1 (diff) | |
download | org.eclipse.cdt-2724fbbe45994673ad6af70cab6137f0f4fcc19d.tar.gz org.eclipse.cdt-2724fbbe45994673ad6af70cab6137f0f4fcc19d.tar.xz org.eclipse.cdt-2724fbbe45994673ad6af70cab6137f0f4fcc19d.zip |
Improved reliability of indexer cancellation - a safer version.
18 files changed, 128 insertions, 108 deletions
diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/PDOMCPPBugsTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/PDOMCPPBugsTest.java index 97a13d904e9..36694557fcd 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/PDOMCPPBugsTest.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/PDOMCPPBugsTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007, 2010 Symbian Software Systems and others. + * Copyright (c) 2007, 2014 Symbian Software Systems 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 @@ -72,7 +72,7 @@ public class PDOMCPPBugsTest extends BaseTestCase { public void testPDOMProperties() throws Exception { PDOM pdom = (PDOM) CCoreInternals.getPDOMManager().getPDOM(cproject); - pdom.acquireWriteLock(0); + pdom.acquireWriteLock(0, null); try { WritablePDOM wpdom = (WritablePDOM) pdom; IIndexBinding[] b = wpdom.findBindings(Pattern.compile(".+"), false, IndexFilter.ALL, null); @@ -111,7 +111,7 @@ public class PDOMCPPBugsTest extends BaseTestCase { File tmp= new File(System.getProperty("java.io.tmpdir")+"/temp"+System.currentTimeMillis()+".pdom"); IIndexLocationConverter cvr= new ResourceContainerRelativeLocationConverter(cproject.getProject()); final PDOMManager pdomManager = CCoreInternals.getPDOMManager(); - pdomManager.exportProjectPDOM(cproject, tmp, cvr); + pdomManager.exportProjectPDOM(cproject, tmp, cvr, null); IWritableIndexFragment pdom = new WritablePDOM(tmp, cvr, new ChunkCache(), LanguageManager.getInstance().getPDOMLinkageFactoryMappings()); pdom.acquireReadLock(); @@ -155,7 +155,7 @@ public class PDOMCPPBugsTest extends BaseTestCase { public void testInterruptingAcquireReadLock() throws Exception { final PDOM pdom= (PDOM) CCoreInternals.getPDOMManager().getPDOM(cproject); final boolean[] ok= {false}; - pdom.acquireWriteLock(); + pdom.acquireWriteLock(null); try { Thread other= new Thread() { @Override @@ -175,7 +175,7 @@ public class PDOMCPPBugsTest extends BaseTestCase { finally { pdom.releaseWriteLock(); } - pdom.acquireWriteLock(); + pdom.acquireWriteLock(null); pdom.releaseWriteLock(); } @@ -189,7 +189,7 @@ public class PDOMCPPBugsTest extends BaseTestCase { public void run() { try { pdom.acquireReadLock(); - pdom.acquireWriteLock(1); + pdom.acquireWriteLock(1, null); } catch (InterruptedException e) { ok[0]= true; pdom.releaseReadLock(); @@ -204,7 +204,7 @@ public class PDOMCPPBugsTest extends BaseTestCase { finally { pdom.releaseReadLock(); } - pdom.acquireWriteLock(); + pdom.acquireWriteLock(null); pdom.releaseWriteLock(); } diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/PDOMNameTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/PDOMNameTests.java index 9dcde135f75..54563209258 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/PDOMNameTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/PDOMNameTests.java @@ -1,3 +1,13 @@ +/******************************************************************************* + * Copyright (c) 2013, 2014 QNX Software Systems 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 + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Andrew Eidsness - Initial implementation + *******************************************************************************/ package org.eclipse.cdt.internal.pdom.tests; import junit.framework.Test; @@ -30,7 +40,7 @@ public class PDOMNameTests extends BaseTestCase { @Override protected void setUp() throws Exception { super.setUp(); - cproject= CProjectHelper.createCCProject("PDOMNameTest"+System.currentTimeMillis(), "bin", IPDOMManager.ID_FAST_INDEXER); + cproject= CProjectHelper.createCCProject("PDOMNameTest" + System.currentTimeMillis(), "bin", IPDOMManager.ID_FAST_INDEXER); waitForIndexer(cproject); } @@ -53,7 +63,7 @@ public class PDOMNameTests extends BaseTestCase { waitForIndexer(cproject); PDOM pdom = (PDOM) CCoreInternals.getPDOMManager().getPDOM(cproject); - pdom.acquireWriteLock(); + pdom.acquireWriteLock(null); try { IIndexBinding[] bindings = pdom.findBindings(new char[][]{"E_cpp".toCharArray()}, IndexFilter.ALL, npm()); assertEquals(1, bindings.length); @@ -158,7 +168,6 @@ public class PDOMNameTests extends BaseTestCase { // 5) Check deleting of first entry. extRef_3.delete(); assertEquals(0, countExternalReferences(binding_cpp)); - } finally { pdom.releaseWriteLock(); } diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/PDOMProviderTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/PDOMProviderTests.java index 8e52106f071..87d54e2c6df 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/PDOMProviderTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/PDOMProviderTests.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007, 2012 Symbian Software Systems and others. + * Copyright (c) 2007, 2014 Symbian Software Systems 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 @@ -69,7 +69,7 @@ public class PDOMProviderTests extends PDOMTestBase { } ResourceContainerRelativeLocationConverter cvr= new ResourceContainerRelativeLocationConverter(cproject.getProject()); - CCoreInternals.getPDOMManager().exportProjectPDOM(cproject, tempPDOM, cvr); + CCoreInternals.getPDOMManager().exportProjectPDOM(cproject, tempPDOM, cvr, null); assertTrue(tempPDOM.exists()); CProjectHelper.delete(cproject); @@ -141,7 +141,7 @@ public class PDOMProviderTests extends PDOMTestBase { } ResourceContainerRelativeLocationConverter cvr= new ResourceContainerRelativeLocationConverter(cproject.getProject()); - CCoreInternals.getPDOMManager().exportProjectPDOM(cproject, tempPDOM, cvr); + CCoreInternals.getPDOMManager().exportProjectPDOM(cproject, tempPDOM, cvr, null); assertTrue(tempPDOM.exists()); CProjectHelper.delete(cproject); @@ -249,12 +249,12 @@ public class PDOMProviderTests extends PDOMTestBase { TestSourceReader.createFile(cproject.getProject(), new Path("/this.h"), "class A {};\n\n"); waitForIndexer(cproject); ResourceContainerRelativeLocationConverter cvr= new ResourceContainerRelativeLocationConverter(cproject.getProject()); - CCoreInternals.getPDOMManager().exportProjectPDOM(cproject, tempPDOM, cvr); + CCoreInternals.getPDOMManager().exportProjectPDOM(cproject, tempPDOM, cvr, null); CProjectHelper.delete(cproject); // Mimic a PDOM with superseded version. WritablePDOM wpdom= new WritablePDOM(tempPDOM, cvr, LanguageManager.getInstance().getPDOMLinkageFactoryMappings()); - wpdom.acquireWriteLock(); + wpdom.acquireWriteLock(null); try { wpdom.getDB().setVersion(1); wpdom.close(); diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/PDOMTagIndexTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/PDOMTagIndexTests.java index c735691e987..d1c4795912b 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/PDOMTagIndexTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/PDOMTagIndexTests.java @@ -1,5 +1,5 @@ -/* - * Copyright (c) 2013 QNX Software Systems and others. +/******************************************************************************* + * Copyright (c) 2013, 2014 QNX Software Systems 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 @@ -7,7 +7,7 @@ * * Contributors: * Andrew Eidsness - Initial implementation - */ + *******************************************************************************/ package org.eclipse.cdt.internal.pdom.tests; import java.io.File; @@ -58,7 +58,7 @@ public class PDOMTagIndexTests extends BaseTestCase { + Double.toString(Math.random()).substring(2), null); pdom = new WritablePDOM(tmpFile, new MockIndexLocationConverter(), LanguageManager.getInstance().getPDOMLinkageFactoryMappings()); - pdom.acquireWriteLock(); + pdom.acquireWriteLock(null); } @Override diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/IWritableIndex.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/IWritableIndex.java index d01278ae559..f1a31e0c7f8 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/IWritableIndex.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/IWritableIndex.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2006, 2012 Wind River Systems, Inc. and others. + * Copyright (c) 2006, 2014 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 @@ -21,6 +21,7 @@ import org.eclipse.cdt.core.parser.ISignificantMacros; import org.eclipse.cdt.internal.core.pdom.ASTFilePathResolver; import org.eclipse.cdt.internal.core.pdom.YieldableIndexLock; import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IProgressMonitor; /** * Interface used by the indexer to write to the index. A writable index is not thread-safe, @@ -123,7 +124,7 @@ public interface IWritableIndex extends IIndex { /** * Acquires a write lock, while giving up a certain amount of read locks. */ - void acquireWriteLock() throws InterruptedException; + void acquireWriteLock(IProgressMonitor monitor) throws InterruptedException; /** * Releases a write lock, reestablishing a certain amount of read locks. diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/IWritableIndexFragment.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/IWritableIndexFragment.java index bad8218156e..a295f743511 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/IWritableIndexFragment.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/IWritableIndexFragment.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2006, 2010 Wind River Systems, Inc. and others. + * Copyright (c) 2006, 2014 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 @@ -20,6 +20,7 @@ import org.eclipse.cdt.internal.core.index.IWritableIndex.IncludeInformation; import org.eclipse.cdt.internal.core.pdom.ASTFilePathResolver; import org.eclipse.cdt.internal.core.pdom.YieldableIndexLock; import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IProgressMonitor; /** * The interface that an actual storage for an index has to implement. @@ -85,7 +86,7 @@ public interface IWritableIndexFragment extends IIndexFragment { /** * Acquires a write lock, while giving up a certain amount of read locks. */ - void acquireWriteLock(int giveupReadLockCount) throws InterruptedException; + void acquireWriteLock(int giveupReadLockCount, IProgressMonitor monitor) throws InterruptedException; /** * Releases a write lock, reestablishing a certain amount of read locks. diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/WritableCIndex.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/WritableCIndex.java index 074242f51de..6a677a5310c 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/WritableCIndex.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/WritableCIndex.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2006, 2012 Wind River Systems, Inc. and others. + * Copyright (c) 2006, 2014 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 @@ -19,6 +19,7 @@ import org.eclipse.cdt.core.parser.ISignificantMacros; import org.eclipse.cdt.internal.core.pdom.ASTFilePathResolver; import org.eclipse.cdt.internal.core.pdom.YieldableIndexLock; import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IProgressMonitor; public class WritableCIndex extends CIndex implements IWritableIndex { private boolean fIsWriteLocked; @@ -113,11 +114,11 @@ public class WritableCIndex extends CIndex implements IWritableIndex { } @Override - public void acquireWriteLock() throws InterruptedException { + public void acquireWriteLock(IProgressMonitor monitor) throws InterruptedException { checkThread(); assert !fIsWriteLocked: "Multiple write locks is not allowed"; //$NON-NLS-1$ - getWritableFragment().acquireWriteLock(getReadLockCount()); + getWritableFragment().acquireWriteLock(getReadLockCount(), monitor); fIsWriteLocked= true; } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/indexer/StandaloneIndexer.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/indexer/StandaloneIndexer.java index c816b677755..e8d54d83e2c 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/indexer/StandaloneIndexer.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/indexer/StandaloneIndexer.java @@ -354,11 +354,10 @@ public abstract class StandaloneIndexer { private void clearIndex() throws CoreException, InterruptedException { IWritableIndex index= getIndex(); // First clear the pdom - index.acquireWriteLock(); + index.acquireWriteLock(null); try { index.clear(); - } - finally { + } finally { index.releaseWriteLock(); } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/AbstractIndexerTask.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/AbstractIndexerTask.java index 63d9b455d14..f61986b6a1e 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/AbstractIndexerTask.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/AbstractIndexerTask.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007, 2013 Wind River Systems, Inc. and others. + * Copyright (c) 2007, 2014 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 @@ -322,6 +322,7 @@ public abstract class AbstractIndexerTask extends PDOMWriter { private final LinkedList<AbstractIndexerTask> fUrgentTasks; boolean fTaskCompleted; private IndexerProgress fInfo= new IndexerProgress(); + private IProgressMonitor fProgressMonitor; public AbstractIndexerTask(Object[] filesToUpdate, Object[] filesToRemove, IndexerInputAdapter resolver, boolean fastIndexer) { @@ -498,6 +499,7 @@ public abstract class AbstractIndexerTask extends PDOMWriter { } public final void runTask(IProgressMonitor monitor) throws InterruptedException { + fProgressMonitor = monitor; try { if (!fIndexFilesWithoutConfiguration) { fIndexHeadersWithoutContext= UnusedHeaderStrategy.skip; @@ -600,11 +602,12 @@ public abstract class AbstractIndexerTask extends PDOMWriter { synchronized (this) { fTaskCompleted = true; } + fProgressMonitor = null; } } private void setResume(boolean value) throws InterruptedException, CoreException { - fIndex.acquireWriteLock(); + fIndex.acquireWriteLock(fProgressMonitor); try { fIndex.getWritableFragment().setProperty(IIndexFragment.PROPERTY_RESUME_INDEXER, String.valueOf(value)); } finally { @@ -810,7 +813,7 @@ public abstract class AbstractIndexerTask extends PDOMWriter { private void removeFilesInIndex(List<Object> filesToRemove, List<IIndexFragmentFile> indexFilesToRemove, IProgressMonitor monitor) throws InterruptedException, CoreException { if (!filesToRemove.isEmpty() || !indexFilesToRemove.isEmpty()) { - fIndex.acquireWriteLock(); + fIndex.acquireWriteLock(fProgressMonitor); try { for (Object tu : filesToRemove) { if (monitor.isCanceled()) { @@ -899,7 +902,7 @@ public abstract class AbstractIndexerTask extends PDOMWriter { } // Delete remaining files. - fIndex.acquireWriteLock(); + fIndex.acquireWriteLock(fProgressMonitor); try { for (IIndexFileLocation ifl : files) { LocationTask locTask = map.find(ifl); @@ -1077,7 +1080,7 @@ public abstract class AbstractIndexerTask extends PDOMWriter { if (!resultCacheCleared) { // If the result cache has not been cleared, clear it under a write lock to reduce // interference with index readers. - fIndex.acquireWriteLock(); + fIndex.acquireWriteLock(fProgressMonitor); try { fIndex.clearResultCache(); } finally { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOM.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOM.java index a0ffcdce685..513598bc25f 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOM.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOM.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2005, 2012 QNX Software Systems and others. + * Copyright (c) 2005, 2014 QNX Software Systems 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 @@ -102,6 +102,7 @@ import org.eclipse.core.runtime.Status; * Database for storing semantic information for one project. */ public class PDOM extends PlatformObject implements IPDOM { + private static final int CANCELLATION_CHECK_INTERVAL = 500; private static final int BLOCKED_WRITE_LOCK_OUTPUT_INTERVAL = 30000; private static final int LONG_WRITE_LOCK_REPORT_THRESHOLD = 1000; private static final int LONG_READ_LOCK_WAIT_REPORT_THRESHOLD = 1000; @@ -989,8 +990,8 @@ public class PDOM extends PlatformObject implements IPDOM { * @throws InterruptedException * @throws IllegalStateException if this PDOM is not writable */ - public void acquireWriteLock() throws InterruptedException { - acquireWriteLock(0); + public void acquireWriteLock(IProgressMonitor monitor) throws InterruptedException { + acquireWriteLock(0, monitor); } /** @@ -999,7 +1000,7 @@ public class PDOM extends PlatformObject implements IPDOM { * @throws InterruptedException * @throws IllegalStateException if this PDOM is not writable */ - public void acquireWriteLock(int giveupReadLocks) throws InterruptedException { + public void acquireWriteLock(int giveupReadLocks, IProgressMonitor monitor) throws InterruptedException { assert !isPermanentlyReadOnly(); synchronized (mutex) { if (sDEBUG_LOCKS) { @@ -1019,7 +1020,10 @@ public class PDOM extends PlatformObject implements IPDOM { // Let the readers go first long start= sDEBUG_LOCKS ? System.currentTimeMillis() : 0; while (lockCount > giveupReadLocks || waitingReaders > 0) { - mutex.wait(BLOCKED_WRITE_LOCK_OUTPUT_INTERVAL); + mutex.wait(CANCELLATION_CHECK_INTERVAL); + if (monitor.isCanceled()) { + throw new OperationCanceledException(); + } if (sDEBUG_LOCKS) { start = reportBlockedWriteLock(start, giveupReadLocks); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOMIndexerJob.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOMIndexerJob.java index fa6e73bbc35..2e6f88f6da9 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOMIndexerJob.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOMIndexerJob.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2005, 2014 QNX Software Systems + * Copyright (c) 2005, 2010 QNX Software Systems * 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: * Doug Schaefer (QNX Software Systems) - initial API and implementation * Markus Schorn (Wind River Systems) - * Sergey Prigogin (Google) *******************************************************************************/ package org.eclipse.cdt.internal.core.pdom; @@ -141,8 +140,7 @@ public class PDOMIndexerJob extends Job { System.out.println("Indexer: completed " + name + "[" + time + "ms]"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ } } catch (InterruptedException e) { - // An interrupt cancels the current task. - Thread.interrupted(); // Clear interrupted status. + Thread.currentThread().interrupt(); } catch (OperationCanceledException e) { } } @@ -200,15 +198,7 @@ public class PDOMIndexerJob extends Job { } } } - - @Override - protected void canceling() { - Thread currThread = getThread(); - if (currThread != null) { - currThread.interrupt(); - } - } - + @Override public boolean belongsTo(Object family) { return family == pdomManager; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOMManager.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOMManager.java index 7cc48e6bbcb..51f9a4340dd 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOMManager.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOMManager.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2005, 2013 QNX Software Systems and others. + * Copyright (c) 2005, 2014 QNX Software Systems 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 @@ -344,7 +344,7 @@ public class PDOMManager implements IWritableIndexManager, IListener { * case a pdom ready to use is returned. * @throws CoreException */ - private WritablePDOM getOrCreatePDOM(ICProject project) throws CoreException { + private WritablePDOM getOrCreatePDOM(ICProject project, IProgressMonitor monitor) throws CoreException { synchronized (fProjectToPDOM) { IProject rproject = project.getProject(); IPDOM pdomProxy= fProjectToPDOM.get(rproject); @@ -384,7 +384,7 @@ public class PDOMManager implements IWritableIndexManager, IListener { WritablePDOM pdom= new WritablePDOM(dbFile, new PDOMProjectIndexLocationConverter(rproject), getLinkageFactories()); if (!pdom.isSupportedVersion() || fromScratch) { try { - pdom.acquireWriteLock(); + pdom.acquireWriteLock(monitor); } catch (InterruptedException e) { throw new CoreException(CCorePlugin.createStatus(Messages.PDOMManager_creationOfIndexInterrupted, e)); } @@ -569,7 +569,7 @@ public class PDOMManager implements IWritableIndexManager, IListener { return; } - WritablePDOM pdom= getOrCreatePDOM(project); + WritablePDOM pdom= getOrCreatePDOM(project, pm); Properties props= IndexerPreferences.getProperties(prj); IPDOMIndexer indexer= newIndexer(getIndexerId(project), props); IndexUpdatePolicy policy= createPolicy(project); @@ -862,7 +862,7 @@ public class PDOMManager implements IWritableIndexManager, IListener { @Override protected IStatus run(IProgressMonitor monitor) { try { - finalpdom.acquireWriteLock(); + finalpdom.acquireWriteLock(monitor); try { finalpdom.close(); if (delete) { @@ -1235,10 +1235,12 @@ public class PDOMManager implements IWritableIndexManager, IListener { * Note. This will acquire a write lock while the pdom is exported * @param targetLocation a location that does not currently exist * @param newConverter + * @param monitor * @throws CoreException * @throws IllegalArgumentException if a file exists at targetLocation */ - public void exportProjectPDOM(ICProject cproject, File targetLocation, final IIndexLocationConverter newConverter) throws CoreException { + public void exportProjectPDOM(ICProject cproject, File targetLocation, + final IIndexLocationConverter newConverter, IProgressMonitor monitor) throws CoreException { if (targetLocation.exists()) { boolean deleted= targetLocation.delete(); if (!deleted) { @@ -1249,7 +1251,7 @@ public class PDOMManager implements IWritableIndexManager, IListener { } try { // Copy it. - PDOM pdom= getOrCreatePDOM(cproject); + PDOM pdom= getOrCreatePDOM(cproject, monitor); pdom.acquireReadLock(); String oldID= null; try { @@ -1264,7 +1266,7 @@ public class PDOMManager implements IWritableIndexManager, IListener { // Overwrite internal location representations. final WritablePDOM newPDOM = new WritablePDOM(targetLocation, pdom.getLocationConverter(), getLinkageFactories()); - newPDOM.acquireWriteLock(); + newPDOM.acquireWriteLock(null); try { newPDOM.rewriteLocations(newConverter); @@ -1284,11 +1286,12 @@ public class PDOMManager implements IWritableIndexManager, IListener { /** * Resets the pdom for the project with the provided stream. + * @param monitor * @throws CoreException * @throws OperationCanceledException in case the thread was interrupted * @since 4.0 */ - public void importProjectPDOM(ICProject project, InputStream stream) throws CoreException, IOException { + public void importProjectPDOM(ICProject project, InputStream stream, IProgressMonitor monitor) throws CoreException, IOException { // make a copy of the database String newName= createNewDatabaseName(project); File newFile= fileFromDatabaseName(newName); @@ -1319,7 +1322,7 @@ public class PDOMManager implements IWritableIndexManager, IListener { WritablePDOM pdom= (WritablePDOM) getPDOM(project); try { - pdom.acquireWriteLock(); + pdom.acquireWriteLock(monitor); } catch (InterruptedException e) { throw new OperationCanceledException(); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOMWriter.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOMWriter.java index 6226751bccd..98c5b9bda63 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOMWriter.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOMWriter.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007, 2013 Wind River Systems, Inc. and others. + * Copyright (c) 2007, 2014 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 @@ -12,6 +12,16 @@ *******************************************************************************/ package org.eclipse.cdt.internal.core.pdom; +import java.io.PrintWriter; +import java.io.StringWriter; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Set; + import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.dom.ILinkage; import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier; @@ -63,16 +73,6 @@ import org.eclipse.core.runtime.MultiStatus; import org.eclipse.core.runtime.Status; import org.eclipse.osgi.util.NLS; -import java.io.PrintWriter; -import java.io.StringWriter; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Set; - /** * Abstract class to write information from AST. * @since 4.0 @@ -313,7 +313,7 @@ abstract public class PDOMWriter implements IPDOMASTProcessor { trace("Indexer: adding " + fileInAST.fileContentKey.getLocation().getURI()); //$NON-NLS-1$ } Throwable th= null; - YieldableIndexLock lock = new YieldableIndexLock(data.fIndex, false); + YieldableIndexLock lock = new YieldableIndexLock(data.fIndex, false, pm); lock.acquire(); try { final boolean isReplacement= ctx != null && fileInAST.includeStatement == null; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/TeamPDOMExportOperation.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/TeamPDOMExportOperation.java index 90242f833a9..9d54bda8dcc 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/TeamPDOMExportOperation.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/TeamPDOMExportOperation.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007, 2010 Wind River Systems, Inc. and others. + * Copyright (c) 2007, 2014 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 @@ -107,7 +107,7 @@ public class TeamPDOMExportOperation implements IWorkspaceRunnable { // create index IIndexLocationConverter converter= new PDOMProjectIndexLocationConverter(fProject.getProject(), true); - pdomManager.exportProjectPDOM(fProject, tmpPDOM, converter); + pdomManager.exportProjectPDOM(fProject, tmpPDOM, converter, monitor); checkMonitor(monitor); monitor.worked(5); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/TeamPDOMImportOperation.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/TeamPDOMImportOperation.java index 3fbeaa380a7..62a126a556c 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/TeamPDOMImportOperation.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/TeamPDOMImportOperation.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007, 2010 Wind River Systems, Inc. and others. + * Copyright (c) 2007, 2014 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 @@ -168,7 +168,7 @@ public class TeamPDOMImportOperation implements IWorkspaceRunnable { NLS.bind(Messages.PDOMImportTask_errorInvalidArchive, zip.getName()))); } InputStream stream= zip.getInputStream(indexEntry); - CCoreInternals.getPDOMManager().importProjectPDOM(fProject, stream); + CCoreInternals.getPDOMManager().importProjectPDOM(fProject, stream, monitor); } private Map<?, ?> getChecksums(ZipFile zip) { @@ -260,7 +260,7 @@ public class TeamPDOMImportOperation implements IWorkspaceRunnable { private void updateIndex(WritablePDOM pdom, final int giveupReadlocks, IIndexFragmentFile[] filesToDelete, List<FileAndChecksum> updateTimestamps, IProgressMonitor monitor) throws InterruptedException, CoreException { - pdom.acquireWriteLock(giveupReadlocks); + pdom.acquireWriteLock(giveupReadlocks, null); try { for (IIndexFragmentFile ifile : filesToDelete) { if (ifile != null) { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/YieldableIndexLock.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/YieldableIndexLock.java index 4420b6ad6ab..346429c39d5 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/YieldableIndexLock.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/YieldableIndexLock.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2010 Google, Inc and others. + * Copyright (c) 2010, 2014 Google, 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 @@ -11,6 +11,7 @@ package org.eclipse.cdt.internal.core.pdom; import org.eclipse.cdt.internal.core.index.IWritableIndex; +import org.eclipse.core.runtime.IProgressMonitor; /** * Write lock on the index that can be yielded temporarily to unblock threads that need @@ -20,12 +21,14 @@ import org.eclipse.cdt.internal.core.index.IWritableIndex; public class YieldableIndexLock { private final IWritableIndex index; private final boolean flushIndex; + private final IProgressMonitor progressMonitor; private long lastLockTime; private long cumulativeLockTime; - public YieldableIndexLock(IWritableIndex index, boolean flushIndex) { + public YieldableIndexLock(IWritableIndex index, boolean flushIndex, IProgressMonitor monitor) { this.index = index; this.flushIndex = flushIndex; + this.progressMonitor = monitor; } /** @@ -34,7 +37,7 @@ public class YieldableIndexLock { * @throws InterruptedException */ public void acquire() throws InterruptedException { - index.acquireWriteLock(); + index.acquireWriteLock(progressMonitor); lastLockTime = System.currentTimeMillis(); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/export/GeneratePDOM.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/export/GeneratePDOM.java index 6312b599510..e77f6429020 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/export/GeneratePDOM.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/export/GeneratePDOM.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007, 2013 Symbian Software Systems and others. + * Copyright (c) 2007, 2014 Symbian Software Systems 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 @@ -127,12 +127,12 @@ public class GeneratePDOM { } } // Export a .pdom file - CCoreInternals.getPDOMManager().exportProjectPDOM(cproject, targetLocation, converter); + CCoreInternals.getPDOMManager().exportProjectPDOM(cproject, targetLocation, converter, null); // Write properties to exported PDOM WritablePDOM exportedPDOM= new WritablePDOM(targetLocation, converter, LanguageManager.getInstance().getPDOMLinkageFactoryMappings()); - exportedPDOM.acquireWriteLock(0); + exportedPDOM.acquireWriteLock(0, null); try { Map<String, String> exportProperties= pm.getExportProperties(); if (exportProperties != null) { 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 7351fa28caa..1d3b17ff230 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 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007, 2010 Wind River Systems, Inc. and others. + * Copyright (c) 2007, 2014 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 @@ -42,6 +42,7 @@ public class PDOMRebuildTask implements IPDOMIndexerTask { private final IPDOMIndexer fIndexer; private final IndexerProgress fProgress; private volatile IPDOMIndexerTask fDelegate; + private IProgressMonitor fProgressMonitor; public PDOMRebuildTask(IPDOMIndexer indexer) { fIndexer= indexer; @@ -61,36 +62,41 @@ public class PDOMRebuildTask implements IPDOMIndexerTask { @Override public void run(IProgressMonitor monitor) throws InterruptedException { - monitor.subTask(NLS.bind(Messages.PDOMIndexerTask_collectingFilesTask, - fIndexer.getProject().getElementName())); - - ICProject cproject= fIndexer.getProject(); - IProject project= cproject.getProject(); - if (project.isOpen() && project.exists()) { - try { - IWritableIndex index= ((IWritableIndexManager) CCorePlugin.getIndexManager()).getWritableIndex(cproject); - if (index != null) { - clearIndex(cproject, index); - if (!IPDOMManager.ID_NO_INDEXER.equals(fIndexer.getID())) { - createDelegate(cproject, monitor); + fProgressMonitor = monitor; + try { + monitor.subTask(NLS.bind(Messages.PDOMIndexerTask_collectingFilesTask, + fIndexer.getProject().getElementName())); + + ICProject cproject= fIndexer.getProject(); + IProject project= cproject.getProject(); + if (project.isOpen() && project.exists()) { + try { + IWritableIndex index= ((IWritableIndexManager) CCorePlugin.getIndexManager()).getWritableIndex(cproject); + if (index != null) { + clearIndex(cproject, index); + if (!IPDOMManager.ID_NO_INDEXER.equals(fIndexer.getID())) { + createDelegate(cproject, monitor); + } } + // remove task-tags. + TodoTaskUpdater.removeTasksFor(project); + } catch (CoreException e) { + CCorePlugin.log(NLS.bind(Messages.PDOMRebuildTask_0, cproject.getElementName() ), e); + } catch (InterruptedException e) { } - // remove task-tags. - TodoTaskUpdater.removeTasksFor(project); - } catch (CoreException e) { - CCorePlugin.log(NLS.bind(Messages.PDOMRebuildTask_0, cproject.getElementName() ), e); - } catch (InterruptedException e) { } - } - - if (fDelegate != null) { - fDelegate.run(monitor); + + if (fDelegate != null) { + fDelegate.run(monitor); + } + } finally { + fProgressMonitor = null; } } private void clearIndex(ICProject project, IWritableIndex index) throws CoreException, InterruptedException { // First clear the pdom - index.acquireWriteLock(); + index.acquireWriteLock(fProgressMonitor); try { index.clear(); IWritableIndexFragment wf= index.getWritableFragment(); |