|
| 1 | +/* |
| 2 | + * Scala (https://www.scala-lang.org) |
| 3 | + * |
| 4 | + * Copyright EPFL and Lightbend, Inc. |
| 5 | + * |
| 6 | + * Licensed under Apache License 2.0 |
| 7 | + * (http://www.apache.org/licenses/LICENSE-2.0). |
| 8 | + * |
| 9 | + * See the NOTICE file distributed with this work for |
| 10 | + * additional information regarding copyright ownership. |
| 11 | + */ |
| 12 | + |
| 13 | +package scala.collection.concurrent; |
| 14 | + |
| 15 | +import java.util.concurrent.atomic.AtomicReferenceFieldUpdater; |
| 16 | + |
| 17 | +abstract class MainNode<K, V> extends BasicNode { |
| 18 | + |
| 19 | + @SuppressWarnings("unchecked") |
| 20 | + public static final AtomicReferenceFieldUpdater<MainNode<?, ?>, MainNode<?, ?>> updater = |
| 21 | + AtomicReferenceFieldUpdater.newUpdater((Class<MainNode<?, ?>>) (Class<?>) MainNode.class, (Class<MainNode<?, ?>>) (Class<?>) MainNode.class, "prev"); |
| 22 | + |
| 23 | + public volatile MainNode<K, V> prev = null; |
| 24 | + |
| 25 | + public abstract int cachedSize(Object ct); |
| 26 | + |
| 27 | + // standard contract |
| 28 | + public abstract int knownSize(); |
| 29 | + |
| 30 | + public boolean CAS_PREV(MainNode<K, V> oldval, MainNode<K, V> nval) { |
| 31 | + return updater.compareAndSet(this, oldval, nval); |
| 32 | + } |
| 33 | + |
| 34 | + public void WRITE_PREV(MainNode<K, V> nval) { |
| 35 | + updater.set(this, nval); |
| 36 | + } |
| 37 | + |
| 38 | + // do we need this? unclear in the javadocs... |
| 39 | + // apparently not - volatile reads are supposed to be safe |
| 40 | + // regardless of whether there are concurrent ARFU updates |
| 41 | + @Deprecated @SuppressWarnings("unchecked") |
| 42 | + public MainNode<K, V> READ_PREV() { |
| 43 | + return (MainNode<K, V>) updater.get(this); |
| 44 | + } |
| 45 | + |
| 46 | +} |
0 commit comments