DescriptionAvoid snapshotting ContextLifecycleObservers when iterating.
To allow safe iteration over the set of ExecutionContext observers,
a snapshot of the set was taken before iterating over it. So as to
allow observers to unregister themselves while being notified.
Apart from PostMessageTimer unregistering itself while being stop()ed,
the ContextLifecycleObservers do not mutate the observer set, hence
we can avoid the snapshot step and iterate directly over the observers.
Attempts to remove an observer while iterating is caught and
asserted for.
As the observer set is a set of weak references, some care is needed
to keep those references strong while iterating. That and other details
surrounding observer iteration is now handled by the auxiliary scope object
LifecycleNotifier<>::IterationScope.
Should the constraint of not being allowed to remove observers while
iterating prove too cumbersome, supporting lazy removal of observers
(post iteration) would be straightforward.
R=
BUG=451132
Committed: https://crrev.com/5b0b4e4f357e9348870dd5612b663a35894b49f3
Cr-Commit-Position: refs/heads/master@{#402141}
Patch Set 1 #Patch Set 2 : record removals when iterating stopped observers also #Patch Set 3 : avoid removing PostMessageTimers when stop-iterating #Patch Set 4 : just disallow all adds + removals during ContextLifecycleNotifier iterations #Patch Set 5 : tidy up further #Patch Set 6 : msvc compile fix.. #
Total comments: 5
Patch Set 7 : remove IterationScope, indirection not needed #
Messages
Total messages: 26 (15 generated)
|