ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/main/java/util/concurrent/FutureTask.java
(Generate patch)

Comparing jsr166/src/main/java/util/concurrent/FutureTask.java (file contents):
Revision 1.26 by dl, Wed Jan 7 01:00:50 2004 UTC vs.
Revision 1.27 by dl, Fri Jan 9 14:45:17 2004 UTC

# Line 64 | Line 64 | public class FutureTask<V> implements Fu
64      }
65  
66      public boolean isCancelled() {
67 <        return sync.doIsCancelled();
67 >        return sync.innerIsCancelled();
68      }
69      
70      public boolean isDone() {
71 <        return sync.doIsDone();
71 >        return sync.innerIsDone();
72      }
73  
74      public boolean cancel(boolean mayInterruptIfRunning) {
75 <        return sync.doCancel(mayInterruptIfRunning);
75 >        return sync.innerCancel(mayInterruptIfRunning);
76      }
77      
78      /**
# Line 88 | Line 88 | public class FutureTask<V> implements Fu
88       * while waiting
89       */
90      public V get() throws InterruptedException, ExecutionException {
91 <        return sync.doGet();
91 >        return sync.innerGet();
92      }
93  
94      /**
# Line 108 | Line 108 | public class FutureTask<V> implements Fu
108       */
109      public V get(long timeout, TimeUnit unit)
110          throws InterruptedException, ExecutionException, TimeoutException {
111 <        return sync.doGet(unit.toNanos(timeout));
111 >        return sync.innerGet(unit.toNanos(timeout));
112      }
113  
114      /**
# Line 128 | Line 128 | public class FutureTask<V> implements Fu
128       * @param v the value
129       */
130      protected void set(V v) {
131 <        sync.doSet(v);
131 >        sync.innerSet(v);
132      }
133  
134      /**
# Line 138 | Line 138 | public class FutureTask<V> implements Fu
138       * @param t the cause of failure.
139       */
140      protected void setException(Throwable t) {
141 <        sync.doSetException(t);
141 >        sync.innerSetException(t);
142      }
143      
144      /**
# Line 146 | Line 146 | public class FutureTask<V> implements Fu
146       * it has been cancelled.
147       */
148      public void run() {
149 <        sync.doRun();
149 >        sync.innerRun();
150      }
151  
152      /**
# Line 158 | Line 158 | public class FutureTask<V> implements Fu
158       * @return true if successfully run and reset
159       */
160      protected boolean runAndReset() {
161 <        return sync.doRunAndReset();
161 >        return sync.innerRunAndReset();
162      }
163  
164      /**
165       * Synchronization control for FutureTask. Note that this must be
166       * a non-static inner class in order to invoke protected
167       * <tt>done</tt> method. For clarity, all inner class support
168 <     * methods are same as outer, prefixed with "do".
168 >     * methods are same as outer, prefixed with "inner".
169       *
170       * Uses AQS sync state to represent run status
171       */
# Line 203 | Line 203 | public class FutureTask<V> implements Fu
203           * Implements AQS base acquire to succeed if ran or cancelled
204           */
205          protected int tryAcquireShared(int ignore) {
206 <            return doIsDone()? 1 : -1;
206 >            return innerIsDone()? 1 : -1;
207          }
208  
209          /**
# Line 215 | Line 215 | public class FutureTask<V> implements Fu
215              return true;
216          }
217  
218 <        boolean doIsCancelled() {
218 >        boolean innerIsCancelled() {
219              return getState() == CANCELLED;
220          }
221          
222 <        boolean doIsDone() {
222 >        boolean innerIsDone() {
223              return ranOrCancelled(getState()) && runner == null;
224          }
225  
226 <        V doGet() throws InterruptedException, ExecutionException {
226 >        V innerGet() throws InterruptedException, ExecutionException {
227              acquireSharedInterruptibly(0);
228              if (getState() == CANCELLED)
229                  throw new CancellationException();
# Line 232 | Line 232 | public class FutureTask<V> implements Fu
232              return result;
233          }
234  
235 <        V doGet(long nanosTimeout) throws InterruptedException, ExecutionException, TimeoutException {
236 <            if (!acquireSharedTimed(0, nanosTimeout))
235 >        V innerGet(long nanosTimeout) throws InterruptedException, ExecutionException, TimeoutException {
236 >            if (!acquireSharedNanos(0, nanosTimeout))
237                  throw new TimeoutException();                
238              if (getState() == CANCELLED)
239                  throw new CancellationException();
# Line 242 | Line 242 | public class FutureTask<V> implements Fu
242              return result;
243          }
244  
245 <        void doSet(V v) {
245 >        void innerSet(V v) {
246              int s = getState();
247              if (ranOrCancelled(s) || !compareAndSetState(s, RAN))
248                  return;
# Line 251 | Line 251 | public class FutureTask<V> implements Fu
251              done();
252          }
253  
254 <        void doSetException(Throwable t) {
254 >        void innerSetException(Throwable t) {
255              int s = getState();
256              if (ranOrCancelled(s) || !compareAndSetState(s, RAN))
257                  return;
# Line 261 | Line 261 | public class FutureTask<V> implements Fu
261              done();
262          }
263  
264 <        boolean doCancel(boolean mayInterruptIfRunning) {
264 >        boolean innerCancel(boolean mayInterruptIfRunning) {
265              int s = getState();
266              if (ranOrCancelled(s) || !compareAndSetState(s, CANCELLED))
267                  return false;
# Line 275 | Line 275 | public class FutureTask<V> implements Fu
275              return true;
276          }
277  
278 <        void doRun() {
278 >        void innerRun() {
279              if (!compareAndSetState(0, RUNNING))
280                  return;
281              try {
282                  runner = Thread.currentThread();
283 <                doSet(callable.call());
283 >                innerSet(callable.call());
284              } catch(Throwable ex) {
285 <                doSetException(ex);
285 >                innerSetException(ex);
286              }
287          }
288  
289 <        boolean doRunAndReset() {
289 >        boolean innerRunAndReset() {
290              if (!compareAndSetState(0, RUNNING))
291                  return false;
292              try {
# Line 295 | Line 295 | public class FutureTask<V> implements Fu
295                  runner = null;
296                  return compareAndSetState(RUNNING, 0);
297              } catch(Throwable ex) {
298 <                doSetException(ex);
298 >                innerSetException(ex);
299                  return false;
300              }
301          }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines