Class InvokeSWTLater
Locking (CC-FIX-IIZIGO-EXIT-DEADLOCK). The instance monitor guards this instance's own fields and nothing else: no thread calls into SWT or into a callback while it holds it. Display.asyncExec, syncExec and getDefault take the lock of the Device class, and Device.dispose() holds that lock while it runs the Display's pending runnables and timers - this class's among them - in the SWT thread. A worker that posted while it held the instance monitor deadlocked iiziGo at its exit: the worker in asyncExec, waiting for the Device lock, and the SWT thread in a pending timer of the same instance, waiting for the monitor. A trigger made once the disposal of the Display has begun is dropped: it is not posted, and nothing waits for it.
- Author:
- Christopher Mindus
Constructor Summary
ConstructorsConstructorDescriptionConstructs an instance that fires the event immediately.InvokeSWTLater(int wait) Constructs an instance that fires the event after a while.InvokeSWTLater(int wait, boolean triggerCancelPending, Runnable callback) Constructs an instance that fires the event after a while.InvokeSWTLater(int wait, Runnable callback) Constructs an instance that fires the event after a while.Method Summary
Modifier and TypeMethodDescriptionbooleancancel()Cancels a pending run-later task.voiddispose()Disposes of the instance.static DisplayGets the display: the workbench's own, while the workbench runs and the disposal of its Display has not begun.booleanChecks if disposed of.booleanFlag indicating the async call has been done and that it will run.voidsetCallback(Runnable callback) Sets the callback, when it is the same one to use all the time.voidtrigger()Calls the trigger function, the Runnable is the one registered usingsetCallback(Runnable).voidCalls the trigger function, the Runnable is the one registered usingsetCallback(Runnable).
Constructor Details
InvokeSWTLater
public InvokeSWTLater()Constructs an instance that fires the event immediately.InvokeSWTLater
public InvokeSWTLater(int wait) Constructs an instance that fires the event after a while.- Parameters:
wait- How long to wait in milliseconds, (0=no wait).
InvokeSWTLater
Constructs an instance that fires the event after a while.- Parameters:
wait- How long to wait in milliseconds, (0=no wait).callback- The callback to use for all events in SWT.
InvokeSWTLater
Constructs an instance that fires the event after a while.- Parameters:
wait- How long to wait in milliseconds, (0=no wait).triggerCancelPending- Flag indicating trigger will cancel pending triggered event.callback- The callback to use for all events in SWT.
Method Details
getDisplay
Gets the display: the workbench's own, while the workbench runs and the disposal of its Display has not begun.Never
Display.getDefault(): once the workbench has ended and its Display is disposed,getDefault()CREATES a new Display on the calling thread, and on GTK that blocks forever ingdk_threads_enter(the GDK lock the first Display's thread holds). The stress run of r21335 hung the Designer test runtime that way on lx64 for 4.5 hours:SyncState.setStateon a Building worker, after the harness' Display was gone (CC-FIX-STRESS-R21335-REDS). The workbench running is not test enough that no Display is created: a workbench that ends withoutIWorkbench.close()- Tycho's UI harness - still answers "running" while its Display is disposed of and after it (measured: the thread dump of CC-FIX-IIZIGO-EXIT-DEADLOCK), andgetDefault()also takes the lock of theDeviceclass, whichDevice.dispose()holds. So the Display is the one the workbench was created with, which is read without a lock and never created here. Public for every caller that may run after the workbench ended; it may be called with a monitor held.- Returns:
- The display instance, or
nullif Eclipse is shutting down!
isDisposed
public boolean isDisposed()Checks if disposed of.dispose
public void dispose()Disposes of the instance.setCallback
Sets the callback, when it is the same one to use all the time.- Parameters:
callback- The callback to use for all events in SWT.- Throws:
NullPointerException- If the callback is null.
trigger
public void trigger()Calls the trigger function, the Runnable is the one registered usingsetCallback(Runnable).- Throws:
NullPointerException- If the callback is null.
trigger
Calls the trigger function, the Runnable is the one registered usingsetCallback(Runnable).A trigger made while the workbench is not running, or once the disposal of its Display has begun, is dropped (logged at FINE): nothing is posted and nothing waits for it.
- Parameters:
callback- The callback to notify upon event.- Throws:
NullPointerException- If the callback is null.
isTriggered
public boolean isTriggered()Flag indicating the async call has been done and that it will run.cancel
public boolean cancel()Cancels a pending run-later task.- Returns:
- true if successfully canceled, false if disposed of or no pending task was set to run.