From cff13bc18f2cec0e4e7a115b50344a8362697d9d Mon Sep 17 00:00:00 2001 From: "Artem.Bukhonov" Date: Tue, 20 Aug 2024 21:38:59 +0200 Subject: [PATCH] RDCT-1642 resetThreadContext() in FlushQueue.flushNow() GitOrigin-RevId: 3cfc25ea5390565f3b57e1944de37f15dff405a6 --- .../openapi/application/impl/FlushQueue.java | 33 +++++++++++-------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/platform/core-impl/src/com/intellij/openapi/application/impl/FlushQueue.java b/platform/core-impl/src/com/intellij/openapi/application/impl/FlushQueue.java index 413700966a22..626996315882 100644 --- a/platform/core-impl/src/com/intellij/openapi/application/impl/FlushQueue.java +++ b/platform/core-impl/src/com/intellij/openapi/application/impl/FlushQueue.java @@ -2,7 +2,9 @@ package com.intellij.openapi.application.impl; import com.intellij.concurrency.ContextAwareRunnable; +import com.intellij.concurrency.ThreadContext; import com.intellij.diagnostic.EventWatcher; +import com.intellij.openapi.application.AccessToken; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.application.ModalityState; import com.intellij.openapi.diagnostic.Logger; @@ -26,22 +28,25 @@ final class FlushQueue { private final BulkArrayQueue myQueue = new BulkArrayQueue<>(); //guarded by getQueueLock() private void flushNow() { - ThreadingAssertions.assertEventDispatchThread(); - synchronized (getQueueLock()) { - FLUSHER_SCHEDULED = false; - } - long startTime = System.currentTimeMillis(); - while (true) { - RunnableInfo info = pollNextEvent(); - if (info == null) { - break; + try (AccessToken ignored = ThreadContext.resetThreadContext()) { + ThreadingAssertions.assertEventDispatchThread(); + synchronized (getQueueLock()) { + FLUSHER_SCHEDULED = false; } - runNextEvent(info); - if (InvocationUtil.priorityEventPending() || System.currentTimeMillis() - startTime > 5) { - synchronized (getQueueLock()) { - requestFlush(); + + long startTime = System.currentTimeMillis(); + while (true) { + RunnableInfo info = pollNextEvent(); + if (info == null) { + break; + } + runNextEvent(info); + if (InvocationUtil.priorityEventPending() || System.currentTimeMillis() - startTime > 5) { + synchronized (getQueueLock()) { + requestFlush(); + } + break; } - break; } } }