From 8b598ca38dbdb425d10dcbc78994601b2bdf5212 Mon Sep 17 00:00:00 2001 From: Nelson Tavares de Sousa <stu103017@mail.uni-kiel.de> Date: Wed, 22 Jul 2015 15:05:49 +0200 Subject: [PATCH] Set stage state field to volatile and added check in add(), if the current stage should be terminated --- src/main/java/teetime/framework/AbstractStage.java | 2 +- .../teetime/framework/exceptionHandling/StageException.java | 2 +- src/main/java/teetime/framework/pipe/SpScPipe.java | 3 ++- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/main/java/teetime/framework/AbstractStage.java b/src/main/java/teetime/framework/AbstractStage.java index 9ac7e9df..4f634f27 100644 --- a/src/main/java/teetime/framework/AbstractStage.java +++ b/src/main/java/teetime/framework/AbstractStage.java @@ -34,7 +34,7 @@ public abstract class AbstractStage extends Stage { private final PortList<InputPort<?>> inputPorts = new PortList<InputPort<?>>(); private final PortList<OutputPort<?>> outputPorts = new PortList<OutputPort<?>>(); - private StageState currentState = StageState.CREATED; + private volatile StageState currentState = StageState.CREATED; @Override protected List<InputPort<?>> getInputPorts() { diff --git a/src/main/java/teetime/framework/exceptionHandling/StageException.java b/src/main/java/teetime/framework/exceptionHandling/StageException.java index 524db186..7468e439 100644 --- a/src/main/java/teetime/framework/exceptionHandling/StageException.java +++ b/src/main/java/teetime/framework/exceptionHandling/StageException.java @@ -18,7 +18,7 @@ package teetime.framework.exceptionHandling; import teetime.framework.Stage; /** - * Represents an Exception, which is thrown by stages in case of theyimport teetime.framework.Stage; + * Represents an Exception, which is thrown by stages in case of they import teetime.framework.Stage; * original exception, which was thrown, call {@link #getCause()}. {@link #getThrowingStage()} returns the stage, which has thrown the original exception. * * @since 1.1 diff --git a/src/main/java/teetime/framework/pipe/SpScPipe.java b/src/main/java/teetime/framework/pipe/SpScPipe.java index eb58b9e0..2580bdc1 100644 --- a/src/main/java/teetime/framework/pipe/SpScPipe.java +++ b/src/main/java/teetime/framework/pipe/SpScPipe.java @@ -39,7 +39,8 @@ final class SpScPipe extends AbstractInterThreadPipe implements IMonitorablePipe public boolean add(final Object element) { while (!this.queue.offer(element)) { // Thread.yield(); - if (this.cachedTargetStage.getCurrentState() == StageState.TERMINATED) { + if (this.cachedTargetStage.getCurrentState() == StageState.TERMINATED && + this.getSourcePort().getOwningStage().getCurrentState() == StageState.TERMINATING) { return false; } this.numWaits++; -- GitLab