提交 c79c53a2 编写于 作者: D dl

6981113: Add ConcurrentLinkedDeque

Summary: Extend techniques developed for ConcurrentLinkedQueue and LinkedTransferQueue to implement a non-blocking concurrent Deque with interior removes.
Reviewed-by: martin, dholmes, chegar
上级 bfeeb3b8
...@@ -272,6 +272,7 @@ JAVA_JAVA_java = \ ...@@ -272,6 +272,7 @@ JAVA_JAVA_java = \
java/util/concurrent/CancellationException.java \ java/util/concurrent/CancellationException.java \
java/util/concurrent/CompletionService.java \ java/util/concurrent/CompletionService.java \
java/util/concurrent/ConcurrentHashMap.java \ java/util/concurrent/ConcurrentHashMap.java \
java/util/concurrent/ConcurrentLinkedDeque.java \
java/util/concurrent/ConcurrentLinkedQueue.java \ java/util/concurrent/ConcurrentLinkedQueue.java \
java/util/concurrent/ConcurrentMap.java \ java/util/concurrent/ConcurrentMap.java \
java/util/concurrent/ConcurrentNavigableMap.java \ java/util/concurrent/ConcurrentNavigableMap.java \
......
...@@ -173,6 +173,11 @@ public class BiggernYours { ...@@ -173,6 +173,11 @@ public class BiggernYours {
new ConcurrentHashMap() { new ConcurrentHashMap() {
public int size() {return randomize(super.size());}}); public int size() {return randomize(super.size());}});
testCollections(
new ConcurrentLinkedDeque(),
new ConcurrentLinkedDeque() {
public int size() {return randomize(super.size());}});
testCollections( testCollections(
new ConcurrentLinkedQueue(), new ConcurrentLinkedQueue(),
new ConcurrentLinkedQueue() { new ConcurrentLinkedQueue() {
......
...@@ -48,6 +48,7 @@ public class IteratorAtEnd { ...@@ -48,6 +48,7 @@ public class IteratorAtEnd {
testCollection(new PriorityQueue()); testCollection(new PriorityQueue());
testCollection(new LinkedBlockingQueue()); testCollection(new LinkedBlockingQueue());
testCollection(new ArrayBlockingQueue(100)); testCollection(new ArrayBlockingQueue(100));
testCollection(new ConcurrentLinkedDeque());
testCollection(new ConcurrentLinkedQueue()); testCollection(new ConcurrentLinkedQueue());
testCollection(new LinkedTransferQueue()); testCollection(new LinkedTransferQueue());
......
...@@ -75,6 +75,7 @@ public class MOAT { ...@@ -75,6 +75,7 @@ public class MOAT {
testCollection(new ArrayBlockingQueue<Integer>(20)); testCollection(new ArrayBlockingQueue<Integer>(20));
testCollection(new LinkedBlockingQueue<Integer>(20)); testCollection(new LinkedBlockingQueue<Integer>(20));
testCollection(new LinkedBlockingDeque<Integer>(20)); testCollection(new LinkedBlockingDeque<Integer>(20));
testCollection(new ConcurrentLinkedDeque<Integer>());
testCollection(new ConcurrentLinkedQueue<Integer>()); testCollection(new ConcurrentLinkedQueue<Integer>());
testCollection(new LinkedTransferQueue<Integer>()); testCollection(new LinkedTransferQueue<Integer>());
testCollection(new ConcurrentSkipListSet<Integer>()); testCollection(new ConcurrentSkipListSet<Integer>());
...@@ -433,6 +434,7 @@ public class MOAT { ...@@ -433,6 +434,7 @@ public class MOAT {
checkFunctionalInvariants(q); checkFunctionalInvariants(q);
if ((q instanceof LinkedBlockingQueue) || if ((q instanceof LinkedBlockingQueue) ||
(q instanceof LinkedBlockingDeque) || (q instanceof LinkedBlockingDeque) ||
(q instanceof ConcurrentLinkedDeque) ||
(q instanceof ConcurrentLinkedQueue)) { (q instanceof ConcurrentLinkedQueue)) {
testQueueIteratorRemove(q); testQueueIteratorRemove(q);
} }
......
...@@ -235,6 +235,7 @@ public class RacingCollections { ...@@ -235,6 +235,7 @@ public class RacingCollections {
new ArrayList<Queue<Integer>>(newConcurrentDeques()); new ArrayList<Queue<Integer>>(newConcurrentDeques());
list.add(new LinkedBlockingQueue<Integer>(10)); list.add(new LinkedBlockingQueue<Integer>(10));
list.add(new LinkedTransferQueue<Integer>()); list.add(new LinkedTransferQueue<Integer>());
list.add(new ConcurrentLinkedQueue<Integer>());
return list; return list;
} }
...@@ -248,6 +249,7 @@ public class RacingCollections { ...@@ -248,6 +249,7 @@ public class RacingCollections {
private static List<Deque<Integer>> newConcurrentDeques() { private static List<Deque<Integer>> newConcurrentDeques() {
List<Deque<Integer>> list = new ArrayList<Deque<Integer>>(); List<Deque<Integer>> list = new ArrayList<Deque<Integer>>();
list.add(new LinkedBlockingDeque<Integer>(10)); list.add(new LinkedBlockingDeque<Integer>(10));
list.add(new ConcurrentLinkedDeque<Integer>());
return list; return list;
} }
......
...@@ -129,6 +129,7 @@ public class ChorusLine { ...@@ -129,6 +129,7 @@ public class ChorusLine {
deqs.add(new ArrayDeque<Integer>()); deqs.add(new ArrayDeque<Integer>());
deqs.add(new LinkedList<Integer>()); deqs.add(new LinkedList<Integer>());
deqs.add(new LinkedBlockingDeque<Integer>()); deqs.add(new LinkedBlockingDeque<Integer>());
deqs.add(new ConcurrentLinkedDeque<Integer>());
equal(deqs); equal(deqs);
......
...@@ -55,6 +55,7 @@ public class ConcurrentQueueLoops { ...@@ -55,6 +55,7 @@ public class ConcurrentQueueLoops {
Collection<Queue<Integer>> concurrentQueues() { Collection<Queue<Integer>> concurrentQueues() {
List<Queue<Integer>> queues = new ArrayList<Queue<Integer>>(); List<Queue<Integer>> queues = new ArrayList<Queue<Integer>>();
queues.add(new ConcurrentLinkedDeque<Integer>());
queues.add(new ConcurrentLinkedQueue<Integer>()); queues.add(new ConcurrentLinkedQueue<Integer>());
queues.add(new ArrayBlockingQueue<Integer>(items, false)); queues.add(new ArrayBlockingQueue<Integer>(items, false));
//queues.add(new ArrayBlockingQueue<Integer>(count, true)); //queues.add(new ArrayBlockingQueue<Integer>(count, true));
...@@ -105,7 +106,7 @@ public class ConcurrentQueueLoops { ...@@ -105,7 +106,7 @@ public class ConcurrentQueueLoops {
final Queue<Integer> queue; final Queue<Integer> queue;
final CyclicBarrier barrier; final CyclicBarrier barrier;
int items; int items;
Stage (Queue<Integer> q, CyclicBarrier b, int items) { Stage(Queue<Integer> q, CyclicBarrier b, int items) {
queue = q; queue = q;
barrier = b; barrier = b;
this.items = items; this.items = items;
......
...@@ -40,6 +40,7 @@ ...@@ -40,6 +40,7 @@
import java.util.concurrent.ArrayBlockingQueue; import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentLinkedDeque;
import java.util.concurrent.ConcurrentLinkedQueue; import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.LinkedBlockingDeque; import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.LinkedBlockingQueue; import java.util.concurrent.LinkedBlockingQueue;
...@@ -62,6 +63,7 @@ public class GCRetention { ...@@ -62,6 +63,7 @@ public class GCRetention {
Collection<Queue<Boolean>> queues() { Collection<Queue<Boolean>> queues() {
List<Queue<Boolean>> queues = new ArrayList<Queue<Boolean>>(); List<Queue<Boolean>> queues = new ArrayList<Queue<Boolean>>();
queues.add(new ConcurrentLinkedDeque<Boolean>());
queues.add(new ConcurrentLinkedQueue<Boolean>()); queues.add(new ConcurrentLinkedQueue<Boolean>());
queues.add(new ArrayBlockingQueue<Boolean>(count, false)); queues.add(new ArrayBlockingQueue<Boolean>(count, false));
queues.add(new ArrayBlockingQueue<Boolean>(count, true)); queues.add(new ArrayBlockingQueue<Boolean>(count, true));
......
...@@ -48,6 +48,7 @@ public class IteratorWeakConsistency { ...@@ -48,6 +48,7 @@ public class IteratorWeakConsistency {
test(new LinkedBlockingQueue(20)); test(new LinkedBlockingQueue(20));
test(new LinkedBlockingDeque()); test(new LinkedBlockingDeque());
test(new LinkedBlockingDeque(20)); test(new LinkedBlockingDeque(20));
test(new ConcurrentLinkedDeque());
test(new ConcurrentLinkedQueue()); test(new ConcurrentLinkedQueue());
test(new LinkedTransferQueue()); test(new LinkedTransferQueue());
// Other concurrent queues (e.g. ArrayBlockingQueue) do not // Other concurrent queues (e.g. ArrayBlockingQueue) do not
......
...@@ -55,6 +55,7 @@ public class OfferRemoveLoops { ...@@ -55,6 +55,7 @@ public class OfferRemoveLoops {
testQueue(new LinkedBlockingDeque()); testQueue(new LinkedBlockingDeque());
testQueue(new ArrayBlockingQueue(10)); testQueue(new ArrayBlockingQueue(10));
testQueue(new PriorityBlockingQueue(10)); testQueue(new PriorityBlockingQueue(10));
testQueue(new ConcurrentLinkedDeque());
testQueue(new ConcurrentLinkedQueue()); testQueue(new ConcurrentLinkedQueue());
testQueue(new LinkedTransferQueue()); testQueue(new LinkedTransferQueue());
} }
......
...@@ -41,6 +41,7 @@ ...@@ -41,6 +41,7 @@
import java.util.concurrent.ArrayBlockingQueue; import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentLinkedDeque;
import java.util.concurrent.ConcurrentLinkedQueue; import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.CountDownLatch; import java.util.concurrent.CountDownLatch;
import java.util.concurrent.LinkedBlockingDeque; import java.util.concurrent.LinkedBlockingDeque;
...@@ -62,6 +63,7 @@ public class RemovePollRace { ...@@ -62,6 +63,7 @@ public class RemovePollRace {
Collection<Queue<Boolean>> concurrentQueues() { Collection<Queue<Boolean>> concurrentQueues() {
List<Queue<Boolean>> queues = new ArrayList<Queue<Boolean>>(); List<Queue<Boolean>> queues = new ArrayList<Queue<Boolean>>();
queues.add(new ConcurrentLinkedDeque<Boolean>());
queues.add(new ConcurrentLinkedQueue<Boolean>()); queues.add(new ConcurrentLinkedQueue<Boolean>());
queues.add(new ArrayBlockingQueue<Boolean>(count, false)); queues.add(new ArrayBlockingQueue<Boolean>(count, false));
queues.add(new ArrayBlockingQueue<Boolean>(count, true)); queues.add(new ArrayBlockingQueue<Boolean>(count, true));
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册