BUG-7464: update INode.GCAS_Complete() 96/50296/2
authorRobert Varga <rovarga@cisco.com>
Wed, 11 Jan 2017 00:43:49 +0000 (01:43 +0100)
committerRobert Varga <nite@hq.sk>
Fri, 13 Jan 2017 15:29:12 +0000 (15:29 +0000)
Undo previous read on INode generation. It makes the the code
read a bit clunky, as the context of reasoning about the root
INode is lost.

While we're here, improve code readability with explicit
while(m != null) instead of a while(true)/if(m != null).

Change-Id: I01dde9603ff6fec98845036742375f3c5524ba00
Signed-off-by: Robert Varga <rovarga@cisco.com>
third-party/triemap/src/main/java/org/opendaylight/yangtools/triemap/INode.java

index eb0d895865c94fa164d0f93f33411ed6dfe679dd..23046ed0e835f5148c6003ce2b14708ee4666ff5 100644 (file)
@@ -53,15 +53,12 @@ final class INode<K, V> extends BasicNode {
         return GCAS_Complete(m, ct);
     }
 
-    private MainNode<K, V> GCAS_Complete(MainNode<K, V> m, final TrieMap<?, ?> ct) {
-        while (true) {
-            if (m == null) {
-                return null;
-            }
-
+    private MainNode<K, V> GCAS_Complete(final MainNode<K, V> oldmain, final TrieMap<?, ?> ct) {
+        MainNode<K, V> m = oldmain;
+        while (m != null) {
             // complete the GCAS
             final MainNode<K, V> prev = /* READ */ m.READ_PREV();
-            final Gen rdgen = ct.readRoot(true).gen;
+            final INode<?, ?> ctr = ct.readRoot(true);
             if (prev == null) {
                 return m;
             }
@@ -86,7 +83,7 @@ final class INode<K, V> extends BasicNode {
             // ==> if `ctr.gen` = `gen` then they are both equal to G.
             // ==> otherwise, we know that either `ctr.gen` > G, `gen` < G,
             // or both
-            if (rdgen == gen && !ct.isReadOnly()) {
+            if (ctr.gen == gen && !ct.isReadOnly()) {
                 // try to commit
                 if (m.CAS_PREV(prev, null)) {
                     return m;
@@ -102,6 +99,8 @@ final class INode<K, V> extends BasicNode {
             // Tail recursion: return GCAS_Complete(/* READ */ mainnode, ct);
             m = /* READ */ mainnode;
         }
+
+        return null;
     }
 
     private boolean GCAS(final MainNode<K, V> old, final MainNode<K, V> n, final TrieMap<?, ?> ct) {