1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

Fix for 233976: Deadlock in ASTProvider

This commit is contained in:
Anton Leherbauer 2008-05-27 08:40:07 +00:00
parent 12cc9fcc6a
commit 9fd60a6db8

View file

@ -10,7 +10,6 @@
* Anton Leherbauer (Wind River Systems) - Adapted for CDT
* Markus Schorn (Wind River Systems)
*******************************************************************************/
package org.eclipse.cdt.internal.ui.editor;
import org.eclipse.core.runtime.Assert;
@ -19,6 +18,7 @@ import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.IDocumentExtension4;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IPartListener2;
import org.eclipse.ui.IWindowListener;
import org.eclipse.ui.IWorkbenchPart;
@ -283,20 +283,35 @@ public final class ASTProvider {
return;
Assert.isTrue(cElement instanceof ITranslationUnit);
fCache.aboutToBeReconciled((ITranslationUnit)cElement);
fTimeStamp= getCurrentModificationStamp();
updateModificationStamp();
}
private synchronized long getCurrentModificationStamp() {
private boolean updateModificationStamp() {
long timeStamp= IDocumentExtension4.UNKNOWN_MODIFICATION_STAMP;
ITextEditor textEditor= null;
synchronized (this) {
if (fActiveEditor instanceof ITextEditor) {
ITextEditor textEditor= (ITextEditor) fActiveEditor;
IDocument document= textEditor.getDocumentProvider().getDocument(textEditor.getEditorInput());
textEditor= (ITextEditor) fActiveEditor;
timeStamp= fTimeStamp;
}
}
if (textEditor != null) {
IEditorInput editorInput= textEditor.getEditorInput();
IDocument document= textEditor.getDocumentProvider().getDocument(editorInput);
if (document instanceof IDocumentExtension4) {
IDocumentExtension4 docExt= (IDocumentExtension4) document;
timeStamp= docExt.getModificationStamp();
long newTimeStamp= docExt.getModificationStamp();
if (newTimeStamp != timeStamp) {
synchronized (this) {
if (fActiveEditor == textEditor && fTimeStamp == timeStamp) {
fTimeStamp= newTimeStamp;
return true;
}
}
return timeStamp;
}
}
}
return false;
}
/**
@ -328,10 +343,8 @@ public final class ASTProvider {
if (waitFlag == WAIT_ACTIVE_ONLY && !isActive) {
return Status.CANCEL_STATUS;
}
long currentStamp= getCurrentModificationStamp();
if (isActive && fTimeStamp != currentStamp) {
if (isActive && updateModificationStamp()) {
fCache.disposeAST();
fTimeStamp= currentStamp;
}
return fCache.runOnAST((ITranslationUnit)cElement, waitFlag != WAIT_NO, monitor, astRunnable);
}