Do not synchronize around ReactorStmtCtx.schemaPath 47/95347/1
authorRobert Varga <robert.varga@pantheon.tech>
Mon, 1 Feb 2021 20:06:02 +0000 (21:06 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Wed, 24 Feb 2021 11:46:04 +0000 (12:46 +0100)
The reactor is inherently single-threaded, hence there is no point
in guarding this single field. Remove synchronization and add a few
markes for future improvement.

JIRA: YANGTOOLS-1218
Change-Id: Ic5017bb589ae5086bf8310995d7c03c80e12678a
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
(cherry picked from commit 0735f709c996762a2ac65338459c465bffc4dbcf)
(cherry picked from commit 7f41bd0651d810544aa1359ce1d762a8185df016)

yang/yang-parser-reactor/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/StatementContextBase.java

index cdf31fcf3b51b98ae72ff90318ab7febf6a3450a..1015fea02d223d0065667805630e114be2a7568a 100644 (file)
@@ -163,7 +163,7 @@ public abstract class StatementContextBase<A, D extends DeclaredStatement<A>, E
 
     // SchemaPath cache for use with SubstatementContext and InferredStatementContext. This hurts RootStatementContext
     // a bit in terms of size -- but those are only a few and SchemaPath is on its way out anyway.
-    private volatile SchemaPath schemaPath;
+    private SchemaPath schemaPath;
 
     // Copy constructor used by subclasses to implement reparent()
     StatementContextBase(final StatementContextBase<A, D, E> original) {
@@ -1046,17 +1046,10 @@ public abstract class StatementContextBase<A, D extends DeclaredStatement<A>, E
     // Exists only to support {SubstatementContext,InferredStatementContext}.getSchemaPath()
     @Deprecated
     final @NonNull Optional<SchemaPath> substatementGetSchemaPath() {
-        SchemaPath local = schemaPath;
-        if (local == null) {
-            synchronized (this) {
-                local = schemaPath;
-                if (local == null) {
-                    schemaPath = local = createSchemaPath(coerceParentContext());
-                }
-            }
+        if (schemaPath == null) {
+            schemaPath = createSchemaPath(coerceParentContext());
         }
-
-        return Optional.ofNullable(local);
+        return Optional.ofNullable(schemaPath);
     }
 
     @Deprecated