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.2 by dl, Wed Jan 7 16:07:37 2009 UTC vs.
Revision 1.3 by dl, Wed Jan 7 19:12:36 2009 UTC

# Line 524 | Line 524 | public class ForkJoinWorkerThread extend
524          while (base != sp) {
525              ForkJoinTask<?> t = deqTask();
526              if (t != null)
527 <                t.cancelIgnoreExceptions();
527 >                t.cancelIgnoringExceptions();
528          }
529      }
530  
# Line 669 | Line 669 | public class ForkJoinWorkerThread extend
669      // Support for ForkJoinTask methods
670  
671      /**
672 <     * Implements ForkJoinTask.helpJoin
672 >     * Scan, returning early if joinMe done
673       */
674 <    final int helpJoinTask(ForkJoinTask<?> joinMe) {
675 <        ForkJoinTask<?> t = null;
676 <        int s;
677 <        while ((s = joinMe.status) >= 0) {
678 <            if (t == null) {
679 <                if ((t = scan(joinMe, false)) == null)  // block if no work
680 <                    return joinMe.awaitDone(this, false);
681 <                // else recheck status before exec
682 <            }
683 <            else {
684 <                t.quietlyExec();
685 <                t = null;
686 <            }
674 >    final ForkJoinTask<?> scanWhileJoining(ForkJoinTask<?> joinMe) {
675 >        ForkJoinTask<?> t = scan(joinMe, false);
676 >        if (t != null && joinMe.status < 0 && sp == base) {
677 >            pushTask(t); // unsteal if done and this task would be stealable
678 >            t = null;
679          }
680 <        if (t != null) // unsteal
689 <            pushTask(t);
690 <        return s;
680 >        return t;
681      }
682 <
682 >    
683      /**
684       * Pops or steals a task
685       * @return task, or null if none available
686       */
687 <    final ForkJoinTask<?> getLocalOrStolenTask() {
688 <        ForkJoinTask<?> t = popTask();
689 <        return t != null? t : scan(null, false);
687 >    final ForkJoinTask<?> pollLocalOrStolenTask() {
688 >        ForkJoinTask<?> t;
689 >        return (t = popTask()) == null? scan(null, false) : t;
690      }
691  
692      /**
# Line 704 | Line 694 | public class ForkJoinWorkerThread extend
694       */
695      final void helpQuiescePool() {
696          for (;;) {
697 <            ForkJoinTask<?> t = getLocalOrStolenTask();
697 >            ForkJoinTask<?> t = pollLocalOrStolenTask();
698              if (t != null) {
699                  activate();
700                  t.quietlyExec();
# Line 723 | Line 713 | public class ForkJoinWorkerThread extend
713       * Returns an estimate of the number of tasks in the queue.
714       */
715      final int getQueueSize() {
716 <        int b = base;
727 <        int n = sp - b;
716 >        int n = sp - base;
717          return n <= 0? 0 : n; // suppress momentarily negative values
718      }
719  
# Line 733 | Line 722 | public class ForkJoinWorkerThread extend
722       * function of number of idle workers.
723       */
724      final int getEstimatedSurplusTaskCount() {
725 +        // The halving approximates weighting idle vs non-idle workers
726          return (sp - base) - (pool.getIdleThreadCount() >>> 1);
727      }
728  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines