From 5aa86e615473c66a5589cdca4548c789f22bf99f Mon Sep 17 00:00:00 2001 From: Nicolay Mitropolsky Date: Tue, 21 Feb 2023 16:19:46 +0100 Subject: [PATCH] IJ-CR-100779: `ReadActionCacheIml` decoupled from the `ReadMostlyRWLock` GitOrigin-RevId: 6957026b3c35f552d3e01f7608df1f2d4af4784f --- .../core-impl/resources/META-INF/CoreImpl.xml | 2 - .../application/impl/ApplicationImpl.java | 9 +++++ .../application/impl/ReadActionCacheIml.kt | 38 ++++++++++++++----- .../application/impl/ReadMostlyRWLock.java | 35 +---------------- 4 files changed, 39 insertions(+), 45 deletions(-) diff --git a/platform/core-impl/resources/META-INF/CoreImpl.xml b/platform/core-impl/resources/META-INF/CoreImpl.xml index ac33829eb073..d11d7f0cb5d5 100644 --- a/platform/core-impl/resources/META-INF/CoreImpl.xml +++ b/platform/core-impl/resources/META-INF/CoreImpl.xml @@ -57,8 +57,6 @@ - = ThreadLocal() override val processingContext: ProcessingContext? - get() = application?.myLock?.processingContext + get() { + threadProcessingContext.get()?.let { return it } + if (ApplicationManager.getApplication().isWriteIntentLockAcquired) return writeActionProcessingContext + if (!ApplicationManager.getApplication().isReadAccessAllowed) return null + threadProcessingContext.set(ProcessingContext()) + return threadProcessingContext.get() + } + + fun clear() { + threadProcessingContext.remove() + } + + + private var writeActionProcessingContext: ProcessingContext? = null override fun allowInWriteAction(supplier: () -> T): T { - val myLock = application?.myLock ?: return supplier.invoke() - return myLock.allowProcessingContextInWriteAction(supplier) + return if (!ApplicationManager.getApplication().isWriteIntentLockAcquired || writeActionProcessingContext != null) { + supplier.invoke() + } + else try { + writeActionProcessingContext = ProcessingContext() + supplier.invoke() + } + finally { + writeActionProcessingContext = null + } } - + override fun allowInWriteAction(runnable: Runnable) { - allowInWriteAction { runnable.run() } + allowInWriteAction { runnable.run() } } } \ No newline at end of file diff --git a/platform/platform-impl/src/com/intellij/openapi/application/impl/ReadMostlyRWLock.java b/platform/platform-impl/src/com/intellij/openapi/application/impl/ReadMostlyRWLock.java index 07a51b4226f2..f091d92955ff 100644 --- a/platform/platform-impl/src/com/intellij/openapi/application/impl/ReadMostlyRWLock.java +++ b/platform/platform-impl/src/com/intellij/openapi/application/impl/ReadMostlyRWLock.java @@ -6,7 +6,6 @@ import com.intellij.openapi.progress.ProcessCanceledException; import com.intellij.openapi.progress.ProgressIndicator; import com.intellij.openapi.progress.ProgressIndicatorProvider; import com.intellij.openapi.progress.ProgressManager; -import com.intellij.util.ProcessingContext; import com.intellij.util.containers.ConcurrentList; import com.intellij.util.containers.ContainerUtil; import org.intellij.lang.annotations.MagicConstant; @@ -18,7 +17,6 @@ import java.util.ArrayList; import java.util.List; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.locks.LockSupport; -import java.util.function.Supplier; import static com.intellij.openapi.progress.util.ProgressIndicatorUtils.cancelActionsToBeCancelledBeforeWrite; @@ -72,8 +70,6 @@ final class ReadMostlyRWLock { thread = readerThread; } - private ProcessingContext processingContext; - @Override @NonNls public String toString() { @@ -149,10 +145,8 @@ final class ReadMostlyRWLock { // If implicit read lock is disabled, don't check for write thread, check for true read lock if (allowImplicitRead) checkReadThreadAccess(); - if (status != null) { + if (status != null) status.readRequested = false; - status.processingContext = null; - } if (isWriteRequested()) { LockSupport.unpark(writeThread); // parked by writeLock() } @@ -185,33 +179,6 @@ final class ReadMostlyRWLock { return R.get().impatientReads; } - - ProcessingContext getProcessingContext() { - if (Thread.currentThread() == writeThread) return writeActionProcessingContext; - Reader reader = R.get(); - if (!reader.readRequested) return null; - ProcessingContext context = reader.processingContext; - if (context == null) { - context = reader.processingContext = new ProcessingContext(); - } - return context; - } - - private ProcessingContext writeActionProcessingContext = null; - - T allowProcessingContextInWriteAction(Supplier supplier) { - if (Thread.currentThread() != writeThread || writeActionProcessingContext != null) { - return supplier.get(); - } - try { - writeActionProcessingContext = new ProcessingContext(); - return supplier.get(); - } - finally { - writeActionProcessingContext = null; - } - } - /** * Executes a {@code runnable} in an "impatient" mode. * In this mode any attempt to grab read lock