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

refactoring

parent 2f2be3fd
No related branches found
No related tags found
No related merge requests found
......@@ -37,17 +37,18 @@ public class A2InvalidThreadAssignmentCheck {
this.threadableStages = threadableStages;
}
@SuppressWarnings("PMD.DataflowAnomalyAnalysis")
public void check() {
int color = DEFAULT_COLOR;
ObjectIntMap<AbstractStage> colors = new ObjectIntHashMap<AbstractStage>();
ThreadPainter threadPainter = new ThreadPainter();
Traverser traverser = new Traverser(threadPainter);
for (AbstractStage threadableStage : threadableStages) {
color++;
colors.put(threadableStage, color);
threadPainter.reset(colors, color, threadableStages);
Traverser traverser = new Traverser(threadPainter);
traverser.traverse(threadableStage);
}
}
......@@ -77,17 +78,13 @@ public class A2InvalidThreadAssignmentCheck {
int targetColor = colors.containsKey(targetStage) ? colors.get(targetStage) : DEFAULT_COLOR;
if (threadableStages.contains(targetStage) && targetColor != color) {
// do nothing
} else {
if (colors.containsKey(targetStage)) {
if (colors.get(targetStage) != color) {
throw new IllegalStateException("1001 - Crossing threads in " + targetStage.getId()); // One stage is connected to a stage of another thread
// (but not its "headstage")
}
if (!threadableStages.contains(targetStage) || targetColor == color) {
if (colors.containsKey(targetStage) && colors.get(targetStage) != color) {
throw new IllegalStateException("1001 - Crossing threads in " + targetStage.getId()); // One stage is connected to a stage of another thread
// (but not its "headstage")
}
colors.put(targetStage, color);
return VisitorBehavior.CONTINUE;
return VisitorBehavior.CONTINUE; // NOPMD makes it clearer
}
return VisitorBehavior.STOP;
}
......
......@@ -47,7 +47,7 @@ class A3PipeInstantiation implements ITraverserVisitor {
public VisitorBehavior visit(final AbstractPort<?> port) {
IPipe<?> pipe = port.getPipe();
if (visitedPipes.contains(pipe)) {
return VisitorBehavior.STOP;
return VisitorBehavior.STOP; // NOPMD two returns are better
}
visitedPipes.add(pipe);
......@@ -64,25 +64,26 @@ class A3PipeInstantiation implements ITraverserVisitor {
Thread sourceStageThread = pipe.getSourcePort().getOwningStage().getOwningThread();
Thread targetStageThread = pipe.getTargetPort().getOwningStage().getOwningThread();
if (targetStageThread != null && sourceStageThread != targetStageThread) {
if (targetStageThread == null || sourceStageThread == targetStageThread) { // NOPMD .equals() can't be used here
// normal or reflexive pipe => intra
new UnsynchedPipe<T>(pipe.getSourcePort(), pipe.getTargetPort());
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Connected (unsynch) " + pipe.getSourcePort() + " and " + pipe.getTargetPort());
}
} else {
// inter
if (pipe.capacity() != 0) {
new BoundedSynchedPipe<T>(pipe.getSourcePort(), pipe.getTargetPort(), pipe.capacity());
if (pipe.capacity() == 0) {
new UnboundedSynchedPipe<T>(pipe.getSourcePort(), pipe.getTargetPort());
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Connected (bounded) " + pipe.getSourcePort() + " and " + pipe.getTargetPort());
LOGGER.debug("Connected (unbounded) " + pipe.getSourcePort() + " and " + pipe.getTargetPort());
}
} else {
new UnboundedSynchedPipe<T>(pipe.getSourcePort(), pipe.getTargetPort());
new BoundedSynchedPipe<T>(pipe.getSourcePort(), pipe.getTargetPort(), pipe.capacity());
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Connected (unbounded) " + pipe.getSourcePort() + " and " + pipe.getTargetPort());
LOGGER.debug("Connected (bounded) " + pipe.getSourcePort() + " and " + pipe.getTargetPort());
}
}
} else {
// normal or reflexive pipe => intra
new UnsynchedPipe<T>(pipe.getSourcePort(), pipe.getTargetPort());
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Connected (unsynch) " + pipe.getSourcePort() + " and " + pipe.getTargetPort());
}
}
}
......
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