mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-08 02:06:01 +02:00
Bug 379317 - This change coalesces runnables into one.
This improves perceived performance as repaints are not interleaved with updates. Change-Id: If9674e45adf1aa5b4d8530e22dfcd494d228f329 Reviewed-on: https://git.eclipse.org/r/5956 Reviewed-by: Pawel Piech <pawel.piech@windriver.com> IP-Clean: Pawel Piech <pawel.piech@windriver.com> Tested-by: Pawel Piech <pawel.piech@windriver.com>
This commit is contained in:
parent
d5cb9f4f8f
commit
03d1253f68
1 changed files with 61 additions and 19 deletions
|
@ -7,12 +7,15 @@
|
||||||
*
|
*
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* Wind River Systems - initial API and implementation
|
* Wind River Systems - initial API and implementation
|
||||||
|
* NVIDIA - coalesce runnable in the single event loop iteration
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package org.eclipse.cdt.dsf.ui.concurrent;
|
package org.eclipse.cdt.dsf.ui.concurrent;
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.LinkedList;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Queue;
|
||||||
import java.util.concurrent.Executor;
|
import java.util.concurrent.Executor;
|
||||||
import java.util.concurrent.RejectedExecutionException;
|
import java.util.concurrent.RejectedExecutionException;
|
||||||
|
|
||||||
|
@ -42,7 +45,7 @@ public class SimpleDisplayExecutor implements Executor{
|
||||||
* @param display Display to create an executor for.
|
* @param display Display to create an executor for.
|
||||||
* @return The new (or re-used) executor.
|
* @return The new (or re-used) executor.
|
||||||
*/
|
*/
|
||||||
public static SimpleDisplayExecutor getSimpleDisplayExecutor(Display display) {
|
public static SimpleDisplayExecutor getSimpleDisplayExecutor(final Display display) {
|
||||||
synchronized (fExecutors) {
|
synchronized (fExecutors) {
|
||||||
SimpleDisplayExecutor executor = fExecutors.get(display);
|
SimpleDisplayExecutor executor = fExecutors.get(display);
|
||||||
if (executor == null) {
|
if (executor == null) {
|
||||||
|
@ -57,16 +60,27 @@ public class SimpleDisplayExecutor implements Executor{
|
||||||
* The display class used by this executor to execute the submitted runnables.
|
* The display class used by this executor to execute the submitted runnables.
|
||||||
*/
|
*/
|
||||||
private final Display fDisplay;
|
private final Display fDisplay;
|
||||||
|
/**
|
||||||
|
* Runnables waiting for the UI loop iteration
|
||||||
|
*/
|
||||||
|
private Queue<Runnable> runnables;
|
||||||
|
|
||||||
private SimpleDisplayExecutor(Display display) {
|
private SimpleDisplayExecutor(final Display display) {
|
||||||
fDisplay = display;
|
fDisplay = display;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute(Runnable command) {
|
public void execute(final Runnable command) {
|
||||||
|
final boolean needsPosting = enqueue(command);
|
||||||
|
if (needsPosting) {
|
||||||
try {
|
try {
|
||||||
fDisplay.asyncExec(command);
|
fDisplay.asyncExec(new Runnable() {
|
||||||
} catch (SWTException e) {
|
@Override
|
||||||
|
public void run() {
|
||||||
|
runInSwtThread();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} catch (final SWTException e) {
|
||||||
if (e.code == SWT.ERROR_DEVICE_DISPOSED) {
|
if (e.code == SWT.ERROR_DEVICE_DISPOSED) {
|
||||||
throw new RejectedExecutionException("Display " + fDisplay + " is disposed", e); //$NON-NLS-1$ //$NON-NLS-2$
|
throw new RejectedExecutionException("Display " + fDisplay + " is disposed", e); //$NON-NLS-1$ //$NON-NLS-2$
|
||||||
} else {
|
} else {
|
||||||
|
@ -74,4 +88,32 @@ public class SimpleDisplayExecutor implements Executor{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private synchronized boolean enqueue(final Runnable runnable) {
|
||||||
|
boolean needsPosting = false;
|
||||||
|
if (runnables == null) {
|
||||||
|
runnables = new LinkedList<Runnable>();
|
||||||
|
needsPosting = true;
|
||||||
|
}
|
||||||
|
runnables.offer(runnable);
|
||||||
|
return needsPosting;
|
||||||
|
}
|
||||||
|
|
||||||
|
private synchronized Runnable getNextRunnable() {
|
||||||
|
final Runnable runnable = runnables.poll();
|
||||||
|
if (runnable == null) {
|
||||||
|
runnables = null;
|
||||||
|
return null;
|
||||||
|
} else {
|
||||||
|
return runnable;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void runInSwtThread() {
|
||||||
|
Runnable runnable;
|
||||||
|
while ((runnable = getNextRunnable()) != null) {
|
||||||
|
runnable.run();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue