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:
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,8 +93,10 @@ 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);
|
||||
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());
|
||||
|
@ -140,4 +142,8 @@ public class IndexLocationTest extends BaseTestCase {
|
|||
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,6 +37,8 @@ class PDOMFastHandleDelta extends PDOMFastIndexerJob {
|
|||
long start = System.currentTimeMillis();
|
||||
try {
|
||||
setupIndexAndReaderFactory();
|
||||
index.acquireReadLock();
|
||||
try {
|
||||
registerTUsInReaderFactory(changed);
|
||||
|
||||
Iterator i= removed.iterator();
|
||||
|
@ -69,6 +71,10 @@ class PDOMFastHandleDelta extends PDOMFastIndexerJob {
|
|||
if (monitor.isCanceled()) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
finally {
|
||||
index.releaseReadLock();
|
||||
}
|
||||
} 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,8 +100,6 @@ 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()) {
|
||||
|
@ -114,10 +111,6 @@ abstract class PDOMFastIndexerJob extends PDOMIndexerTask {
|
|||
// Add the new symbols
|
||||
addSymbols(ast, pm);
|
||||
}
|
||||
finally {
|
||||
index.releaseReadLock();
|
||||
}
|
||||
}
|
||||
|
||||
protected IWritableIndex getIndex() {
|
||||
return index;
|
||||
|
|
|
@ -44,9 +44,15 @@ class PDOMFastReindex extends PDOMFastIndexerJob {
|
|||
return;
|
||||
}
|
||||
|
||||
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 {
|
|||
}
|
||||
}
|
||||
|
||||
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);
|
||||
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