mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
[231156] - [concurrency][view model] Improve performance of the executor used in View model.
This commit is contained in:
parent
b148191afa
commit
6b0a5f2fc8
3 changed files with 81 additions and 8 deletions
|
@ -0,0 +1,74 @@
|
||||||
|
/*******************************************************************************
|
||||||
|
* Copyright (c) 2008 Wind River Systems and others.
|
||||||
|
* All rights reserved. This program and the accompanying materials
|
||||||
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
|
* which accompanies this distribution, and is available at
|
||||||
|
* http://www.eclipse.org/legal/epl-v10.html
|
||||||
|
*
|
||||||
|
* Contributors:
|
||||||
|
* Wind River Systems - initial API and implementation
|
||||||
|
*******************************************************************************/
|
||||||
|
package org.eclipse.dd.dsf.ui.concurrent;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.concurrent.Executor;
|
||||||
|
import java.util.concurrent.RejectedExecutionException;
|
||||||
|
|
||||||
|
import org.eclipse.dd.dsf.concurrent.DsfExecutor;
|
||||||
|
import org.eclipse.swt.SWT;
|
||||||
|
import org.eclipse.swt.SWTException;
|
||||||
|
import org.eclipse.swt.widgets.Display;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A simple executor which uses the display thread to run the submitted
|
||||||
|
* runnables. It only implements the {@link Executor}, and NOT the more
|
||||||
|
* sophisticated {@link DsfExecutor} (which extends
|
||||||
|
* {@link java.util.concurrent.ScheduledExecutorService}). However, this
|
||||||
|
* implementation is much more efficient than DisplayDsfExecutor as it does
|
||||||
|
* not use a separate thread or maintain its own queue.
|
||||||
|
*/
|
||||||
|
public class SimpleDisplayExecutor implements Executor{
|
||||||
|
/**
|
||||||
|
* Internal mapping of display objects to executors.
|
||||||
|
*/
|
||||||
|
private static Map<Display, SimpleDisplayExecutor> fExecutors = Collections.synchronizedMap( new HashMap<Display, SimpleDisplayExecutor>() );
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Factory method for display executors.
|
||||||
|
* @param display Display to create an executor for.
|
||||||
|
* @return The new (or re-used) executor.
|
||||||
|
*/
|
||||||
|
public static SimpleDisplayExecutor getSimpleDisplayExecutor(Display display) {
|
||||||
|
synchronized (fExecutors) {
|
||||||
|
SimpleDisplayExecutor executor = fExecutors.get(display);
|
||||||
|
if (executor == null) {
|
||||||
|
executor = new SimpleDisplayExecutor(display);
|
||||||
|
fExecutors.put(display, executor);
|
||||||
|
}
|
||||||
|
return executor;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The display class used by this executor to execute the submitted runnables.
|
||||||
|
*/
|
||||||
|
private final Display fDisplay;
|
||||||
|
|
||||||
|
private SimpleDisplayExecutor(Display display) {
|
||||||
|
fDisplay = display;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void execute(Runnable command) {
|
||||||
|
try {
|
||||||
|
fDisplay.asyncExec(command);
|
||||||
|
} catch (SWTException e) {
|
||||||
|
if (e.code == SWT.ERROR_DEVICE_DISPOSED) {
|
||||||
|
throw new RejectedExecutionException("Display " + fDisplay + " is disposed", e); //$NON-NLS-1$ //$NON-NLS-2$
|
||||||
|
} else {
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -10,10 +10,11 @@
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package org.eclipse.dd.dsf.ui.viewmodel;
|
package org.eclipse.dd.dsf.ui.viewmodel;
|
||||||
|
|
||||||
|
import java.util.concurrent.Executor;
|
||||||
|
|
||||||
import org.eclipse.core.runtime.IStatus;
|
import org.eclipse.core.runtime.IStatus;
|
||||||
import org.eclipse.core.runtime.Status;
|
import org.eclipse.core.runtime.Status;
|
||||||
import org.eclipse.dd.dsf.concurrent.DataRequestMonitor;
|
import org.eclipse.dd.dsf.concurrent.DataRequestMonitor;
|
||||||
import org.eclipse.dd.dsf.concurrent.DsfExecutor;
|
|
||||||
import org.eclipse.dd.dsf.concurrent.IDsfStatusConstants;
|
import org.eclipse.dd.dsf.concurrent.IDsfStatusConstants;
|
||||||
import org.eclipse.dd.dsf.internal.ui.DsfUIPlugin;
|
import org.eclipse.dd.dsf.internal.ui.DsfUIPlugin;
|
||||||
import org.eclipse.debug.internal.ui.viewers.model.provisional.IChildrenCountUpdate;
|
import org.eclipse.debug.internal.ui.viewers.model.provisional.IChildrenCountUpdate;
|
||||||
|
@ -39,7 +40,7 @@ abstract public class AbstractVMNode implements IVMNode {
|
||||||
/**
|
/**
|
||||||
* Accessor method for sub-classes.
|
* Accessor method for sub-classes.
|
||||||
*/
|
*/
|
||||||
protected DsfExecutor getExecutor() {
|
protected Executor getExecutor() {
|
||||||
return fProvider.getExecutor();
|
return fProvider.getExecutor();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -17,13 +17,13 @@ import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.ListIterator;
|
import java.util.ListIterator;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.concurrent.Executor;
|
||||||
import java.util.concurrent.RejectedExecutionException;
|
import java.util.concurrent.RejectedExecutionException;
|
||||||
|
|
||||||
import org.eclipse.dd.dsf.concurrent.DataRequestMonitor;
|
import org.eclipse.dd.dsf.concurrent.DataRequestMonitor;
|
||||||
import org.eclipse.dd.dsf.concurrent.DsfExecutor;
|
|
||||||
import org.eclipse.dd.dsf.concurrent.IDsfStatusConstants;
|
import org.eclipse.dd.dsf.concurrent.IDsfStatusConstants;
|
||||||
import org.eclipse.dd.dsf.concurrent.RequestMonitor;
|
import org.eclipse.dd.dsf.concurrent.RequestMonitor;
|
||||||
import org.eclipse.dd.dsf.ui.concurrent.DisplayDsfExecutor;
|
import org.eclipse.dd.dsf.ui.concurrent.SimpleDisplayExecutor;
|
||||||
import org.eclipse.dd.dsf.ui.concurrent.ViewerDataRequestMonitor;
|
import org.eclipse.dd.dsf.ui.concurrent.ViewerDataRequestMonitor;
|
||||||
import org.eclipse.debug.internal.ui.viewers.model.provisional.IChildrenCountUpdate;
|
import org.eclipse.debug.internal.ui.viewers.model.provisional.IChildrenCountUpdate;
|
||||||
import org.eclipse.debug.internal.ui.viewers.model.provisional.IChildrenUpdate;
|
import org.eclipse.debug.internal.ui.viewers.model.provisional.IChildrenUpdate;
|
||||||
|
@ -75,7 +75,7 @@ abstract public class AbstractVMProvider implements IVMProvider
|
||||||
* IPresentationContext object (bug 213629). For now utilize the
|
* IPresentationContext object (bug 213629). For now utilize the
|
||||||
* assumption that there is only one display.
|
* assumption that there is only one display.
|
||||||
*/
|
*/
|
||||||
private final DsfExecutor fExecutor = DisplayDsfExecutor.getDisplayDsfExecutor(Display.getDefault());
|
private final Executor fExecutor = SimpleDisplayExecutor.getSimpleDisplayExecutor(Display.getDefault());
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The element content provider implementation that this provider delegates to.
|
* The element content provider implementation that this provider delegates to.
|
||||||
|
@ -527,12 +527,11 @@ abstract public class AbstractVMProvider implements IVMProvider
|
||||||
* need to worry about the executor throwing the {@link RejectedExecutionException}
|
* need to worry about the executor throwing the {@link RejectedExecutionException}
|
||||||
* exception.
|
* exception.
|
||||||
*/
|
*/
|
||||||
public DsfExecutor getExecutor() {
|
public Executor getExecutor() {
|
||||||
return fExecutor;
|
return fExecutor;
|
||||||
}
|
}
|
||||||
|
|
||||||
public IModelProxy createModelProxy(Object element, IPresentationContext context) {
|
public IModelProxy createModelProxy(Object element, IPresentationContext context) {
|
||||||
assert getExecutor().isInExecutorThread();
|
|
||||||
|
|
||||||
// Iterate through the current active proxies to try to find a proxy with the same
|
// Iterate through the current active proxies to try to find a proxy with the same
|
||||||
// element and re-use it if found. At the same time purge proxies that are no longer
|
// element and re-use it if found. At the same time purge proxies that are no longer
|
||||||
|
@ -568,7 +567,6 @@ abstract public class AbstractVMProvider implements IVMProvider
|
||||||
* @see IColumnPresentationFactory#createColumnPresentation(IPresentationContext, Object)
|
* @see IColumnPresentationFactory#createColumnPresentation(IPresentationContext, Object)
|
||||||
*/
|
*/
|
||||||
public IColumnPresentation createColumnPresentation(IPresentationContext context, Object element) {
|
public IColumnPresentation createColumnPresentation(IPresentationContext context, Object element) {
|
||||||
assert fExecutor.isInExecutorThread();
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue