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.101 by jsr166, Fri Dec 14 16:33:42 2012 UTC vs.
Revision 1.102 by jsr166, Sun Dec 16 18:52:27 2012 UTC

# Line 133 | Line 133 | public class FutureTask<V> implements Ru
133      }
134  
135      public boolean cancel(boolean mayInterruptIfRunning) {
136 <        if (state != NEW)
136 >        if (!(state == NEW &&
137 >              UNSAFE.compareAndSwapInt(this, stateOffset, NEW,
138 >                  mayInterruptIfRunning ? INTERRUPTING : CANCELLED)))
139              return false;
140 <        if (mayInterruptIfRunning) {
141 <            if (!UNSAFE.compareAndSwapInt(this, stateOffset, NEW, INTERRUPTING))
142 <                return false;
143 <            try {       // in case call to interrupt throws exception
144 <                Thread t = runner;
145 <                if (t != null)
146 <                    t.interrupt();
147 <            } finally { // final state
148 <                UNSAFE.putOrderedInt(this, stateOffset, INTERRUPTED);
140 >        try {    // in case call to interrupt throws exception
141 >            if (mayInterruptIfRunning) {
142 >                try {
143 >                    Thread t = runner;
144 >                    if (t != null)
145 >                        t.interrupt();
146 >                } finally { // final state
147 >                    UNSAFE.putOrderedInt(this, stateOffset, INTERRUPTED);
148 >                }
149              }
150 +        } finally {
151 +            finishCompletion();
152          }
149        else if (!UNSAFE.compareAndSwapInt(this, stateOffset, NEW, CANCELLED))
150            return false;
151        finishCompletion();
153          return true;
154      }
155  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines