Do not synchronize around ReactorStmtCtx.schemaPath 51/94951/1
authorRobert Varga <robert.varga@pantheon.tech>
Mon, 1 Feb 2021 20:06:02 +0000 (21:06 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Mon, 1 Feb 2021 20:07:03 +0000 (21:07 +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>
yang/yang-parser-reactor/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/ReactorStmtCtx.java

index a7f3941042514ddce09e8ca85b954ae8c8f3d9e4..5e9f5983e2f2e697cb465a7798414a659adc17f4 100644 (file)
@@ -154,8 +154,8 @@ abstract class ReactorStmtCtx<A, D extends DeclaredStatement<A>, E extends Effec
 
     // 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.
-    @Deprecated
-    private volatile SchemaPath schemaPath;
+    // FIXME: this should become 'QName'
+    private SchemaPath schemaPath;
 
     ReactorStmtCtx() {
         // Empty on purpose
@@ -559,19 +559,13 @@ abstract class ReactorStmtCtx<A, D extends DeclaredStatement<A>, E extends Effec
     // Exists only to support {SubstatementContext,InferredStatementContext}.schemaPath()
     @Deprecated
     final @Nullable SchemaPath substatementGetSchemaPath() {
-        SchemaPath local = schemaPath;
-        if (local == null) {
-            synchronized (this) {
-                local = schemaPath;
-                if (local == null) {
-                    schemaPath = local = createSchemaPath((StatementContextBase<?, ?, ?>) coerceParentContext());
-                }
-            }
+        if (schemaPath == null) {
+            schemaPath = createSchemaPath((StatementContextBase<?, ?, ?>) coerceParentContext());
         }
-
-        return local;
+        return schemaPath;
     }
 
+    // FIXME: 7.0.0: this method's logic needs to be moved to the respective StatementSupport classes
     @Deprecated
     private SchemaPath createSchemaPath(final StatementContextBase<?, ?, ?> parent) {
         final SchemaPath parentPath = parent.getSchemaPath();