BUG-1886: eliminate sychronized blocks 99/11199/5
authorRobert Varga <rovarga@cisco.com>
Mon, 15 Sep 2014 13:22:13 +0000 (15:22 +0200)
committerTony Tkacik <ttkacik@cisco.com>
Wed, 22 Oct 2014 12:23:02 +0000 (14:23 +0200)
The tree state is guarded by the read-write lock, so there is no need
for the additional, overly large, critical section. This allows empty
operations to complete completely lockfree.

Change-Id: Iee01f4745a4927e6dc5093252c15d7d4e3959e9a
Signed-off-by: Robert Varga <rovarga@cisco.com>
(cherry picked from commit 66e428b873f427038424051e00d4a09e8918c667)

yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/InMemoryDataTree.java

index beed7771cecb298848dfdf95bcf8aa643fb0086b..2dd71bc0c93b2a269255ef4fad87db31a742e608 100644 (file)
@@ -44,7 +44,7 @@ final class InMemoryDataTree implements DataTree {
     }
 
     @Override
-    public synchronized void setSchemaContext(final SchemaContext newSchemaContext) {
+    public void setSchemaContext(final SchemaContext newSchemaContext) {
         Preconditions.checkNotNull(newSchemaContext);
 
         LOG.info("Attempting to install schema contexts");
@@ -81,13 +81,18 @@ final class InMemoryDataTree implements DataTree {
     @Override
     public void validate(final DataTreeModification modification) throws DataValidationFailedException {
         Preconditions.checkArgument(modification instanceof InMemoryDataTreeModification, "Invalid modification class %s", modification.getClass());
-
         final InMemoryDataTreeModification m = (InMemoryDataTreeModification)modification;
-        m.getStrategy().checkApplicable(PUBLIC_ROOT_PATH, m.getRootModification(), Optional.<TreeNode>of(rootNode));
+
+        rwLock.readLock().lock();
+        try {
+            m.getStrategy().checkApplicable(PUBLIC_ROOT_PATH, m.getRootModification(), Optional.<TreeNode>of(rootNode));
+        } finally {
+            rwLock.readLock().unlock();
+        }
     }
 
     @Override
-    public synchronized DataTreeCandidate prepare(final DataTreeModification modification) {
+    public DataTreeCandidate prepare(final DataTreeModification modification) {
         Preconditions.checkArgument(modification instanceof InMemoryDataTreeModification, "Invalid modification class %s", modification.getClass());
 
         final InMemoryDataTreeModification m = (InMemoryDataTreeModification)modification;
@@ -100,7 +105,7 @@ final class InMemoryDataTree implements DataTree {
         rwLock.writeLock().lock();
         try {
             final Optional<TreeNode> newRoot = m.getStrategy().apply(m.getRootModification(),
-                    Optional.<TreeNode>of(rootNode), m.getVersion());
+                Optional.<TreeNode>of(rootNode), m.getVersion());
             Preconditions.checkState(newRoot.isPresent(), "Apply strategy failed to produce root node");
             return new InMemoryDataTreeCandidate(PUBLIC_ROOT_PATH, root, rootNode, newRoot.get());
         } finally {
@@ -109,7 +114,7 @@ final class InMemoryDataTree implements DataTree {
     }
 
     @Override
-    public synchronized void commit(final DataTreeCandidate candidate) {
+    public void commit(final DataTreeCandidate candidate) {
         if (candidate instanceof NoopDataTreeCandidate) {
             return;
         }