getFleet().sendToken(this, port);
}
- public boolean readyForDataFromShip() {
+ public boolean readyForTokenFromShip() {
return super.readyForItemFromShip();
}
addItemFromShip(0);
}
- public boolean readyForToken() {
- return readyForDataFromShip();
- }
}
--- /dev/null
+package edu.berkeley.fleet.ships;
+import edu.berkeley.fleet.*;
+
+import java.util.*;
+import java.io.*;
+
+public class ArithmeticShip extends Ship {
+
+ TokenOutbox tout = new TokenOutbox(this, "tout");
+ TokenInbox tin = new TokenInbox(this, "tin");
+ DataOutbox dout = new DataOutbox(this, "dout");
+ DataInbox din = new DataInbox(this, "din");
+
+ public ArithmeticShip(Fleet fleet, String name) {
+ super(fleet, name);
+ }
+
+ public void service() {
+
+ // dominic, pretend this method is inside an infinite loop;
+ // every time it is invoked you should:
+
+ // 1. check your input ports to see if they have stuff
+
+ // 2. make sure your output ports don't still have stuff stuck
+ // in them (if they do, just return and wait until later)
+
+ // 3. do your thing
+
+ // here's some sample code snippets that should cover all the
+ // cases you need
+
+ if (!tin.tokenReadyForShip())
+ return;
+ tin.removeTokenForShip();
+
+ if (!din.dataReadyForShip())
+ return;
+ int mydat = din.removeDataForShip();
+
+ if (tout.readyForTokenFromShip())
+ tout.addTokenFromShip();
+ if (dout.readyForDataFromShip())
+ dout.addDataFromShip(123);
+
+ }
+
+}
public void service() {
if (!codebag.dataReadyForShip()) return;
if (!release.tokenReadyForShip() && !revoke.tokenReadyForShip()) return;
- if (!done.readyForToken()) return;
+ if (!done.readyForTokenFromShip()) return;
int cbd = codebag.removeDataForShip();
CodeBag cb = CodeBag.getCodeBagByDescriptor(cbd);
}
public void service() {
- if (!zero.readyForToken()) return;
- if (!positive.readyForToken()) return;
+ if (!zero.readyForTokenFromShip()) return;
+ if (!positive.readyForTokenFromShip()) return;
if (load.dataReadyForShip()) {
count = load.removeDataForShip();
return;
public void service() {
if (_count > 0) {
if (!data.readyForDataFromShip()) return;
- data.addDataFromShip(_addr>=fleet.mem.length ? 0 : fleet.mem[_addr]);
+ data.addDataFromShip(_addr>=getFleet().mem.length ? 0 : getFleet().mem[_addr]);
_count--;
_addr += _stride;
if (_count==0)
if (count.dataReadyForShip() &&
addr.dataReadyForShip() &&
stride.dataReadyForShip() &&
- done.readyForToken() &&
+ done.readyForTokenFromShip() &&
data.readyForDataFromShip()) {
_count = count.removeDataForShip();