Skip to content

Commit d25bbee

Browse files
committed
Avoid BusyIndicator putting Display to sleep after being done
Due to a race condition between the BusyIndicator's event loop spinning and the display.wake() call performed after the future to wait for is done, the BusyIndicator execution may get stuck in a display.sleep() call. While on Windows and MacOS the wake() call will effectively still ensure that display.sleep() return immediately if invoked display.sleep() was called, this is neither guaranteed nor does that happen on Linux. This fixes the race condition by replacing the wake() call in the future with scheduling an empty task that ensures that the event queue remains spinned (like everywhere else). Contributes to #3044
1 parent a589ee9 commit d25bbee

1 file changed

Lines changed: 8 additions & 3 deletions

File tree

  • bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom

bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/BusyIndicator.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,10 +111,15 @@ public static void showWhile(Future<?> future) {
111111
stage.handle((nil1, nil2) -> {
112112
if (!display.isDisposed()) {
113113
try {
114-
display.wake();
114+
// Use asyncExec() to wake up the display thread instead of wake()
115+
// as this call may happen between the future.isDone() check and the
116+
// display.sleep() call such that a wake() may get lost whereas an asyncExec()
117+
// will wake up the sleep() even if it is scheduled before calling sleep()
118+
display.asyncExec(() -> {
119+
});
115120
} catch (SWTException e) {
116-
// ignore then, this can happen due to the async nature between our check for
117-
// disposed and the actual call to wake the display can be disposed
121+
// ignore; due to the async nature between our disposed check and scheduling
122+
// asyncExec(), the display may already be disposed
118123
}
119124
}
120125
return null;

0 commit comments

Comments
 (0)