package edu.berkeley.fleet.dataflow;
+import java.util.*;
import edu.berkeley.fleet.loops.*;
import java.util.concurrent.Semaphore;
import java.util.*;
public class Node {
- int doReset(Context ctx, int phase, Dock dock, Port peer, Destination ackDestination, boolean peerUsed) {
+ int doReset(Context ctx, int phase, Dock dock, Port peer, Destination ackDestination, HashSet<Dock> sendTorpedoesTo, boolean peerUsed) {
int ret = 0;
if (dock.getShip().getType().equals("Debug")) return ret;
// the switch fabric.
case 0: {
if (!dock.isInputDock()) {
- DataFlowGraph.torpedoes.add(dock);
+ sendTorpedoesTo.add(dock);
LoopFactory lf = new LoopFactory(ctx, dock, 1);
lf.sendToken(ackDestination);
lf = lf.makeNext(0);
// Phase 1: torpedo every input dock, put it in loopback mode
case 1: {
if (dock.isInputDock()) {
- DataFlowGraph.torpedoes.add(dock);
+ sendTorpedoesTo.add(dock);
LoopFactory lf = new LoopFactory(ctx, dock, 1);
lf.sendToken(ackDestination);
// Phase 2: torpedo every output dock, have it absorb tokens
case 2: {
if (!dock.isInputDock()) {
- DataFlowGraph.torpedoes.add(dock);
+ sendTorpedoesTo.add(dock);
LoopFactory lf = new LoopFactory(ctx, dock, 1);
if (peer != null)
for(int i=0; i<((InPort)peer).getTokensToAbsorb(); i++)
case 3: {
if (dock.isInputDock()) {
if (peerUsed && peer!=null) {
- DataFlowGraph.torpedoes.add(dock);
+ sendTorpedoesTo.add(dock);
}
LoopFactory lf = new LoopFactory(ctx, dock, 1);
lf.sendToken(ackDestination);
public OutPort getOutPort(String name) { return (OutPort)ports.get(name); }
public void build(Context ctx) { for(Port p : ports.values()) p.build(ctx); }
- public int reset(Context ctx, int phase, Destination ackDestination) {
+ public int reset(Context ctx, int phase, Destination ackDestination, HashSet<Dock> sendTorpedoesTo) {
int ret = 0;
- for(Port p : ports.values()) ret += p.reset(ctx, phase, ackDestination);
+ for(Port p : ports.values()) ret += p.reset(ctx, phase, ackDestination, sendTorpedoesTo);
return ret;
}
Node.this.ports.put(name,this);
}
public abstract void build(Context ctx);
- public abstract int reset(Context ctx, int phase, Destination ackDestination);
+ public abstract int reset(Context ctx, int phase, Destination ackDestination, HashSet<Dock> sendTorpedoesTo);
}
public abstract class InPort extends Port {
for(int i=0; i<pattern.length; i++) if (pattern[i]==null) return true;
return false;
}
- public int reset(Context ctx, int phase, Destination ackDestination) {
- return doReset(ctx, phase, dock, peer, ackDestination, peerUsed());
+ public int reset(Context ctx, int phase, Destination ackDestination, HashSet<Dock> sendTorpedoesTo) {
+ return doReset(ctx, phase, dock, peer, ackDestination, sendTorpedoesTo, peerUsed());
}
protected void build(Context ctx, LoopFactory lf) {
int inflight = (count != 0 && count < getInflight()) ? count : getInflight();
lf.collectWord();
peer.sendWord(lf);
}
- public int reset(Context ctx, int phase, Destination ackDestination) {
- return doReset(ctx, phase, dock, peer, ackDestination, true);
+ public int reset(Context ctx, int phase, Destination ackDestination, HashSet<Dock> sendTorpedoesTo) {
+ return doReset(ctx, phase, dock, peer, ackDestination, sendTorpedoesTo, true);
}
}