1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-08-10 09:45:39 +02:00

Adds some of the missing locks when using the index.

This commit is contained in:
Markus Schorn 2007-02-05 10:06:32 +00:00
parent 6279316f60
commit 7ed3390565
9 changed files with 123 additions and 97 deletions

View file

@ -382,6 +382,7 @@ public class IndexBugsTests extends BaseTestCase {
header.setContents(in, IResource.FORCE, null); header.setContents(in, IResource.FORCE, null);
TestSourceReader.waitUntilFileIsIndexed(index, header, INDEX_WAIT_TIME); TestSourceReader.waitUntilFileIsIndexed(index, header, INDEX_WAIT_TIME);
index.acquireReadLock();
try { try {
IBinding[] bindings = index.findBindings(Pattern.compile("var"), true, IndexFilter.ALL, new NullProgressMonitor()); IBinding[] bindings = index.findBindings(Pattern.compile("var"), true, IndexFilter.ALL, new NullProgressMonitor());
assertEquals(1, bindings.length); assertEquals(1, bindings.length);

View file

@ -93,51 +93,57 @@ public class IndexLocationTest extends BaseTestCase {
// #include "header.h" // #include "header.h"
// #include "ABS_EXTERNAL" // #include "ABS_EXTERNAL"
// class baz {}; // class baz {};
public void testBasicLocations() throws CoreException, ExecutionException { public void testBasicLocations() throws CoreException, ExecutionException, InterruptedException {
IIndex index = CCorePlugin.getIndexManager().getIndex(cproject); IIndex index = CCorePlugin.getIndexManager().getIndex(cproject);
IBinding[] bs1 = index.findBindings(Pattern.compile("foo"), true, IndexFilter.ALL, new NullProgressMonitor()); index.acquireReadLock();
IBinding[] bs2 = index.findBindings(Pattern.compile("bar"), true, IndexFilter.ALL, new NullProgressMonitor()); try {
IBinding[] bs3 = index.findBindings(Pattern.compile("baz"), true, IndexFilter.ALL, new NullProgressMonitor()); IBinding[] bs1 = index.findBindings(Pattern.compile("foo"), true, IndexFilter.ALL, new NullProgressMonitor());
assertEquals(1, bs1.length); IBinding[] bs2 = index.findBindings(Pattern.compile("bar"), true, IndexFilter.ALL, new NullProgressMonitor());
assertEquals(1, bs2.length); IBinding[] bs3 = index.findBindings(Pattern.compile("baz"), true, IndexFilter.ALL, new NullProgressMonitor());
assertEquals(1, bs3.length); assertEquals(1, bs1.length);
bs1 = index.findBindings("foo".toCharArray(), IndexFilter.ALL, new NullProgressMonitor()); assertEquals(1, bs2.length);
bs2 = index.findBindings("bar".toCharArray(), IndexFilter.ALL, new NullProgressMonitor()); assertEquals(1, bs3.length);
bs3 = index.findBindings("baz".toCharArray(), IndexFilter.ALL, new NullProgressMonitor()); bs1 = index.findBindings("foo".toCharArray(), IndexFilter.ALL, new NullProgressMonitor());
assertEquals(1, bs1.length); bs2 = index.findBindings("bar".toCharArray(), IndexFilter.ALL, new NullProgressMonitor());
assertEquals(1, bs2.length); bs3 = index.findBindings("baz".toCharArray(), IndexFilter.ALL, new NullProgressMonitor());
assertEquals(1, bs3.length); assertEquals(1, bs1.length);
IIndexName[] nms1 = index.findNames(bs1[0], IIndex.FIND_ALL_OCCURENCES); assertEquals(1, bs2.length);
IIndexName[] nms2 = index.findNames(bs2[0], IIndex.FIND_ALL_OCCURENCES); assertEquals(1, bs3.length);
IIndexName[] nms3 = index.findNames(bs3[0], IIndex.FIND_ALL_OCCURENCES); IIndexName[] nms1 = index.findNames(bs1[0], IIndex.FIND_ALL_OCCURENCES);
assertEquals(1, nms1.length); IIndexName[] nms2 = index.findNames(bs2[0], IIndex.FIND_ALL_OCCURENCES);
assertEquals(1, nms2.length); IIndexName[] nms3 = index.findNames(bs3[0], IIndex.FIND_ALL_OCCURENCES);
assertEquals(1, nms3.length); assertEquals(1, nms1.length);
URI workspaceRoot = ResourcesPlugin.getWorkspace().getRoot().getLocationURI(); assertEquals(1, nms2.length);
assertEquals( assertEquals(1, nms3.length);
ResourcesPlugin.getWorkspace().getRoot().getFile(new Path("LocationTests/header.h")).getLocationURI(), URI workspaceRoot = ResourcesPlugin.getWorkspace().getRoot().getLocationURI();
nms1[0].getFile().getLocation().getURI() assertEquals(
); ResourcesPlugin.getWorkspace().getRoot().getFile(new Path("LocationTests/header.h")).getLocationURI(),
assertEquals( nms1[0].getFile().getLocation().getURI()
externalHeader.toURI(), );
nms2[0].getFile().getLocation().getURI() assertEquals(
); externalHeader.toURI(),
assertEquals( nms2[0].getFile().getLocation().getURI()
ResourcesPlugin.getWorkspace().getRoot().getFile(new Path("LocationTests/source.cpp")).getLocationURI(), );
nms3[0].getFile().getLocation().getURI() assertEquals(
); ResourcesPlugin.getWorkspace().getRoot().getFile(new Path("LocationTests/source.cpp")).getLocationURI(),
nms3[0].getFile().getLocation().getURI()
);
assertEquals( assertEquals(
ResourcesPlugin.getWorkspace().getRoot().getFile(new Path("LocationTests/header.h")).getFullPath(), ResourcesPlugin.getWorkspace().getRoot().getFile(new Path("LocationTests/header.h")).getFullPath(),
new Path(nms1[0].getFile().getLocation().getFullPath()) new Path(nms1[0].getFile().getLocation().getFullPath())
); );
assertEquals( assertEquals(
null, null,
nms2[0].getFile().getLocation().getFullPath() nms2[0].getFile().getLocation().getFullPath()
); );
assertEquals( assertEquals(
ResourcesPlugin.getWorkspace().getRoot().getFile(new Path("LocationTests/source.cpp")).getFullPath(), ResourcesPlugin.getWorkspace().getRoot().getFile(new Path("LocationTests/source.cpp")).getFullPath(),
new Path(nms3[0].getFile().getLocation().getFullPath()) new Path(nms3[0].getFile().getLocation().getFullPath())
); );
}
finally {
index.releaseReadLock();
}
} }
} }

View file

@ -67,11 +67,14 @@ public abstract class IndexBindingResolutionTestBase extends PDOMTestBase {
assertTrue(CCorePlugin.getIndexManager().joinIndexer(360000, new NullProgressMonitor())); assertTrue(CCorePlugin.getIndexManager().joinIndexer(360000, new NullProgressMonitor()));
index= CCorePlugin.getIndexManager().getIndex(cproject); index= CCorePlugin.getIndexManager().getIndex(cproject);
index.acquireReadLock();
ast = TestSourceReader.createIndexBasedAST(index, cproject, cppfile); ast = TestSourceReader.createIndexBasedAST(index, cproject, cppfile);
} }
protected void tearDown() throws Exception { protected void tearDown() throws Exception {
if (index != null) {
index.releaseReadLock();
}
if (cproject != null) { if (cproject != null) {
cproject.getProject().delete(IResource.FORCE | IResource.ALWAYS_DELETE_PROJECT_CONTENT, new NullProgressMonitor()); cproject.getProject().delete(IResource.FORCE | IResource.ALWAYS_DELETE_PROJECT_CONTENT, new NullProgressMonitor());
} }

View file

@ -37,38 +37,44 @@ class PDOMFastHandleDelta extends PDOMFastIndexerJob {
long start = System.currentTimeMillis(); long start = System.currentTimeMillis();
try { try {
setupIndexAndReaderFactory(); setupIndexAndReaderFactory();
registerTUsInReaderFactory(changed); index.acquireReadLock();
try {
Iterator i= removed.iterator(); registerTUsInReaderFactory(changed);
while (i.hasNext()) {
if (monitor.isCanceled())
return;
ITranslationUnit tu = (ITranslationUnit)i.next();
removeTU(index, tu);
if (tu.isSourceUnit()) {
fCompletedSources++;
}
else {
fTotalSourcesEstimate--;
fCompletedHeaders++;
}
}
// separate headers Iterator i= removed.iterator();
List headers= new ArrayList(); while (i.hasNext()) {
List sources= changed; if (monitor.isCanceled())
for (Iterator iter = changed.iterator(); iter.hasNext();) { return;
ITranslationUnit tu = (ITranslationUnit) iter.next(); ITranslationUnit tu = (ITranslationUnit)i.next();
if (!tu.isSourceUnit()) { removeTU(index, tu);
headers.add(tu); if (tu.isSourceUnit()) {
iter.remove(); 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) { } catch (CoreException e) {
CCorePlugin.log(e); CCorePlugin.log(e);
} catch (InterruptedException e) { } catch (InterruptedException e) {

View file

@ -20,7 +20,6 @@ import java.util.Map;
import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.dom.IPDOMIndexer; 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.dom.ast.IASTTranslationUnit;
import org.eclipse.cdt.core.index.IIndexFile; import org.eclipse.cdt.core.index.IIndexFile;
import org.eclipse.cdt.core.index.IIndexFileLocation; import org.eclipse.cdt.core.index.IIndexFileLocation;
@ -101,22 +100,16 @@ abstract class PDOMFastIndexerJob extends PDOMIndexerTask {
return; return;
} }
index.acquireReadLock(); // get the AST in a "Fast" way
try { IASTTranslationUnit ast= language.getASTTranslationUnit(codeReader, scanner, codeReaderFactory, index, ParserUtil.getParserLogService());
// get the AST in a "Fast" way if (pm.isCanceled()) {
IASTTranslationUnit ast= language.getASTTranslationUnit(codeReader, scanner, codeReaderFactory, index, ParserUtil.getParserLogService()); return;
if (pm.isCanceled()) {
return;
}
// Clear the macros
codeReaderFactory.clearMacroAttachements();
// Add the new symbols
addSymbols(ast, pm);
}
finally {
index.releaseReadLock();
} }
// Clear the macros
codeReaderFactory.clearMacroAttachements();
// Add the new symbols
addSymbols(ast, pm);
} }
protected IWritableIndex getIndex() { protected IWritableIndex getIndex() {

View file

@ -44,9 +44,15 @@ class PDOMFastReindex extends PDOMFastIndexerJob {
return; return;
} }
registerTUsInReaderFactory(sources); index.acquireReadLock();
registerTUsInReaderFactory(headers); try {
parseTUs(sources, headers, monitor); registerTUsInReaderFactory(sources);
registerTUsInReaderFactory(headers);
parseTUs(sources, headers, monitor);
}
finally {
index.releaseReadLock();
}
} catch (CoreException e) { } catch (CoreException e) {
CCorePlugin.log(e); CCorePlugin.log(e);

View file

@ -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) { } catch (CoreException e) {
CCorePlugin.log(e); CCorePlugin.log(e);
} catch (InterruptedException e) { } catch (InterruptedException e) {

View file

@ -19,7 +19,6 @@ import java.util.Map;
import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.dom.IPDOMIndexer; 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.dom.ast.IASTTranslationUnit;
import org.eclipse.cdt.core.index.IIndexFile; import org.eclipse.cdt.core.index.IIndexFile;
import org.eclipse.cdt.core.index.IIndexFileLocation; import org.eclipse.cdt.core.index.IIndexFileLocation;
@ -95,7 +94,7 @@ abstract class PDOMFullIndexerJob extends PDOMIndexerTask {
} }
protected int getReadlockCount() { protected int getReadlockCount() {
return 0; return 1;
} }
protected boolean needToUpdate(IIndexFileLocation location) throws CoreException { protected boolean needToUpdate(IIndexFileLocation location) throws CoreException {

View file

@ -48,7 +48,13 @@ class PDOMFullReindex extends PDOMFullIndexerJob {
} }
registerTUsInReaderFactory(sources); registerTUsInReaderFactory(sources);
parseTUs(sources, headers, monitor); index.acquireReadLock();
try {
parseTUs(sources, headers, monitor);
}
finally {
index.releaseReadLock();
}
} catch (CoreException e) { } catch (CoreException e) {
if (e.getStatus() != Status.CANCEL_STATUS) if (e.getStatus() != Status.CANCEL_STATUS)
CCorePlugin.log(e); CCorePlugin.log(e);