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

Comparing jsr166/src/jsr166y/ForkJoinTask.java (file contents):
Revision 1.53 by dl, Wed Aug 11 18:45:12 2010 UTC vs.
Revision 1.56 by jsr166, Sat Sep 4 00:21:31 2010 UTC

# Line 205 | Line 205 | public abstract class ForkJoinTask<V> im
205      }
206  
207      /**
208 <     * Record exception and set exceptional completion
208 >     * Records exception and sets exceptional completion.
209 >     *
210       * @return status on exit
211       */
212      private void setExceptionalCompletion(Throwable rex) {
# Line 214 | Line 215 | public abstract class ForkJoinTask<V> im
215      }
216  
217      /**
218 <     * Blocks a worker thread until completion. Called only by pool.
218 >     * Blocks a worker thread until completion. Called only by
219 >     * pool. Currently unused -- pool-based waits use timeout
220 >     * version below.
221       */
222      final void internalAwaitDone() {
223          int s;         // the odd construction reduces lock bias effects
# Line 231 | Line 234 | public abstract class ForkJoinTask<V> im
234      }
235  
236      /**
237 +     * Blocks a worker thread until completed or timed out.  Called
238 +     * only by pool.
239 +     *
240 +     * @return status on exit
241 +     */
242 +    final int internalAwaitDone(long millis) {
243 +        int s;
244 +        if ((s = status) >= 0) {
245 +            try {
246 +                synchronized(this) {
247 +                    if (UNSAFE.compareAndSwapInt(this, statusOffset, s,SIGNAL))
248 +                        wait(millis, 0);
249 +                }
250 +            } catch (InterruptedException ie) {
251 +                cancelIfTerminating();
252 +            }
253 +            s = status;
254 +        }
255 +        return s;
256 +    }
257 +
258 +    /**
259       * Blocks a non-worker-thread until completion.
260       */
261      private void externalAwaitDone() {
# Line 314 | Line 339 | public abstract class ForkJoinTask<V> im
339  
340      /**
341       * Commences performing this task, awaits its completion if
342 <     * necessary, and return its result, or throws an (unchecked)
342 >     * necessary, and returns its result, or throws an (unchecked)
343       * exception if the underlying computation did so.
344       *
345       * @return the computed result
# Line 510 | Line 535 | public abstract class ForkJoinTask<V> im
535      }
536  
537      /**
538 <     * Cancels ignoring exceptions if worker is terminating
538 >     * Cancels if current thread is a terminating worker thread,
539 >     * ignoring any exceptions thrown by cancel.
540       */
541      final void cancelIfTerminating() {
542          Thread t = Thread.currentThread();
# Line 643 | Line 669 | public abstract class ForkJoinTask<V> im
669           */
670          boolean interrupted = false;
671          boolean dec = false; // true if pool count decremented
672 +        long nanos = unit.toNanos(timeout);
673          for (;;) {
674              if (Thread.interrupted() && pool == null) {
675                  interrupted = true;
# Line 653 | Line 680 | public abstract class ForkJoinTask<V> im
680                  break;
681              if (UNSAFE.compareAndSwapInt(this, statusOffset, s, SIGNAL)) {
682                  long startTime = System.nanoTime();
656                long nanos = unit.toNanos(timeout);
683                  long nt; // wait time
684                  while (status >= 0 &&
685                         (nt = nanos - (System.nanoTime() - startTime)) > 0) {
# Line 1069 | Line 1095 | public abstract class ForkJoinTask<V> im
1095      private static final long serialVersionUID = -7721805057305804111L;
1096  
1097      /**
1098 <     * Saves the state to a stream.
1098 >     * Saves the state to a stream (that is, serializes it).
1099       *
1100       * @serialData the current run status and the exception thrown
1101       * during execution, or {@code null} if none
# Line 1082 | Line 1108 | public abstract class ForkJoinTask<V> im
1108      }
1109  
1110      /**
1111 <     * Reconstitutes the instance from a stream.
1111 >     * Reconstitutes the instance from a stream (that is, deserializes it).
1112       *
1113       * @param s the stream
1114       */

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines