Use compareAndExchange() to set closeFuture 50/109250/1
authorRobert Varga <robert.varga@pantheon.tech>
Sat, 9 Dec 2023 10:51:14 +0000 (11:51 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Sat, 9 Dec 2023 10:51:14 +0000 (11:51 +0100)
Java 9+ gives us a convenient way to ensure null-safety in this CAS
operation -- compareAndExchange() returns the witness value, i.e.
we get the value instead of a plain boolean false.

Change-Id: I636b0f084170d42bbd99490577917afefe5145e2
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
singleton-service/mdsal-singleton-dom-impl/src/main/java/org/opendaylight/mdsal/singleton/dom/impl/ActiveServiceGroup.java

index 78e50149db474c015772a0fa39c2ff403a67f551..457474c112dd15f4f0d6fc5b46b444924eef0ba6 100644 (file)
@@ -294,8 +294,9 @@ final class ActiveServiceGroup extends ServiceGroup {
 
     private synchronized @NonNull ListenableFuture<?> destroyGroup() {
         final var future = SettableFuture.<Void>create();
-        if (!closeFuture.compareAndSet(null, future)) {
-            return verifyNotNull(closeFuture.get());
+        final var witness = closeFuture.compareAndExchange(null, future);
+        if (witness != null) {
+            return witness;
         }
 
         if (serviceEntityReg != null) {