From 2e44b138f39de68b3b895c01678cd3d8fbe22f80 Mon Sep 17 00:00:00 2001 From: David Drysdale Date: Wed, 2 Dec 2020 13:17:57 -0800 Subject: [PATCH] Make CallbackManager.hasEverSetCallback atomic PiperOrigin-RevId: 345298471 --- java/arcs/core/storage/util/CallbackManager.kt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/java/arcs/core/storage/util/CallbackManager.kt b/java/arcs/core/storage/util/CallbackManager.kt index 307cc7934ce..c2b2031a050 100644 --- a/java/arcs/core/storage/util/CallbackManager.kt +++ b/java/arcs/core/storage/util/CallbackManager.kt @@ -35,7 +35,7 @@ class CallbackManager( // token for the current map and the addition of that callback and token to the map. private var callbacksMap = atomic(emptyMap>()) - private var hasEverSetCallback = false + private var hasEverSetCallback = atomic(false) val callbacks: Collection> get() = callbacksMap.value.values @@ -56,7 +56,7 @@ class CallbackManager( token = tokenGenerator(it.keys) it + (token to callback) } - hasEverSetCallback = true + hasEverSetCallback.value = true return token } @@ -86,7 +86,7 @@ class CallbackManager( /** True if no callbacks are registered, and at least one has been registered before. */ fun hasBecomeEmpty(): Boolean { - return hasEverSetCallback && callbacksMap.value.isEmpty() + return hasEverSetCallback.value && callbacksMap.value.isEmpty() } /** Remove all currently registered callbacks. */