From 2a3a9d6b4badabd29ed359cbb98be7027e281c66 Mon Sep 17 00:00:00 2001 From: Sergey Prigogin Date: Tue, 4 Oct 2016 14:55:40 -0700 Subject: [PATCH] Bug 503988 - UI thread got blocked by the reconciler Change-Id: I176d9fd132291630aed3aeefb4a6279048c13d14 --- .../cdt/internal/core/model/ASTCache.java | 8 +++++++- .../core/dom/parser/ASTTranslationUnit.java | 18 ++++++++++++++++-- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/ASTCache.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/ASTCache.java index 28896549900..ed895111809 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/ASTCache.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/ASTCache.java @@ -252,7 +252,13 @@ public class ASTCache { IASTTranslationUnit ast= getAST(tUnit, index, wait, progressMonitor); if (ast != null) { try { - ((ASTTranslationUnit) ast).beginExclusiveAccess(); + if (wait) { + ((ASTTranslationUnit) ast).beginExclusiveAccess(); + } else { + if (!((ASTTranslationUnit) ast).tryBeginExclusiveAccess(0)) { + return null; + } + } } catch (InterruptedException e) { throw new OperationCanceledException(); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTTranslationUnit.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTTranslationUnit.java index 01cef0af768..24f88372e94 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTTranslationUnit.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTTranslationUnit.java @@ -15,6 +15,7 @@ package org.eclipse.cdt.internal.core.dom.parser; import java.util.Arrays; import java.util.List; import java.util.concurrent.Semaphore; +import java.util.concurrent.TimeUnit; import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.dom.IName; @@ -493,13 +494,26 @@ public abstract class ASTTranslationUnit extends ASTNode implements IASTTranslat } /** - * Starts exclusive access - * @throws InterruptedException + * Starts exclusive access. + * + * @throws InterruptedException if the current thread is interrupted */ public void beginExclusiveAccess() throws InterruptedException { fSemaphore.acquire(); } + /** + * Starts exclusive access. + * + * @param timeoutMillis the maximum time to wait in milliseconds + * @return {@code true} if exclusive access was acquired, or {@code false} if it + * was not possible to acquire exclusive access before the timeout expired + * @throws InterruptedException if the current thread is interrupted + */ + public boolean tryBeginExclusiveAccess(long timeoutMillis) throws InterruptedException { + return fSemaphore.tryAcquire(timeoutMillis, TimeUnit.MILLISECONDS); + } + public void endExclusiveAccess() { fSemaphore.release(); }