diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexBugsTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexBugsTests.java index 9a32bfe3f89..8640ce62810 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexBugsTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexBugsTests.java @@ -382,6 +382,7 @@ public class IndexBugsTests extends BaseTestCase { header.setContents(in, IResource.FORCE, null); TestSourceReader.waitUntilFileIsIndexed(index, header, INDEX_WAIT_TIME); + index.acquireReadLock(); try { IBinding[] bindings = index.findBindings(Pattern.compile("var"), true, IndexFilter.ALL, new NullProgressMonitor()); assertEquals(1, bindings.length); diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexLocationTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexLocationTest.java index f64d32f3795..ea1e20930fd 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexLocationTest.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexLocationTest.java @@ -93,51 +93,57 @@ public class IndexLocationTest extends BaseTestCase { // #include "header.h" // #include "ABS_EXTERNAL" // class baz {}; - public void testBasicLocations() throws CoreException, ExecutionException { + public void testBasicLocations() throws CoreException, ExecutionException, InterruptedException { IIndex index = CCorePlugin.getIndexManager().getIndex(cproject); - IBinding[] bs1 = index.findBindings(Pattern.compile("foo"), true, IndexFilter.ALL, new NullProgressMonitor()); - IBinding[] bs2 = index.findBindings(Pattern.compile("bar"), true, IndexFilter.ALL, new NullProgressMonitor()); - IBinding[] bs3 = index.findBindings(Pattern.compile("baz"), true, IndexFilter.ALL, new NullProgressMonitor()); - assertEquals(1, bs1.length); - assertEquals(1, bs2.length); - assertEquals(1, bs3.length); - bs1 = index.findBindings("foo".toCharArray(), IndexFilter.ALL, new NullProgressMonitor()); - bs2 = index.findBindings("bar".toCharArray(), IndexFilter.ALL, new NullProgressMonitor()); - bs3 = index.findBindings("baz".toCharArray(), IndexFilter.ALL, new NullProgressMonitor()); - assertEquals(1, bs1.length); - assertEquals(1, bs2.length); - assertEquals(1, bs3.length); - IIndexName[] nms1 = index.findNames(bs1[0], IIndex.FIND_ALL_OCCURENCES); - IIndexName[] nms2 = index.findNames(bs2[0], IIndex.FIND_ALL_OCCURENCES); - IIndexName[] nms3 = index.findNames(bs3[0], IIndex.FIND_ALL_OCCURENCES); - assertEquals(1, nms1.length); - assertEquals(1, nms2.length); - assertEquals(1, nms3.length); - URI workspaceRoot = ResourcesPlugin.getWorkspace().getRoot().getLocationURI(); - assertEquals( - ResourcesPlugin.getWorkspace().getRoot().getFile(new Path("LocationTests/header.h")).getLocationURI(), - nms1[0].getFile().getLocation().getURI() - ); - assertEquals( - externalHeader.toURI(), - nms2[0].getFile().getLocation().getURI() - ); - assertEquals( - ResourcesPlugin.getWorkspace().getRoot().getFile(new Path("LocationTests/source.cpp")).getLocationURI(), - nms3[0].getFile().getLocation().getURI() - ); + index.acquireReadLock(); + try { + IBinding[] bs1 = index.findBindings(Pattern.compile("foo"), true, IndexFilter.ALL, new NullProgressMonitor()); + IBinding[] bs2 = index.findBindings(Pattern.compile("bar"), true, IndexFilter.ALL, new NullProgressMonitor()); + IBinding[] bs3 = index.findBindings(Pattern.compile("baz"), true, IndexFilter.ALL, new NullProgressMonitor()); + assertEquals(1, bs1.length); + assertEquals(1, bs2.length); + assertEquals(1, bs3.length); + bs1 = index.findBindings("foo".toCharArray(), IndexFilter.ALL, new NullProgressMonitor()); + bs2 = index.findBindings("bar".toCharArray(), IndexFilter.ALL, new NullProgressMonitor()); + bs3 = index.findBindings("baz".toCharArray(), IndexFilter.ALL, new NullProgressMonitor()); + assertEquals(1, bs1.length); + assertEquals(1, bs2.length); + assertEquals(1, bs3.length); + IIndexName[] nms1 = index.findNames(bs1[0], IIndex.FIND_ALL_OCCURENCES); + IIndexName[] nms2 = index.findNames(bs2[0], IIndex.FIND_ALL_OCCURENCES); + IIndexName[] nms3 = index.findNames(bs3[0], IIndex.FIND_ALL_OCCURENCES); + assertEquals(1, nms1.length); + assertEquals(1, nms2.length); + assertEquals(1, nms3.length); + URI workspaceRoot = ResourcesPlugin.getWorkspace().getRoot().getLocationURI(); + assertEquals( + ResourcesPlugin.getWorkspace().getRoot().getFile(new Path("LocationTests/header.h")).getLocationURI(), + nms1[0].getFile().getLocation().getURI() + ); + assertEquals( + externalHeader.toURI(), + nms2[0].getFile().getLocation().getURI() + ); + assertEquals( + ResourcesPlugin.getWorkspace().getRoot().getFile(new Path("LocationTests/source.cpp")).getLocationURI(), + nms3[0].getFile().getLocation().getURI() + ); - assertEquals( - ResourcesPlugin.getWorkspace().getRoot().getFile(new Path("LocationTests/header.h")).getFullPath(), - new Path(nms1[0].getFile().getLocation().getFullPath()) - ); - assertEquals( - null, - nms2[0].getFile().getLocation().getFullPath() - ); - assertEquals( - ResourcesPlugin.getWorkspace().getRoot().getFile(new Path("LocationTests/source.cpp")).getFullPath(), - new Path(nms3[0].getFile().getLocation().getFullPath()) - ); + assertEquals( + ResourcesPlugin.getWorkspace().getRoot().getFile(new Path("LocationTests/header.h")).getFullPath(), + new Path(nms1[0].getFile().getLocation().getFullPath()) + ); + assertEquals( + null, + nms2[0].getFile().getLocation().getFullPath() + ); + assertEquals( + ResourcesPlugin.getWorkspace().getRoot().getFile(new Path("LocationTests/source.cpp")).getFullPath(), + new Path(nms3[0].getFile().getLocation().getFullPath()) + ); + } + finally { + index.releaseReadLock(); + } } } \ No newline at end of file diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/IndexBindingResolutionTestBase.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/IndexBindingResolutionTestBase.java index 5f3599ed5f9..a0a593e22b4 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/IndexBindingResolutionTestBase.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/IndexBindingResolutionTestBase.java @@ -67,11 +67,14 @@ public abstract class IndexBindingResolutionTestBase extends PDOMTestBase { assertTrue(CCorePlugin.getIndexManager().joinIndexer(360000, new NullProgressMonitor())); index= CCorePlugin.getIndexManager().getIndex(cproject); - + index.acquireReadLock(); ast = TestSourceReader.createIndexBasedAST(index, cproject, cppfile); } protected void tearDown() throws Exception { + if (index != null) { + index.releaseReadLock(); + } if (cproject != null) { cproject.getProject().delete(IResource.FORCE | IResource.ALWAYS_DELETE_PROJECT_CONTENT, new NullProgressMonitor()); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/fast/PDOMFastHandleDelta.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/fast/PDOMFastHandleDelta.java index 39b655cf9de..7df3f50a05c 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/fast/PDOMFastHandleDelta.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/fast/PDOMFastHandleDelta.java @@ -37,38 +37,44 @@ class PDOMFastHandleDelta extends PDOMFastIndexerJob { long start = System.currentTimeMillis(); try { setupIndexAndReaderFactory(); - registerTUsInReaderFactory(changed); - - Iterator i= removed.iterator(); - while (i.hasNext()) { - if (monitor.isCanceled()) - return; - ITranslationUnit tu = (ITranslationUnit)i.next(); - removeTU(index, tu); - if (tu.isSourceUnit()) { - fCompletedSources++; - } - else { - fTotalSourcesEstimate--; - fCompletedHeaders++; - } - } + index.acquireReadLock(); + try { + registerTUsInReaderFactory(changed); - // separate headers - List headers= new ArrayList(); - List sources= changed; - for (Iterator iter = changed.iterator(); iter.hasNext();) { - ITranslationUnit tu = (ITranslationUnit) iter.next(); - if (!tu.isSourceUnit()) { - headers.add(tu); - iter.remove(); + Iterator i= removed.iterator(); + while (i.hasNext()) { + if (monitor.isCanceled()) + return; + ITranslationUnit tu = (ITranslationUnit)i.next(); + removeTU(index, tu); + if (tu.isSourceUnit()) { + fCompletedSources++; + } + else { + fTotalSourcesEstimate--; + fCompletedHeaders++; + } } + + // separate headers + List headers= new ArrayList(); + List sources= changed; + for (Iterator iter = changed.iterator(); iter.hasNext();) { + ITranslationUnit tu = (ITranslationUnit) iter.next(); + if (!tu.isSourceUnit()) { + headers.add(tu); + iter.remove(); + } + } + + parseTUs(sources, headers, monitor); + if (monitor.isCanceled()) { + return; + } + } + finally { + index.releaseReadLock(); } - - parseTUs(sources, headers, monitor); - if (monitor.isCanceled()) { - return; - } } catch (CoreException e) { CCorePlugin.log(e); } catch (InterruptedException e) { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/fast/PDOMFastIndexerJob.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/fast/PDOMFastIndexerJob.java index 1c2f3140968..91afca09c9a 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/fast/PDOMFastIndexerJob.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/fast/PDOMFastIndexerJob.java @@ -20,7 +20,6 @@ import java.util.Map; import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.dom.IPDOMIndexer; -import org.eclipse.cdt.core.dom.IPDOMIndexerTask; import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit; import org.eclipse.cdt.core.index.IIndexFile; import org.eclipse.cdt.core.index.IIndexFileLocation; @@ -101,22 +100,16 @@ abstract class PDOMFastIndexerJob extends PDOMIndexerTask { return; } - index.acquireReadLock(); - try { - // get the AST in a "Fast" way - IASTTranslationUnit ast= language.getASTTranslationUnit(codeReader, scanner, codeReaderFactory, index, ParserUtil.getParserLogService()); - if (pm.isCanceled()) { - return; - } - // Clear the macros - codeReaderFactory.clearMacroAttachements(); - - // Add the new symbols - addSymbols(ast, pm); - } - finally { - index.releaseReadLock(); + // get the AST in a "Fast" way + IASTTranslationUnit ast= language.getASTTranslationUnit(codeReader, scanner, codeReaderFactory, index, ParserUtil.getParserLogService()); + if (pm.isCanceled()) { + return; } + // Clear the macros + codeReaderFactory.clearMacroAttachements(); + + // Add the new symbols + addSymbols(ast, pm); } protected IWritableIndex getIndex() { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/fast/PDOMFastReindex.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/fast/PDOMFastReindex.java index 88c09748f5b..9f31ee920f9 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/fast/PDOMFastReindex.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/fast/PDOMFastReindex.java @@ -44,9 +44,15 @@ class PDOMFastReindex extends PDOMFastIndexerJob { return; } - registerTUsInReaderFactory(sources); - registerTUsInReaderFactory(headers); - parseTUs(sources, headers, monitor); + index.acquireReadLock(); + try { + registerTUsInReaderFactory(sources); + registerTUsInReaderFactory(headers); + parseTUs(sources, headers, monitor); + } + finally { + index.releaseReadLock(); + } } catch (CoreException e) { CCorePlugin.log(e); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/full/PDOMFullHandleDelta.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/full/PDOMFullHandleDelta.java index 3d150a9e531..812007fa9a8 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/full/PDOMFullHandleDelta.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/full/PDOMFullHandleDelta.java @@ -71,7 +71,13 @@ class PDOMFullHandleDelta extends PDOMFullIndexerJob { } } - parseTUs(sources, headers, monitor); + index.acquireReadLock(); + try { + parseTUs(sources, headers, monitor); + } + finally { + index.releaseReadLock(); + } } catch (CoreException e) { CCorePlugin.log(e); } catch (InterruptedException e) { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/full/PDOMFullIndexerJob.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/full/PDOMFullIndexerJob.java index fa3f45b6bc0..d3ec46a2db0 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/full/PDOMFullIndexerJob.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/full/PDOMFullIndexerJob.java @@ -19,7 +19,6 @@ import java.util.Map; import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.dom.IPDOMIndexer; -import org.eclipse.cdt.core.dom.IPDOMIndexerTask; import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit; import org.eclipse.cdt.core.index.IIndexFile; import org.eclipse.cdt.core.index.IIndexFileLocation; @@ -95,7 +94,7 @@ abstract class PDOMFullIndexerJob extends PDOMIndexerTask { } protected int getReadlockCount() { - return 0; + return 1; } protected boolean needToUpdate(IIndexFileLocation location) throws CoreException { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/full/PDOMFullReindex.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/full/PDOMFullReindex.java index 8fcd4e1817b..19ca583cdbd 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/full/PDOMFullReindex.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/full/PDOMFullReindex.java @@ -48,7 +48,13 @@ class PDOMFullReindex extends PDOMFullIndexerJob { } registerTUsInReaderFactory(sources); - parseTUs(sources, headers, monitor); + index.acquireReadLock(); + try { + parseTUs(sources, headers, monitor); + } + finally { + index.releaseReadLock(); + } } catch (CoreException e) { if (e.getStatus() != Status.CANCEL_STATUS) CCorePlugin.log(e);