mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-23 08:55:25 +02:00
Adds some of the missing locks when using the index.
This commit is contained in:
parent
6279316f60
commit
7ed3390565
9 changed files with 123 additions and 97 deletions
|
@ -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);
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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());
|
||||
}
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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() {
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Add table
Reference in a new issue