Skip to content

Commit

Permalink
Make CallbackManager.hasEverSetCallback atomic
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 345298471
  • Loading branch information
daviddrysdale authored and arcs-c3po committed Dec 2, 2020
1 parent 84fc7ee commit 2e44b13
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions java/arcs/core/storage/util/CallbackManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class CallbackManager<T>(
// token for the current map and the addition of that callback and token to the map.
private var callbacksMap = atomic(emptyMap<Int, Callback<T>>())

private var hasEverSetCallback = false
private var hasEverSetCallback = atomic(false)

val callbacks: Collection<Callback<T>>
get() = callbacksMap.value.values
Expand All @@ -56,7 +56,7 @@ class CallbackManager<T>(
token = tokenGenerator(it.keys)
it + (token to callback)
}
hasEverSetCallback = true
hasEverSetCallback.value = true
return token
}

Expand Down Expand Up @@ -86,7 +86,7 @@ class CallbackManager<T>(

/** 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. */
Expand Down

0 comments on commit 2e44b13

Please sign in to comment.