ソースを参照

Synchronized threads and Stackframes

Andreas Muelder 9 年 前
コミット
079b1cf0ba

+ 20 - 17
plugins/org.yakindu.sct.simulation.core/src/org/yakindu/sct/simulation/core/debugmodel/SCTDebugTarget.java

@@ -103,27 +103,29 @@ public class SCTDebugTarget extends SCTDebugElement implements IDebugTarget, ISt
 		for (RegularState vertex : activeLeafStates) {
 			activeRegions.add(vertex.getParentRegion());
 		}
-		// Remove orphaned debug threads
-		Iterator<SCTDebugThread> iterator = threads.iterator();
-		while (iterator.hasNext()) {
-			SCTDebugThread next = iterator.next();
-			if (!activeRegions.contains(next.getElement())) {
-				iterator.remove();
-			}
-		}
-		// Add new debug threads
-		for (Region region : activeRegions) {
-			boolean found = false;
-			for (SCTDebugThread thread : threads) {
-				if (thread.getElement() == region) {
-					found = true;
+		synchronized (threads) {
+			// Remove orphaned debug threads
+			Iterator<SCTDebugThread> iterator = threads.iterator();
+			while (iterator.hasNext()) {
+				SCTDebugThread next = iterator.next();
+				if (!activeRegions.contains(next.getElement())) {
+					iterator.remove();
 				}
 			}
-			if (!found) {
-				threads.add(new SCTDebugThread(this, engine, getResourceString(), region));
+			// Add new debug threads
+			for (Region region : activeRegions) {
+				boolean found = false;
+				for (SCTDebugThread thread : threads) {
+					if (thread.getElement() == region) {
+						found = true;
+					}
+				}
+				if (!found) {
+					threads.add(new SCTDebugThread(this, engine, getResourceString(), region));
+				}
 			}
+			return threads.toArray(new IThread[] {});
 		}
-		return threads.toArray(new IThread[] {});
 	}
 
 	public boolean hasThreads() throws DebugException {
@@ -216,6 +218,7 @@ public class SCTDebugTarget extends SCTDebugElement implements IDebugTarget, ISt
 		return this;
 	}
 
+	@SuppressWarnings("unchecked")
 	public Object getAdapter(@SuppressWarnings("rawtypes") Class adapter) {
 		if (adapter == ISimulationEngine.class)
 			return engine;

+ 12 - 10
plugins/org.yakindu.sct.simulation.core/src/org/yakindu/sct/simulation/core/debugmodel/SCTDebugThread.java

@@ -58,19 +58,20 @@ public class SCTDebugThread extends SCTDebugElement implements IThread {
 				break;
 			}
 		}
-
-		if (activeState != null && lastActiveState != activeState) {
-			lastActiveState = activeState;
-			EObject container = activeState;
-			stateStack = new ArrayList<SCTStackFrame>();
-			while (container != null) {
-				if (container instanceof RegularState) {
-					stateStack.add(new SCTStackFrame(this, (RegularState) container, getResourceString()));
+		synchronized (stateStack) {
+			if (activeState != null && lastActiveState != activeState) {
+				lastActiveState = activeState;
+				EObject container = activeState;
+				stateStack = new ArrayList<SCTStackFrame>();
+				while (container != null) {
+					if (container instanceof RegularState) {
+						stateStack.add(new SCTStackFrame(this, (RegularState) container, getResourceString()));
+					}
+					container = container.eContainer();
 				}
-				container = container.eContainer();
 			}
+			return stateStack.toArray(new IStackFrame[] {});
 		}
-		return stateStack.toArray(new IStackFrame[] {});
 	}
 
 	public boolean hasStackFrames() throws DebugException {
@@ -147,6 +148,7 @@ public class SCTDebugThread extends SCTDebugElement implements IThread {
 		return null;
 	}
 
+	@SuppressWarnings("unchecked")
 	public Object getAdapter(@SuppressWarnings("rawtypes") Class adapter) {
 		if (adapter == ISimulationEngine.class)
 			return container;

+ 1 - 0
plugins/org.yakindu.sct.simulation.core/src/org/yakindu/sct/simulation/core/debugmodel/SCTStackFrame.java

@@ -152,6 +152,7 @@ public class SCTStackFrame extends SCTDebugElement implements IStackFrame {
 		return element.eResource().getURI().toPlatformString(true);
 	}
 
+	@SuppressWarnings("unchecked")
 	public Object getAdapter(@SuppressWarnings("rawtypes") Class adapter) {
 		if (adapter == EObject.class)
 			return element;