added am10 inbox/outbox support
[fleet.git] / flow-control-example.fleet
1 #import edu.berkeley.fleet.ships
2
3 #ship helper      : FifoShip
4 #ship source      : FifoShip
5 #ship dest        : FifoShip
6 #ship halt        : HaltShip
7 #ship fetch       : FetchShip
8 #ship tokensource : TokenSourceShip
9
10 // NOTE: "accept" is a synonym for "move" it is less confusing in the case
11 //       of inboxes, but is otherwise identical
12
13
14 //////////////////////////////////////////////////////////////////////////////
15 // The following three instructions simply produce one hundred "3"s
16 // and put them into fifo "a".  Ignore the switch-fabric clogging
17 // issue here; this is just setup for the rest of the code.
18
19                  3                -> helper.in
20             copy helper.out -[10]-> source.in
21          discard helper.out       -> ()
22
23
24 //////////////////////////////////////////////////////////////////////////////
25 // set up a counting move of 10 items from source.out to dest.in, but require
26 // flow control tokens (10 items is too many to send at once)
27
28  triggered move  source.out -[10]-> dest.in
29
30
31 //////////////////////////////////////////////////////////////////////////////
32 // The next instruction tears down the "default" standing move on dest.in
33 // and uses the resulting tokens to prime source.out's pump.  Once that
34 // has been kicked off, any subsequent incoming items will generate tokens
35 // which are sent back to the source outbox
36
37           nop+ack dest.in     -[3]-> source.out
38        accept+ack dest.in   -[10]-> source.out
39           nop+ack dest.in         -> fetch.release    // then release the fetch
40            accept dest.in     -[*]-> ()               // and return the fabric to normal
41
42 { tokensource.out -> halt.in }    -> fetch.codebag    // termination codebag
43
44
45