[cvs] / jsr166 / src / main / java / util / concurrent / LinkedTransferQueue.java Repository:
ViewVC logotype

Diff of /jsr166/src/main/java/util/concurrent/LinkedTransferQueue.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.56, Wed Mar 13 12:39:02 2013 UTC revision 1.57, Sat Mar 16 16:03:08 2013 UTC
# Line 906  Line 906 
906          }          }
907      }      }
908    
909      // Very similar to ConcurrentLinkedQueue spliterator      /** A customized variant of Spliterators.IteratorSpliterator */
910      static final class LTQSpliterator<E> implements Spliterator<E> {      static final class LTQSpliterator<E> implements Spliterator<E> {
911          static final int MAX_BATCH = 1 << 10;  // saturate batch size          static final int MAX_BATCH = 1 << 20;  // max batch array size;
912            static final int MAX_QUEUED = 1 << 12; // max task backlog
913          final LinkedTransferQueue<E> queue;          final LinkedTransferQueue<E> queue;
914          Node current;    // current node; null until initialized          Node current;    // current node; null until initialized
915          int batch;          // batch size for splits          int batch;          // batch size for splits
# Line 926  Line 927 
927           * not, we limit slowdowns by eventually returning null split.           * not, we limit slowdowns by eventually returning null split.
928           */           */
929          public Spliterator<E> trySplit() {          public Spliterator<E> trySplit() {
930              Node p; int n;              Node p; int b;
931              final LinkedTransferQueue<E> q = this.queue;              final LinkedTransferQueue<E> q = this.queue;
932              if (!exhausted && (n = batch + 1) > 0 && n <= MAX_BATCH &&              if (!exhausted &&
933                    ((b = batch) < MAX_QUEUED ||
934                     java.util.concurrent.ForkJoinTask.getQueuedTaskCount() < MAX_QUEUED) &&
935                  ((p = current) != null || (p = q.firstDataNode()) != null) &&                  ((p = current) != null || (p = q.firstDataNode()) != null) &&
936                  p.next != null) {                  p.next != null) {
937                  Object[] a = new Object[batch = n];                  int n = batch = (b >= MAX_BATCH)? MAX_BATCH : b + 1;
938                    Object[] a;
939                    try {
940                        a = new Object[n];
941                    } catch (OutOfMemoryError oome) {
942                        return null;
943                    }
944                  int i = 0;                  int i = 0;
945                  do {                  do {
946                      if ((a[i] = p.item) != null)                      if ((a[i] = p.item) != null)

Legend:
Removed from v.1.56  
changed lines
  Added in v.1.57

Doug Lea
ViewVC Help
Powered by ViewVC 1.0.8