Mercurial > hg > Members > tatsuki > Alice
view src/alice/codesegment/InputDataSegment.java @ 205:28469b1671e7 working
repair flip API
author | sugi |
---|---|
date | Tue, 26 Mar 2013 01:45:05 +0900 |
parents | 7f47231ef509 |
children | 96110f25adcc |
line wrap: on
line source
package alice.codesegment; import java.util.concurrent.atomic.AtomicInteger; import alice.datasegment.Command; import alice.datasegment.CommandType; import alice.datasegment.DataSegment; import alice.datasegment.DataSegmentValue; import alice.datasegment.Receiver; /** * InputDataSegment Manager * keep tracking unbound/bound count * @author kazz * */ public class InputDataSegment { public CodeSegment cs; private AtomicInteger count = new AtomicInteger(1); // 1 for no input data segments private AtomicInteger keyCount = new AtomicInteger(0); // number of DataSegments public InputDataSegment(CodeSegment cs) { this.cs = cs; } public void peek(Receiver receiver, String managerKey, String key) { peek(receiver, managerKey, key, 0); } public void peek(Receiver receiver, String managerKey, String key, int index) { DataSegment.get(managerKey).peek(receiver, key, index, cs); } public void peek(Receiver receiver, String key) { peek(receiver, key, 0); } public void peek(Receiver receiver, String key, int index) { DataSegment.getLocal().peek(receiver, key, index, cs); } public void take(Receiver receiver, String managerKey, String key) { take(receiver, managerKey, key, 0); } public void take(Receiver receiver, String managerKey, String key, int index) { DataSegment.get(managerKey).take(receiver, key, index, cs); } public void take(Receiver receiver, String key) { take(receiver, key, 0); } public void take(Receiver receiver, String key, int index) { DataSegment.getLocal().take(receiver, key, index, cs); } public void flip(Command cmd) { DataSegment.getLocal().flip(cmd); } public void reply(Receiver receiver, DataSegmentValue val, Command reply) { receiver.index = val.index; receiver.val = val.val; receiver.from = val.from; receiver.obj = val.obj; receiver.setCommand(reply); receive(); } public void regist() { count.getAndIncrement(); keyCount.getAndIncrement(); } public void setKey() { if (keyCount.decrementAndGet() == 0) { receive(); } } public void receive() { if (count.decrementAndGet() == 0) { CodeSegmentManager.submit(cs); } } /** * InputDataSegment factory * @param type PEEK or TAKE * @return Receiver of DataSegment reply */ public Receiver create(CommandType type) { return new Receiver(this, type); } }