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>
@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");
}
-
}
+