get rid of ugly globals in DataFlowGraph
[fleet.git] / src / edu / berkeley / fleet / dataflow / Node.java
index 383121e..640d488 100644 (file)
@@ -1,4 +1,5 @@
 package edu.berkeley.fleet.dataflow;
+import java.util.*;
 import edu.berkeley.fleet.loops.*;
 import java.util.concurrent.Semaphore;
 import java.util.*;
@@ -14,7 +15,7 @@ import static edu.berkeley.fleet.util.BitManipulations.*;
 
 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;
 
@@ -29,7 +30,7 @@ public class Node {
             // 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);
@@ -43,7 +44,7 @@ public class Node {
                 // 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);
 
@@ -65,7 +66,7 @@ public class Node {
                 // 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++)
@@ -80,7 +81,7 @@ public class Node {
             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);
@@ -104,9 +105,9 @@ public class Node {
     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;
     }
 
@@ -118,7 +119,7 @@ public class Node {
             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 {
@@ -183,8 +184,8 @@ public class Node {
             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();
@@ -237,8 +238,8 @@ public class Node {
             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);
         }
     }