From 9f3ca33757f556d03d2cc9418df307ada80662d8 Mon Sep 17 00:00:00 2001 From: Alexey Kudravtsev Date: Fri, 27 Jan 2012 13:14:12 +0400 Subject: [PATCH] optimisation: do not start background thread if there is no contention --- .../application/impl/ApplicationImpl.java | 39 ++++++++++--------- 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/platform/platform-impl/src/com/intellij/openapi/application/impl/ApplicationImpl.java b/platform/platform-impl/src/com/intellij/openapi/application/impl/ApplicationImpl.java index 88e5bf57d91c..b88935f46efc 100644 --- a/platform/platform-impl/src/com/intellij/openapi/application/impl/ApplicationImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/application/impl/ApplicationImpl.java @@ -1118,28 +1118,29 @@ public class ApplicationImpl extends ComponentManagerImpl implements Application fireBeforeWriteActionStart(_clazz); final AtomicBoolean stopped = new AtomicBoolean(false); - if (ourDumpThreadsOnLongWriteActionWaiting > 0) { - executeOnPooledThread(new Runnable() { - @Override - public void run() { - while (!stopped.get()) { - try { - Thread.sleep(ourDumpThreadsOnLongWriteActionWaiting); - if (!stopped.get()) { - PerformanceWatcher.getInstance().dumpThreads(true); - } - } - catch (InterruptedException ignored) { - } - } - } - }); - } - LOG.assertTrue(myActionsLock.isWriteLockAcquired(Thread.currentThread()) || !Thread.holdsLock(PsiLock.LOCK), "Thread must not hold PsiLock while performing writeAction"); try { - myActionsLock.writeLock().acquire(); + if (!myActionsLock.writeLock().attempt(0)) { + if (ourDumpThreadsOnLongWriteActionWaiting > 0) { + executeOnPooledThread(new Runnable() { + @Override + public void run() { + while (!stopped.get()) { + try { + Thread.sleep(ourDumpThreadsOnLongWriteActionWaiting); + if (!stopped.get()) { + PerformanceWatcher.getInstance().dumpThreads(true); + } + } + catch (InterruptedException ignored) { + } + } + } + }); + } + myActionsLock.writeLock().acquire(); + } acquired(); } catch (InterruptedException e) {