[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.59, Sun Mar 17 15:48:53 2013 UTC revision 1.60, Mon Mar 18 12:40:30 2013 UTC
# Line 908  Line 908 
908    
909      /** A customized variant of Spliterators.IteratorSpliterator */      /** 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 << 20;  // max batch array size;          static final int MAX_BATCH = 1 << 25;  // max batch array size;
         static final int MAX_QUEUED = 1 << 12; // max task backlog  
912          final LinkedTransferQueue<E> queue;          final LinkedTransferQueue<E> queue;
913          Node current;    // current node; null until initialized          Node current;    // current node; null until initialized
914          int batch;          // batch size for splits          int batch;          // batch size for splits
# Line 918  Line 917 
917              this.queue = queue;              this.queue = queue;
918          }          }
919    
         /**  
          * Splits into arrays of arithmetically increasing batch sizes,  
          * giving up at MAX_BATCH.  Treat the result as a  
          * CopyOnWriteArrayList array snapshot.  This will only  
          * improve parallel performance if per-element forEach actions  
          * are more costly than transfering them into an array. If  
          * not, we limit slowdowns by eventually returning null split.  
          */  
920          public Spliterator<E> trySplit() {          public Spliterator<E> trySplit() {
921              Node p; int b;              Node p;
922              final LinkedTransferQueue<E> q = this.queue;              final LinkedTransferQueue<E> q = this.queue;
923                int b = batch;
924                int n = (b <= 0) ? 1 : (b >= MAX_BATCH) ? MAX_BATCH : b + 1;
925              if (!exhausted &&              if (!exhausted &&
                 ((b = batch) < MAX_QUEUED ||  
                  ForkJoinTask.getQueuedTaskCount() < MAX_QUEUED) &&  
926                  ((p = current) != null || (p = q.firstDataNode()) != null) &&                  ((p = current) != null || (p = q.firstDataNode()) != null) &&
927                  p.next != null) {                  p.next != null) {
                 int n = batch = (b >= MAX_BATCH) ? MAX_BATCH : b + 1;  
928                  Object[] a;                  Object[] a;
929                  try {                  try {
930                      a = new Object[n];                      a = new Object[n];
# Line 950  Line 940 
940                  } while (p != null && i < n);                  } while (p != null && i < n);
941                  if ((current = p) == null)                  if ((current = p) == null)
942                      exhausted = true;                      exhausted = true;
943                    if (i > 0) {
944                        batch = i;
945                  return Spliterators.spliterator                  return Spliterators.spliterator
946                      (a, 0, i, Spliterator.ORDERED | Spliterator.NONNULL |                      (a, 0, i, Spliterator.ORDERED | Spliterator.NONNULL |
947                       Spliterator.CONCURRENT);                       Spliterator.CONCURRENT);
948              }              }
949                }
950              return null;              return null;
951          }          }
952    

Legend:
Removed from v.1.59  
changed lines
  Added in v.1.60

Doug Lea
ViewVC Help
Powered by ViewVC 1.0.8