ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/jsr166y/ForkJoinWorkerThread.java
(Generate patch)

Comparing jsr166/src/jsr166y/ForkJoinWorkerThread.java (file contents):
Revision 1.33 by dl, Thu May 27 16:46:49 2010 UTC vs.
Revision 1.34 by dl, Fri Jun 4 14:37:54 2010 UTC

# Line 138 | Line 138 | public class ForkJoinWorkerThread extend
138  
139      /**
140       * Capacity of work-stealing queue array upon initialization.
141 <     * Must be a power of two. Initial size must be at least 2, but is
141 >     * Must be a power of two. Initial size must be at least 4, but is
142       * padded to minimize cache effects.
143       */
144      private static final int INITIAL_QUEUE_CAPACITY = 1 << 13;
# Line 358 | Line 358 | public class ForkJoinWorkerThread extend
358       * Find and execute tasks and check status while running
359       */
360      private void mainLoop() {
361 <        boolean ran = false; // true if ran task on previous step
361 >        boolean ran = false;      // true if ran task in last loop iter
362 >        boolean prevRan = false;  // true if ran on last or previous step
363          ForkJoinPool p = pool;
364          for (;;) {
365 <            p.preStep(this, ran);
365 >            p.preStep(this, prevRan);
366              if (runState != 0)
367                  return;
368              ForkJoinTask<?> t; // try to get and run stolen or submitted task
369 <            if (ran = (t = scan()) != null || (t = pollSubmission()) != null) {
369 >            if ((t = scan()) != null || (t = pollSubmission()) != null) {
370                  t.tryExec();
371                  if (base != sp)
372                      runLocalTasks();
373 +                prevRan = ran = true;
374 +            }
375 +            else {
376 +                prevRan = ran;
377 +                ran = false;
378              }
379          }
380      }
# Line 447 | Line 453 | public class ForkJoinWorkerThread extend
453       * @param t the task. Caller must ensure non-null.
454       */
455      final void pushTask(ForkJoinTask<?> t) {
450        int s;
456          ForkJoinTask<?>[] q = queue;
457          int mask = q.length - 1; // implicit assert q != null
458 <        UNSAFE.putOrderedObject(q, (((s = sp++) & mask) << qShift) + qBase, t);
459 <        if ((s -= base) <= 0)
460 <            pool.signalWork();
461 <        else if (s + 1 >= mask)
462 <            growQueue();
458 >        int s = sp++;            // ok to increment sp before slot write
459 >        UNSAFE.putOrderedObject(q, ((s & mask) << qShift) + qBase, t);
460 >        if ((s -= base) == 0)
461 >            pool.signalWork();   // was empty
462 >        else if (s == mask)
463 >            growQueue();         // is full
464      }
465  
466      /**

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines