X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=third-party%2Ftriemap%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fyangtools%2Ftriemap%2FINode.java;h=b9444056876d93c38ee35dc85b65e2405996a18e;hb=2b5b2411748ae74d0f98fb6ffc2ec853d52048a5;hp=2a59f01afea4e73a3eda6f00738851f10ace1975;hpb=f8f2e5ba4e6ca2c6bbcd3599142cef4647d4c7b2;p=yangtools.git diff --git a/third-party/triemap/src/main/java/org/opendaylight/yangtools/triemap/INode.java b/third-party/triemap/src/main/java/org/opendaylight/yangtools/triemap/INode.java index 2a59f01afe..b944405687 100644 --- a/third-party/triemap/src/main/java/org/opendaylight/yangtools/triemap/INode.java +++ b/third-party/triemap/src/main/java/org/opendaylight/yangtools/triemap/INode.java @@ -47,55 +47,50 @@ final class INode extends INodeBase { while (true) { if (m == null) { return null; - } else { - // complete the GCAS - final MainNode prev = /* READ */ m.READ_PREV(); - INode ctr = ct.readRoot(true); + } - if (prev == null) { - return m; + // complete the GCAS + final MainNode prev = /* READ */ m.READ_PREV(); + final INode ctr = ct.readRoot(true); + if (prev == null) { + return m; + } + + if (prev instanceof FailedNode) { + // try to commit to previous value + FailedNode fn = (FailedNode) prev; + if (CAS(m, fn.READ_PREV())) { + return fn.READ_PREV(); } - if (prev instanceof FailedNode) { - // try to commit to previous value - FailedNode fn = (FailedNode) prev; - if (CAS(m, fn.READ_PREV())) { - return fn.READ_PREV(); - } else { - // Tailrec - // return GCAS_Complete (/* READ */mainnode, ct); - m = /* READ */ READ(); - continue; - } - } else { - // Assume that you've read the root from the generation - // G. - // Assume that the snapshot algorithm is correct. - // ==> you can only reach nodes in generations <= G. - // ==> `gen` is <= G. - // We know that `ctr.gen` is >= G. - // ==> if `ctr.gen` = `gen` then they are both equal to - // G. - // ==> otherwise, we know that either `ctr.gen` > G, - // `gen` < - // G, - // or both - if ((ctr.gen == gen) && ct.nonReadOnly()) { - // try to commit - if (m.CAS_PREV(prev, null)) { - return m; - } else { - // return GCAS_Complete (m, ct); - // tailrec - continue; - } - } else { - // try to abort - m.CAS_PREV(prev, new FailedNode<>(prev)); - return GCAS_Complete(/* READ */ READ(), ct); - } + // Tail recursion: return GCAS_Complete (/* READ */ READ(), ct); + m = /* READ */ READ(); + continue; + } + + // Assume that you've read the root from the generation G. + // Assume that the snapshot algorithm is correct. + // ==> you can only reach nodes in generations <= G. + // ==> `gen` is <= G. + // We know that `ctr.gen` is >= G. + // ==> if `ctr.gen` = `gen` then they are both equal to G. + // ==> otherwise, we know that either `ctr.gen` > G, `gen` < G, + // or both + if ((ctr.gen == gen) && ct.nonReadOnly()) { + // try to commit + if (m.CAS_PREV(prev, null)) { + return m; } + + // Tail recursion: return GCAS_Complete (m, ct); + continue; } + + // try to abort + m.CAS_PREV(prev, new FailedNode<>(prev)); + + // Tail recursion: return GCAS_Complete(/* READ */ READ(), ct); + m = /* READ */ READ(); } }