river-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From peter_firmst...@apache.org
Subject svn commit: r1481475 - /river/jtsk/skunk/qa_refactor/trunk/src/com/sun/jini/outrigger/FastList.java
Date Sun, 12 May 2013 06:30:00 GMT
Author: peter_firmstone
Date: Sun May 12 06:29:59 2013
New Revision: 1481475

URL: http://svn.apache.org/r1481475
Log:
FastList failed junit test occasionally due to iterator still finding hasNext() when all nodes
are supposed to have been removed.  Used synchronization on each node to add atomicity to
node removal operations, no more test failures were experienced.

Modified:
    river/jtsk/skunk/qa_refactor/trunk/src/com/sun/jini/outrigger/FastList.java

Modified: river/jtsk/skunk/qa_refactor/trunk/src/com/sun/jini/outrigger/FastList.java
URL: http://svn.apache.org/viewvc/river/jtsk/skunk/qa_refactor/trunk/src/com/sun/jini/outrigger/FastList.java?rev=1481475&r1=1481474&r2=1481475&view=diff
==============================================================================
--- river/jtsk/skunk/qa_refactor/trunk/src/com/sun/jini/outrigger/FastList.java (original)
+++ river/jtsk/skunk/qa_refactor/trunk/src/com/sun/jini/outrigger/FastList.java Sun May 12
06:29:59 2013
@@ -203,13 +203,15 @@ class FastList<T extends FastList.Node> 
                     /* Finished, no appropriate nodes.*/
                     break;
                 }
-                if (node.removed()) {
-                    /* Tell the base list to drop it */
-                    baseIterator.remove();
-                } else {
-                    /* Found a node to return. */
-                    result = node;
-                    break;
+                synchronized (node){
+                    if (node.removed()) {
+                        /* Tell the base list to drop it */
+                        baseIterator.remove();
+                    } else {
+                        /* Found a node to return. */
+                        result = node;
+                        break;
+                    }
                 }
             }
             return result;
@@ -247,9 +249,9 @@ class FastList<T extends FastList.Node> 
                 throw new IllegalArgumentException("Attempt to reuse node "
                         + node);
             }
+            node.setIndex(nextIndex.getAndIncrement());
+            baseQueue.add(node);
         }
-        node.setIndex(nextIndex.getAndIncrement());
-        baseQueue.add(node);
     }
 
     /**
@@ -276,16 +278,17 @@ class FastList<T extends FastList.Node> 
      * removed.
      */
     public void reap() {
-        long stopIndex = nextIndex.get();
         Iterator<T> it = baseQueue.iterator();
         while (it.hasNext()) {
             T node = it.next();
-            if (node.getIndex() >= stopIndex) {
+            if (node.getIndex() >= nextIndex.get()) {
                 // Done enough
                 return;
             }
-            if (node.removed()) {
-                it.remove();
+            synchronized (node){
+                if (node.removed()) {
+                        it.remove();
+                }
             }
         }
     }



Mime
View raw message