geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ga...@apache.org
Subject svn commit: r679860 - /geronimo/server/trunk/plugins/concurrent/geronimo-concurrent-core/src/main/java/org/apache/geronimo/concurrent/harmony/FutureTask.java
Date Fri, 25 Jul 2008 17:14:21 GMT
Author: gawor
Date: Fri Jul 25 10:14:20 2008
New Revision: 679860

URL: http://svn.apache.org/viewvc?rev=679860&view=rev
Log:
in rare circumstances FutureTask.cancel() did not actaully cancel the task

Modified:
    geronimo/server/trunk/plugins/concurrent/geronimo-concurrent-core/src/main/java/org/apache/geronimo/concurrent/harmony/FutureTask.java

Modified: geronimo/server/trunk/plugins/concurrent/geronimo-concurrent-core/src/main/java/org/apache/geronimo/concurrent/harmony/FutureTask.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/concurrent/geronimo-concurrent-core/src/main/java/org/apache/geronimo/concurrent/harmony/FutureTask.java?rev=679860&r1=679859&r2=679860&view=diff
==============================================================================
--- geronimo/server/trunk/plugins/concurrent/geronimo-concurrent-core/src/main/java/org/apache/geronimo/concurrent/harmony/FutureTask.java
(original)
+++ geronimo/server/trunk/plugins/concurrent/geronimo-concurrent-core/src/main/java/org/apache/geronimo/concurrent/harmony/FutureTask.java
Fri Jul 25 10:14:20 2008
@@ -173,6 +173,7 @@
      * Uses AQS sync state to represent run status
      */
     private final class Sync extends AbstractQueuedSynchronizer {
+        private static final int READY     = 0;
         /** State value representing that task is running */
         private static final int RUNNING   = 1;
         /** State value representing that task ran */
@@ -254,18 +255,30 @@
         }
 
         void innerSet(V v) {
-            int s = getState();
-            if (ranOrCancelled(s) || !compareAndSetState(s, RAN))
-                return;
+            for (;;) {
+                int s = getState();
+                if (ranOrCancelled(s)) {
+                    return;
+                }
+                if (compareAndSetState(s, RAN)) {
+                    break;
+                }
+            }
             result = v;
             releaseShared(0);
             done();
         }
 
         void innerSetException(Throwable t) {
-            int s = getState();
-            if (ranOrCancelled(s) || !compareAndSetState(s, RAN)) 
-                return;
+            for (;;) {
+                int s = getState();
+                if (ranOrCancelled(s)) {
+                    return;
+                } 
+                if (compareAndSetState(s, RAN)) {
+                    break;
+                }
+            }            
             exception = t;
             result = null;
             releaseShared(0);
@@ -273,9 +286,15 @@
         }
 
         boolean innerCancel(boolean mayInterruptIfRunning) {
-            int s = getState();
-            if (ranOrCancelled(s) || !compareAndSetState(s, CANCELLED)) 
-                return false;
+            for (;;) {
+                int s = getState();
+                if (ranOrCancelled(s)) {
+                    return false;
+                }
+                if (compareAndSetState(s, CANCELLED)) {
+                    break;
+                }
+            }
             if (mayInterruptIfRunning) {
                 Thread r = runner;
                 if (r != null)
@@ -291,16 +310,21 @@
         }
         
         boolean innerSetSkipped() {
-            int s = getState();
-            if (ranOrCancelled(s) || !compareAndSetState(s, SKIPPED)) {
-                return false;
+            for (;;) {
+                int s = getState();
+                if (ranOrCancelled(s)) {
+                    return false;
+                } 
+                if (compareAndSetState(s, SKIPPED)) {
+                    break;
+                }              
             }
             releaseShared(0);
             return true;
         }
 
         void innerRun() {
-            if (!compareAndSetState(0, RUNNING)) 
+            if (!compareAndSetState(READY, RUNNING)) 
                 return;
             try {
                 taskStart();
@@ -315,14 +339,14 @@
         }
 
         boolean innerRunAndReset() {
-            if (!(compareAndSetState(0, RUNNING) || compareAndSetState(SKIPPED, RUNNING)))
 
+            if (!(compareAndSetState(READY, RUNNING) || compareAndSetState(SKIPPED, RUNNING)))
 
                 return false;
             try {
                 taskStart();
                 runner = Thread.currentThread();
                 callable.call(); // don't set result
                 runner = null;                
-                boolean rs = compareAndSetState(RUNNING, 0);
+                boolean rs = compareAndSetState(RUNNING, READY);
                 taskDone(null);
                 return rs;
             } catch(Throwable ex) {                



Mime
View raw message