Skip to content
Snippets Groups Projects
Commit ff7e6e9d authored by Nelson Tavares de Sousa's avatar Nelson Tavares de Sousa
Browse files

added check whether the following stage is terminated on adding elements

to a full pipe
parent 32722173
No related branches found
No related tags found
No related merge requests found
......@@ -18,6 +18,7 @@ package teetime.framework.pipe;
import teetime.framework.AbstractInterThreadPipe;
import teetime.framework.InputPort;
import teetime.framework.OutputPort;
import teetime.framework.StageState;
import teetime.util.concurrent.queue.ObservableSpScArrayQueue;
public final class SpScPipe extends AbstractInterThreadPipe implements IMonitorablePipe {
......@@ -44,8 +45,11 @@ public final class SpScPipe extends AbstractInterThreadPipe implements IMonitora
public boolean add(final Object element) {
// BETTER introduce a QueueIsFullStrategy
while (!this.queue.offer(element)) {
this.numWaits++;
// Thread.yield();
if (this.cachedTargetStage.getCurrentState() == StageState.TERMINATED) {
return false;
}
this.numWaits++;
try {
Thread.sleep(1);
} catch (InterruptedException e) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment