Commit f3c3f5a7 authored by Antonio Gomes's avatar Antonio Gomes Committed by Commit Bot

Replace HeapListHashSet with HeapLinkedHashSet in (autogen) CoreProbeSink

HeapListHashSet is deprecated in favor of HeapLinkedHashSet.

HeapLinkedHashSet's invalidate iterators when the container is
modified. It happens here that CoreProbeSink::Remove{{class_name}}
(which calls HeapLinkedHashSet<{{class_name}}>::erase) can be called
while iterating over probe_sink->{{class_name}}s(). Hence, a helper
function was added in order to perform the copy.

Note that having a helper function rather than the copy code inlined
helps with binary size matters.

R=jbroman@chromium.org
CC=​​blink-reviews-vendor@chromium.org

BUG=614112

Change-Id: I25692b867e0c32dc634b7d7f3a84877218082268
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1584109Reviewed-by: default avatarDmitry Gozman <dgozman@chromium.org>
Reviewed-by: default avatarJeremy Roman <jbroman@chromium.org>
Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Commit-Queue: Antonio Gomes <tonikitoo@igalia.com>
Cr-Commit-Position: refs/heads/master@{#654540}
parent 32ea343a
...@@ -25,6 +25,19 @@ Mutex& AgentCountMutex() { ...@@ -25,6 +25,19 @@ Mutex& AgentCountMutex() {
return mutex; return mutex;
} }
// HeapLinkedHashSet does not support modification during iteration.
// This helper copies items first so calees iterate over the copied container.
template <typename T>
HeapVector<Member<T>> CopyLinkedHashSetToVector(
const HeapLinkedHashSet<Member<T>>& linked_hash_set) {
unsigned capacity = linked_hash_set.size();
HeapVector<Member<T>> result;
result.ReserveInitialCapacity(capacity);
for (T* agent : linked_hash_set)
result.push_back(agent);
return result;
}
} // namespace } // namespace
// static // static
...@@ -101,7 +114,8 @@ namespace probe { ...@@ -101,7 +114,8 @@ namespace probe {
{% for agent in probe.agents %} {% for agent in probe.agents %}
{% set class_name = agent | agent_name_to_class %} {% set class_name = agent | agent_name_to_class %}
if (probe_sink->Has{{agent}}s()) { if (probe_sink->Has{{agent}}s()) {
for ({{class_name}}* agent : probe_sink->{{class_name}}s()) auto copy = CopyLinkedHashSetToVector(probe_sink->{{class_name}}s());
for ({{class_name}}* agent : copy)
agent->{{agent_probe_name}}({{caller()}}); agent->{{agent_probe_name}}({{caller()}});
} }
{% endfor %} {% endfor %}
......
...@@ -43,7 +43,7 @@ class {{export_symbol}} {{sink_class}} : public GarbageCollectedFinalized<{{sink ...@@ -43,7 +43,7 @@ class {{export_symbol}} {{sink_class}} : public GarbageCollectedFinalized<{{sink
{% set class_name = agent | agent_name_to_class %} {% set class_name = agent | agent_name_to_class %}
{% set getter_name = agent | to_snake_case %} {% set getter_name = agent | to_snake_case %}
bool Has{{agent}}s() const { return !{{getter_name}}s_.IsEmpty(); } bool Has{{agent}}s() const { return !{{getter_name}}s_.IsEmpty(); }
const HeapListHashSet<Member<{{class_name}}>>& {{class_name}}s() const { return {{getter_name}}s_; } const HeapLinkedHashSet<Member<{{class_name}}>>& {{class_name}}s() const { return {{getter_name}}s_; }
void Add{{agent}}({{class_name}}* agent); void Add{{agent}}({{class_name}}* agent);
void Remove{{agent}}({{class_name}}* agent); void Remove{{agent}}({{class_name}}* agent);
...@@ -57,7 +57,7 @@ class {{export_symbol}} {{sink_class}} : public GarbageCollectedFinalized<{{sink ...@@ -57,7 +57,7 @@ class {{export_symbol}} {{sink_class}} : public GarbageCollectedFinalized<{{sink
{% for agent in agents %} {% for agent in agents %}
{% set class_name = agent | agent_name_to_class %} {% set class_name = agent | agent_name_to_class %}
{% set getter_name = agent | to_snake_case %} {% set getter_name = agent | to_snake_case %}
HeapListHashSet<Member<{{class_name}}>> {{getter_name}}s_; HeapLinkedHashSet<Member<{{class_name}}>> {{getter_name}}s_;
{% endfor %} {% endfor %}
// Number of sinks with an enabled agent of each type, used to keep // Number of sinks with an enabled agent of each type, used to keep
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment