1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-19 15:05:36 +02:00

[268760] [view model] DefaultDsfSelectionPolicy accesses DSF services in the wrong thread

This commit is contained in:
Anton Leherbauer 2009-03-16 11:56:07 +00:00
parent f0a0f1b4ad
commit 3e30929b5b

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2008 Wind River Systems, Inc. and others. * Copyright (c) 2008, 2009 Wind River Systems, Inc. and others.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -10,6 +10,10 @@
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.dsf.debug.ui.viewmodel.launch; package org.eclipse.cdt.dsf.debug.ui.viewmodel.launch;
import java.util.concurrent.ExecutionException;
import org.eclipse.cdt.dsf.concurrent.DataRequestMonitor;
import org.eclipse.cdt.dsf.concurrent.Query;
import org.eclipse.cdt.dsf.datamodel.DMContexts; import org.eclipse.cdt.dsf.datamodel.DMContexts;
import org.eclipse.cdt.dsf.datamodel.IDMContext; import org.eclipse.cdt.dsf.datamodel.IDMContext;
import org.eclipse.cdt.dsf.debug.service.IRunControl; import org.eclipse.cdt.dsf.debug.service.IRunControl;
@ -17,6 +21,7 @@ import org.eclipse.cdt.dsf.debug.service.IRunControl.IExecutionDMContext;
import org.eclipse.cdt.dsf.debug.service.IStack.IFrameDMContext; import org.eclipse.cdt.dsf.debug.service.IStack.IFrameDMContext;
import org.eclipse.cdt.dsf.internal.ui.DsfUIPlugin; import org.eclipse.cdt.dsf.internal.ui.DsfUIPlugin;
import org.eclipse.cdt.dsf.service.DsfServicesTracker; import org.eclipse.cdt.dsf.service.DsfServicesTracker;
import org.eclipse.cdt.dsf.service.DsfSession;
import org.eclipse.cdt.dsf.ui.viewmodel.datamodel.IDMVMContext; import org.eclipse.cdt.dsf.ui.viewmodel.datamodel.IDMVMContext;
import org.eclipse.debug.internal.ui.viewers.model.provisional.IModelSelectionPolicy; import org.eclipse.debug.internal.ui.viewers.model.provisional.IModelSelectionPolicy;
import org.eclipse.debug.internal.ui.viewers.model.provisional.IPresentationContext; import org.eclipse.debug.internal.ui.viewers.model.provisional.IPresentationContext;
@ -82,20 +87,40 @@ public class DefaultDsfSelectionPolicy implements IModelSelectionPolicy {
protected boolean isSticky(Object element) { protected boolean isSticky(Object element) {
if (element instanceof IDMVMContext) { if (element instanceof IDMVMContext) {
IDMVMContext dmvmContext= (IDMVMContext) element; IDMVMContext dmvmContext= (IDMVMContext) element;
IDMContext dmContext= dmvmContext.getDMContext(); final IDMContext dmContext= dmvmContext.getDMContext();
if (dmContext instanceof IFrameDMContext) { if (dmContext instanceof IFrameDMContext) {
IExecutionDMContext execContext= DMContexts.getAncestorOfType(dmContext, IExecutionDMContext.class); final IExecutionDMContext execContext= DMContexts.getAncestorOfType(dmContext, IExecutionDMContext.class);
if (execContext != null) { if (execContext != null) {
DsfServicesTracker servicesTracker = new DsfServicesTracker(DsfUIPlugin.getBundleContext(), dmContext.getSessionId()); Query<Boolean> query = new Query<Boolean>() {
try { @Override
IRunControl runControl= servicesTracker.getService(IRunControl.class); protected void execute(DataRequestMonitor<Boolean> rm) {
if (runControl != null) { DsfServicesTracker servicesTracker = new DsfServicesTracker(DsfUIPlugin.getBundleContext(), dmContext.getSessionId());
if (runControl.isSuspended(execContext)) { try {
return true; IRunControl runControl= servicesTracker.getService(IRunControl.class);
if (runControl != null) {
rm.setData(runControl.isSuspended(execContext));
}
} finally {
servicesTracker.dispose();
rm.done();
} }
} }
} finally { };
servicesTracker.dispose(); DsfSession session = DsfSession.getSession(dmContext.getSessionId());
if (session != null) {
if (session.getExecutor().isInExecutorThread()) {
query.run();
} else {
session.getExecutor().execute(query);
}
try {
Boolean result = query.get();
return result != null && result.booleanValue();
} catch (InterruptedException exc) {
Thread.currentThread().interrupt();
} catch (ExecutionException exc) {
DsfUIPlugin.log(exc);
}
} }
} }
} }