BUG-5222: Optimize use of declared substatements
[yangtools.git] / third-party / triemap / src / main / java / org / opendaylight / yangtools / triemap / MainNode.java
1 /*                     __                                               *\
2  **     ________ ___   / /  ___     Scala API                            **
3  **    / __/ __// _ | / /  / _ |    (c) 2003-2012, LAMP/EPFL             **
4  **  __\ \/ /__/ __ |/ /__/ __ |    http://scala-lang.org/               **
5  ** /____/\___/_/ |_/____/_/ | |                                         **
6  **                          |/                                          **
7 \*                                                                      */
8
9 package org.opendaylight.yangtools.triemap;
10
11 import java.util.concurrent.atomic.AtomicReferenceFieldUpdater;
12
13 abstract class MainNode<K, V> extends BasicNode {
14
15     public static final AtomicReferenceFieldUpdater<MainNode, MainNode> updater = AtomicReferenceFieldUpdater.newUpdater (MainNode.class, MainNode.class, "prev");
16
17     public volatile MainNode<K, V> prev = null;
18
19     public abstract int cachedSize (Object ct);
20
21     public boolean CAS_PREV (MainNode<K, V> oldval, MainNode<K, V> nval) {
22         return updater.compareAndSet (this, oldval, nval);
23     }
24
25     public void WRITE_PREV (MainNode<K, V> nval) {
26         updater.set (this, nval);
27     }
28
29     // do we need this? unclear in the javadocs...
30     // apparently not - volatile reads are supposed to be safe
31     // regardless of whether there are concurrent ARFU updates
32     public MainNode<K, V> READ_PREV () {
33         return updater.get (this);
34     }
35
36 }