Mercurial > hg > Members > tatsuki > Alice
diff src/alice/datasegment/DataSegmentKey.java @ 73:4bfd81352cfa
change to concurrent data segment
author | kazz <kazz@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Tue, 21 Feb 2012 22:55:17 +0900 |
parents | 1d4f2b72fb31 |
children | 409d7679cf7b |
line wrap: on
line diff
--- a/src/alice/datasegment/DataSegmentKey.java Tue Feb 21 21:11:50 2012 +0900 +++ b/src/alice/datasegment/DataSegmentKey.java Tue Feb 21 22:55:17 2012 +0900 @@ -2,7 +2,6 @@ import java.util.ArrayList; import java.util.Iterator; -import java.util.concurrent.atomic.AtomicInteger; import alice.datasegment.Command; @@ -15,16 +14,16 @@ private ArrayList<DataSegmentValue> dataList = new ArrayList<DataSegmentValue>(); private ArrayList<Command> waitList = new ArrayList<Command>(); - private AtomicInteger tailIndex = new AtomicInteger(1); + private int tailIndex = 1; - public void runCommand(Command cmd) { + public synchronized void runCommand(Command cmd) { switch (cmd.type) { case UPDATE: if (dataList.size() != 0) { dataList.remove(0); } case PUT: - int index = tailIndex.getAndIncrement(); + int index = tailIndex++; DataSegmentValue dsv = new DataSegmentValue(index, cmd.val, cmd.reverseKey); dataList.add(dsv); // Process waiting peek and take commands @@ -45,7 +44,7 @@ } break; case PEEK: - if (cmd.index >= tailIndex.get()) { + if (cmd.index >= tailIndex) { waitList.add(cmd); break; } @@ -65,7 +64,7 @@ waitList.add(cmd); break; case TAKE: - if (cmd.index >= tailIndex.get()) { + if (cmd.index >= tailIndex) { waitList.add(cmd); break; }