From 3d65ac2dc8601b1146c4b7b2e9c7993b8c5c6a70 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D0=BB=D0=B5=D0=BA=D1=81=D0=B0=D0=BD=D0=B4=D1=8A?= =?UTF-8?q?=D1=80=20=D0=9A=D1=83=D1=80=D1=82=D0=B0=D0=BA=D0=BE=D0=B2?= Date: Wed, 1 Apr 2026 11:02:52 +0300 Subject: [PATCH] Use timer unconditionally in BusyIndicator.showWhile(Future) Should prevent hangs like https://github.com/eclipse-platform/eclipse.platform.swt/issues/3044 --- .../org/eclipse/swt/custom/BusyIndicator.java | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/BusyIndicator.java b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/BusyIndicator.java index eb143853535..0f50ce5e960 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/BusyIndicator.java +++ b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/BusyIndicator.java @@ -106,6 +106,19 @@ public static void showWhile(Future future) { } else { Integer busyId = setBusyCursor(display); try { + // Install a timer as a safety net to periodically wake the event loop in case + // the primary wake signal is lost (e.g. due to a native call may fail to wake the polling function). + // That should be short enough to not be noticeable by the user and long + // enough to not burn more CPU time than necessary + int wakeTime = 10; + display.timerExec(wakeTime, new Runnable() { + @Override + public void run() { + if (!future.isDone() && !display.isDisposed()) { + display.timerExec(wakeTime, this); + } + } + }); if (future instanceof CompletionStage stage) { // let us wake up from sleep once the future is done stage.handle((nil1, nil2) -> { @@ -119,19 +132,6 @@ public static void showWhile(Future future) { } return null; }); - } else { - // for plain features we need to use a workaround, we install a timer every - // few ms, that should be short enough to not be noticeable by the user and long - // enough to not burn more CPU time than necessary - int wakeTime = 10; - display.timerExec(wakeTime, new Runnable() { - @Override - public void run() { - if (!future.isDone() && !display.isDisposed()) { - display.timerExec(wakeTime, this); - } - } - }); } while (!future.isDone() && !display.isDisposed()) { if (!display.readAndDispatch()) {