Reduce synchronization for child strategy access 61/103161/1
authorRobert Varga <robert.varga@pantheon.tech>
Tue, 8 Nov 2022 18:20:57 +0000 (19:20 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Tue, 8 Nov 2022 18:20:57 +0000 (19:20 +0100)
We now have a VarHandle here, so we can use getAcquire()/setRelease()
for more relaxed happens-before ordering.

Change-Id: I46e1936cc68ba1ec6205135124e69dfc2d578ca0
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
data/yang-data-tree-ri/src/main/java/org/opendaylight/yangtools/yang/data/tree/impl/DataNodeContainerModificationStrategy.java

index a3bb05338e976740910d53e344fdc806b6c2156c..ac76ba09921fecfbce746b1d8c562bdc7d2f843d 100644 (file)
@@ -45,6 +45,7 @@ class DataNodeContainerModificationStrategy<T extends DataNodeContainer & WithSt
 
     private final @NonNull DataTreeConfiguration treeConfig;
 
+    @SuppressWarnings("unused")
     private volatile ImmutableMap<PathArgument, ModificationApplyOperation> children = ImmutableMap.of();
 
     DataNodeContainerModificationStrategy(final NormalizedNodeContainerSupport<?, ?> support, final T schema,
@@ -55,7 +56,7 @@ class DataNodeContainerModificationStrategy<T extends DataNodeContainer & WithSt
 
     @Override
     public final ModificationApplyOperation childByArg(final PathArgument arg) {
-        final var local = children;
+        final var local = (ImmutableMap<PathArgument, ModificationApplyOperation>) CHILDREN.getAcquire(this);
         final var existing = local.get(arg);
         if (existing != null) {
             return existing;
@@ -102,7 +103,7 @@ class DataNodeContainerModificationStrategy<T extends DataNodeContainer & WithSt
 
             // Attempt to install the updated map
             final var witness = (ImmutableMap<PathArgument, ModificationApplyOperation>)
-                CHILDREN.compareAndExchange(this, previous, updated);
+                CHILDREN.compareAndExchangeRelease(this, previous, updated);
             if (witness == previous) {
                 return computed;
             }