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.10 by jsr166, Mon Jul 20 23:07:43 2009 UTC vs.
Revision 1.11 by jsr166, Tue Jul 21 00:15:14 2009 UTC

# Line 205 | Line 205 | public class ForkJoinWorkerThread extend
205  
206      /**
207       * Creates a ForkJoinWorkerThread operating in the given pool.
208 +     *
209       * @param pool the pool this thread works in
210       * @throws NullPointerException if pool is null
211       */
# Line 218 | Line 219 | public class ForkJoinWorkerThread extend
219      // Public access methods
220  
221      /**
222 <     * Returns the pool hosting this thread
222 >     * Returns the pool hosting this thread.
223 >     *
224       * @return the pool
225       */
226      public ForkJoinPool getPool() {
# Line 231 | Line 233 | public class ForkJoinWorkerThread extend
233       * threads (minus one) that have ever been created in the pool.
234       * This method may be useful for applications that track status or
235       * collect results per-worker rather than per-task.
236 <     * @return the index number.
236 >     *
237 >     * @return the index number
238       */
239      public int getPoolIndex() {
240          return poolIndex;
# Line 240 | Line 243 | public class ForkJoinWorkerThread extend
243      /**
244       * Establishes local first-in-first-out scheduling mode for forked
245       * tasks that are never joined.
246 +     *
247       * @param async if true, use locally FIFO scheduling
248       */
249      void setAsyncMode(boolean async) {
# Line 261 | Line 265 | public class ForkJoinWorkerThread extend
265      final boolean shutdownNow()   { return transitionRunStateTo(TERMINATING); }
266  
267      /**
268 <     * Transition to at least the given state. Return true if not
269 <     * already at least given state.
268 >     * Transitions to at least the given state.  Returns true if not
269 >     * already at least at given state.
270       */
271      private boolean transitionRunStateTo(int state) {
272          for (;;) {
# Line 275 | Line 279 | public class ForkJoinWorkerThread extend
279      }
280  
281      /**
282 <     * Try to set status to active; fail on contention
282 >     * Tries to set status to active; fails on contention.
283       */
284      private boolean tryActivate() {
285          if (!active) {
# Line 287 | Line 291 | public class ForkJoinWorkerThread extend
291      }
292  
293      /**
294 <     * Try to set status to active; fail on contention
294 >     * Tries to set status to active; fails on contention.
295       */
296      private boolean tryInactivate() {
297          if (active) {
# Line 299 | Line 303 | public class ForkJoinWorkerThread extend
303      }
304  
305      /**
306 <     * Computes next value for random victim probe. Scans don't
306 >     * Computes next value for random victim probe.  Scans don't
307       * require a very high quality generator, but also not a crummy
308 <     * one. Marsaglia xor-shift is cheap and works well.
308 >     * one.  Marsaglia xor-shift is cheap and works well.
309       */
310      private static int xorShift(int r) {
311          r ^= r << 1;
# Line 331 | Line 335 | public class ForkJoinWorkerThread extend
335      }
336  
337      /**
338 <     * Execute tasks until shut down.
338 >     * Executes tasks until shut down.
339       */
340      private void mainLoop() {
341          while (!isShutdown()) {
# Line 363 | Line 367 | public class ForkJoinWorkerThread extend
367      }
368  
369      /**
370 <     * Perform cleanup associated with termination of this worker
370 >     * Performs cleanup associated with termination of this worker
371       * thread.  If you override this method, you must invoke
372       * super.onTermination at the end of the overridden method.
373       *
374       * @param exception the exception causing this thread to abort due
375 <     * to an unrecoverable error, or null if completed normally.
375 >     * to an unrecoverable error, or null if completed normally
376       */
377      protected void onTermination(Throwable exception) {
378          // Execute remaining local tasks unless aborting or terminating
# Line 428 | Line 432 | public class ForkJoinWorkerThread extend
432  
433      /**
434       * Pushes a task. Called only by current thread.
435 +     *
436       * @param t the task. Caller must ensure non-null.
437       */
438      final void pushTask(ForkJoinTask<?> t) {
# Line 445 | Line 450 | public class ForkJoinWorkerThread extend
450      /**
451       * Tries to take a task from the base of the queue, failing if
452       * either empty or contended.
453 <     * @return a task, or null if none or contended.
453 >     *
454 >     * @return a task, or null if none or contended
455       */
456      final ForkJoinTask<?> deqTask() {
457          ForkJoinTask<?> t;
# Line 487 | Line 493 | public class ForkJoinWorkerThread extend
493       * Specialized version of popTask to pop only if
494       * topmost element is the given task. Called only
495       * by current thread while active.
496 <     * @param t the task. Caller must ensure non-null
496 >     *
497 >     * @param t the task. Caller must ensure non-null.
498       */
499      final boolean unpushTask(ForkJoinTask<?> t) {
500          ForkJoinTask<?>[] q = queue;
# Line 587 | Line 594 | public class ForkJoinWorkerThread extend
594      }
595  
596      /**
597 <     * gets and removes a local or stolen a task
597 >     * Gets and removes a local or stolen task.
598 >     *
599       * @return a task, if available
600       */
601      final ForkJoinTask<?> pollTask() {
# Line 598 | Line 606 | public class ForkJoinWorkerThread extend
606      }
607  
608      /**
609 <     * gets a local task
609 >     * Gets a local task.
610 >     *
611       * @return a task, if available
612       */
613      final ForkJoinTask<?> pollLocalTask() {
# Line 607 | Line 616 | public class ForkJoinWorkerThread extend
616  
617      /**
618       * Returns a pool submission, if one exists, activating first.
619 +     *
620       * @return a submission, if available
621       */
622      private ForkJoinTask<?> pollSubmission() {
# Line 632 | Line 642 | public class ForkJoinWorkerThread extend
642      }
643  
644      /**
645 <     * Drains tasks to given collection c
645 >     * Drains tasks to given collection c.
646 >     *
647       * @return the number of tasks drained
648       */
649      final int drainTasksTo(Collection<ForkJoinTask<?>> c) {
# Line 646 | Line 657 | public class ForkJoinWorkerThread extend
657      }
658  
659      /**
660 <     * Get and clear steal count for accumulation by pool.  Called
660 >     * Gets and clears steal count for accumulation by pool.  Called
661       * only when known to be idle (in pool.sync and termination).
662       */
663      final int getAndClearStealCount() {
# Line 694 | Line 705 | public class ForkJoinWorkerThread extend
705      }
706  
707      /**
708 <     * Scan, returning early if joinMe done
708 >     * Scans, returning early if joinMe done
709       */
710      final ForkJoinTask<?> scanWhileJoining(ForkJoinTask<?> joinMe) {
711          ForkJoinTask<?> t = pollTask();
# Line 706 | Line 717 | public class ForkJoinWorkerThread extend
717      }
718  
719      /**
720 <     * Runs tasks until pool isQuiescent
720 >     * Runs tasks until pool isQuiescent.
721       */
722      final void helpQuiescePool() {
723          for (;;) {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines