Commit 95f6363a authored by Sami Kyostila's avatar Sami Kyostila Committed by Commit Bot

trace_event: Don't initialize thread trace buffer during thread shutdown

If we try to record a trace event during MessageLoop shutdown, we can
get to a state where the MessageLoop is present but the thread task
runner handle has been reset. Since we require both in order to
initialize the thread local event buffer, this patch makes sure the
initialization is skipped if that condition isn't met.

Bug: 906795
Change-Id: I9ead620573387f8c329d954425ef43c60547bbef
Reviewed-on: https://chromium-review.googlesource.com/c/1343263Reviewed-by: default avatarEric Seckler <eseckler@chromium.org>
Reviewed-by: default avatarPrimiano Tucci <primiano@chromium.org>
Commit-Queue: Sami Kyöstilä <skyostil@chromium.org>
Cr-Commit-Position: refs/heads/master@{#609677}
parent 4f445ecc
...@@ -409,13 +409,15 @@ TraceLog::TraceLog() ...@@ -409,13 +409,15 @@ TraceLog::TraceLog()
TraceLog::~TraceLog() = default; TraceLog::~TraceLog() = default;
void TraceLog::InitializeThreadLocalEventBufferIfSupported() { void TraceLog::InitializeThreadLocalEventBufferIfSupported() {
// A ThreadLocalEventBuffer needs the message loop // A ThreadLocalEventBuffer needs the message loop with a task runner
// - to know when the thread exits; // - to know when the thread exits;
// - to handle the final flush. // - to handle the final flush.
// For a thread without a message loop or the message loop may be blocked, the // For a thread without a message loop or if the message loop may be blocked,
// trace events will be added into the main buffer directly. // the trace events will be added into the main buffer directly.
if (thread_blocks_message_loop_.Get() || !MessageLoopCurrent::IsSet()) if (thread_blocks_message_loop_.Get() || !MessageLoopCurrent::IsSet() ||
!ThreadTaskRunnerHandle::IsSet()) {
return; return;
}
HEAP_PROFILER_SCOPED_IGNORE; HEAP_PROFILER_SCOPED_IGNORE;
auto* thread_local_event_buffer = thread_local_event_buffer_.Get(); auto* thread_local_event_buffer = thread_local_event_buffer_.Get();
if (thread_local_event_buffer && if (thread_local_event_buffer &&
......
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