BUG-650: clarify TransactionFactory close state handling 24/11124/5
authorRobert Varga <rovarga@cisco.com>
Fri, 12 Sep 2014 21:45:02 +0000 (23:45 +0200)
committerRobert Varga <rovarga@cisco.com>
Sun, 14 Sep 2014 12:53:47 +0000 (14:53 +0200)
getAndSet() translates to a get() + compareAndSet(). We already know the
expected value, so we can skip the first bit. The nice thing is that CAS
will readily give us a boolean, so the code becomes a bit more clear,
too.

Change-Id: Id77dcefb7ba85512fcebbcae7f43f08cd8094fbc
Signed-off-by: Robert Varga <rovarga@cisco.com>
opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/md/sal/dom/broker/impl/AbstractDOMForwardedTransactionFactory.java

index 6838e39093abcf35f6ad3d1e06894d8a346b46b5..8ef60a43d47a0872892b3c360f0836d2c9322141 100644 (file)
@@ -212,8 +212,8 @@ abstract class AbstractDOMForwardedTransactionFactory<T extends DOMStoreTransact
 
     @Override
     public void close() {
-        final int wasClosed = UPDATER.getAndSet(this, 1);
-        Preconditions.checkState(wasClosed == 0, "Transaction factory was already closed");
+        final boolean success = UPDATER.compareAndSet(this, 0, 1);
+        Preconditions.checkState(success, "Transaction factory was already closed");
     }
-
 }
+