1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-08-08 16:55:38 +02:00

Add missing locks when accessing PDOM.

This commit is contained in:
Markus Schorn 2006-09-06 13:48:22 +00:00
parent 683950da14
commit f687cd8f7a
2 changed files with 45 additions and 24 deletions

View file

@ -22,6 +22,8 @@ import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IWorkbenchPage; import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.IWorkbenchWindow; import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.dom.IPDOM;
import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit; import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
import org.eclipse.cdt.core.model.CoreModel; import org.eclipse.cdt.core.model.CoreModel;
@ -130,6 +132,15 @@ public class CallHierarchyUI {
private static ICElement[] findDefinitions(ICProject project, IEditorInput editorInput, ITextSelection sel) throws CoreException { private static ICElement[] findDefinitions(ICProject project, IEditorInput editorInput, ITextSelection sel) throws CoreException {
CIndexQueries index= CIndexQueries.getInstance(); CIndexQueries index= CIndexQueries.getInstance();
IPDOM pdom= CCorePlugin.getPDOMManager().getPDOM(project);
if (pdom != null) {
try {
pdom.acquireReadLock();
} catch (InterruptedException e) {
return null;
}
}
try {
IASTName name= getSelectedName(editorInput, sel); IASTName name= getSelectedName(editorInput, sel);
if (name != null) { if (name != null) {
if (name.isDefinition()) { if (name.isDefinition()) {
@ -156,6 +167,12 @@ public class CallHierarchyUI {
return elems; return elems;
} }
} }
}
finally {
if (pdom != null) {
pdom.releaseReadLock();
}
}
return null; return null;
} }
@ -168,7 +185,7 @@ public class CallHierarchyUI {
if (workingCopy == null) if (workingCopy == null)
return null; return null;
int options= ILanguage.AST_SKIP_ALL_HEADERS | ILanguage.AST_USE_INDEX; int options= ILanguage.AST_SKIP_INDEXED_HEADERS | ILanguage.AST_USE_INDEX;
IASTTranslationUnit ast = workingCopy.getLanguage().getASTTranslationUnit(workingCopy, options); IASTTranslationUnit ast = workingCopy.getLanguage().getASTTranslationUnit(workingCopy, options);
FindNameForSelectionVisitor finder= new FindNameForSelectionVisitor(ast.getFilePath(), selectionStart, selectionLength); FindNameForSelectionVisitor finder= new FindNameForSelectionVisitor(ast.getFilePath(), selectionStart, selectionLength);
ast.accept(finder); ast.accept(finder);

View file

@ -55,7 +55,7 @@ import org.eclipse.cdt.internal.corext.util.CModelUtil;
* @since 4.0 * @since 4.0
*/ */
public class CIndexQueries { public class CIndexQueries {
private static final int ASTTU_OPTIONS = ILanguage.AST_SKIP_ALL_HEADERS | ILanguage.AST_USE_INDEX; private static final int ASTTU_OPTIONS = ILanguage.AST_SKIP_INDEXED_HEADERS | ILanguage.AST_USE_INDEX;
private static final ICElement[] EMPTY_ELEMENTS = new ICElement[0]; private static final ICElement[] EMPTY_ELEMENTS = new ICElement[0];
private static final CIndexIncludeRelation[] EMPTY_INCLUDES = new CIndexIncludeRelation[0]; private static final CIndexIncludeRelation[] EMPTY_INCLUDES = new CIndexIncludeRelation[0];
private static final CIndexQueries sInstance= new CIndexQueries(); private static final CIndexQueries sInstance= new CIndexQueries();
@ -231,6 +231,10 @@ public class CIndexQueries {
return; return;
} }
IASTName name= names[names.length-1]; IASTName name= names[names.length-1];
IASTName[] a= ast.getReferences(name.resolveBinding());
if (a.length > 0) {
a[0]= null;
}
for (int i = 0; i < scope.length; i++) { for (int i = 0; i < scope.length; i++) {
ICProject project = scope[i]; ICProject project = scope[i];
findCalledBy(name, project, result); findCalledBy(name, project, result);