Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(518)

Issue 1916843003: Ensure Origin Thread Affinity for BlameContext (Closed)

Created:
4 years, 8 months ago by Xiaocheng
Modified:
4 years, 7 months ago
CC:
chromium-reviews, tracing+reviews_chromium.org, wfh+watch_chromium.org
Base URL:
https://chromium.googlesource.com/chromium/src.git@master
Target Ref:
refs/pending/heads/master
Project:
chromium
Visibility:
Public.

Description

Ensure Origin Thread Affinity for BlameContext Currently, it is possible that instances of BlameContext (and its subclasses) to be created and managed in one thread, but its callbacks OnTraceLogEnabled() and OnTraceLogDisabled() are called in a different one, which potentially causes threading issues. This patch sets new policies to ensure thread safety: 1. The two callbacks, when called from a different thread, must post tasks to the thread where the instance was created, instead of doing their business directly; 2. BlameContext and any of its subclasses must remove itself from TraceLog's observer list at the beginning of destruction, so that the destructor does not race with the callbacks. BUG=546021

Patch Set 1 #

Patch Set 2 : Add MessageLoop to BlameContextTest #

Patch Set 3 : Error fix #

Total comments: 7

Patch Set 4 : Use origin thread affinity #

Total comments: 2

Patch Set 5 : Introduce UnregisterFromTraceLog() to prevent racing with dtor #

Patch Set 6 : Apply UnregisterFromTraceLog() to subclasses #

Patch Set 7 : Fix windows bot compile error #

Unified diffs Side-by-side diffs Delta from patch set Stats (+120 lines, -8 lines) Patch
M base/trace_event/blame_context.h View 1 2 3 4 5 chunks +32 lines, -0 lines 0 comments Download
M base/trace_event/blame_context.cc View 1 2 3 4 5 chunks +26 lines, -5 lines 0 comments Download
M base/trace_event/blame_context_unittest.cc View 1 2 3 4 5 6 4 chunks +52 lines, -0 lines 0 comments Download
M components/scheduler/base/task_queue_manager_unittest.cc View 1 2 2 chunks +2 lines, -2 lines 0 comments Download
M content/renderer/frame_blame_context.cc View 1 2 3 4 5 1 chunk +3 lines, -1 line 0 comments Download
M content/renderer/top_level_blame_context.h View 1 2 3 4 5 1 chunk +1 line, -0 lines 0 comments Download
M content/renderer/top_level_blame_context.cc View 1 2 3 4 5 1 chunk +4 lines, -0 lines 0 comments Download

Depends on Patchset:

Messages

Total messages: 17 (4 generated)
Xiaocheng
PTAL. This patch is made following the discussion in [1]. After this patch gets landed ...
4 years, 8 months ago (2016-04-26 10:49:47 UTC) #2
Sami
Thanks for the quick fix! One suggestion below. https://codereview.chromium.org/1916843003/diff/40001/base/trace_event/blame_context.cc File base/trace_event/blame_context.cc (right): https://codereview.chromium.org/1916843003/diff/40001/base/trace_event/blame_context.cc#newcode78 base/trace_event/blame_context.cc:78: // ...
4 years, 8 months ago (2016-04-26 11:00:32 UTC) #3
Xiaocheng
Thanks for the review. The patch is revised accordingly. PTAL. https://codereview.chromium.org/1916843003/diff/40001/base/trace_event/blame_context.cc File base/trace_event/blame_context.cc (right): https://codereview.chromium.org/1916843003/diff/40001/base/trace_event/blame_context.cc#newcode78 ...
4 years, 8 months ago (2016-04-26 12:48:21 UTC) #5
Sami
Thanks, lgtm. https://codereview.chromium.org/1916843003/diff/40001/base/trace_event/blame_context.cc File base/trace_event/blame_context.cc (right): https://codereview.chromium.org/1916843003/diff/40001/base/trace_event/blame_context.cc#newcode80 base/trace_event/blame_context.cc:80: // a different thread safely without worrying ...
4 years, 8 months ago (2016-04-26 12:57:13 UTC) #6
Primiano Tucci (use gerrit)
https://codereview.chromium.org/1916843003/diff/60001/base/trace_event/blame_context.cc File base/trace_event/blame_context.cc (right): https://codereview.chromium.org/1916843003/diff/60001/base/trace_event/blame_context.cc#newcode88 base/trace_event/blame_context.cc:88: task_runner_->PostTask(FROM_HERE, Bind(&BlameContext::TakeSnapshot, What happens in the case that BlameContext ...
4 years, 8 months ago (2016-04-26 15:32:15 UTC) #8
Sami
https://codereview.chromium.org/1916843003/diff/60001/base/trace_event/blame_context.cc File base/trace_event/blame_context.cc (right): https://codereview.chromium.org/1916843003/diff/60001/base/trace_event/blame_context.cc#newcode88 base/trace_event/blame_context.cc:88: task_runner_->PostTask(FROM_HERE, Bind(&BlameContext::TakeSnapshot, On 2016/04/26 15:32:15, Primiano Tucci wrote: > ...
4 years, 8 months ago (2016-04-26 15:45:26 UTC) #9
Primiano Tucci (use gerrit)
On 2016/04/26 15:45:26, Sami wrote: > https://codereview.chromium.org/1916843003/diff/60001/base/trace_event/blame_context.cc > File base/trace_event/blame_context.cc (right): > > https://codereview.chromium.org/1916843003/diff/60001/base/trace_event/blame_context.cc#newcode88 > ...
4 years, 8 months ago (2016-04-26 16:27:02 UTC) #10
Sami
> unrelatedly with this cl, you can still see a partially destroyed object there > ...
4 years, 8 months ago (2016-04-26 17:05:51 UTC) #11
Primiano Tucci (use gerrit)
On 2016/04/26 17:05:51, Sami wrote: > > 2. if a class derives from blamecontext, the ...
4 years, 8 months ago (2016-04-26 18:28:03 UTC) #12
Xiaocheng
On 2016/04/26 at 18:28:03, primiano wrote: > On 2016/04/26 17:05:51, Sami wrote: > > > ...
4 years, 7 months ago (2016-04-27 03:02:25 UTC) #13
Xiaocheng
On 2016/04/27 at 03:02:25, Xiaocheng wrote: > On 2016/04/26 at 18:28:03, primiano wrote: > > ...
4 years, 7 months ago (2016-04-27 08:13:17 UTC) #14
Xiaocheng
PTAL. It seems impossible to fix the race between callbacks and dtor if TraceLog::enabled_state_observer_list_ is ...
4 years, 7 months ago (2016-04-27 12:21:11 UTC) #16
Xiaocheng
4 years, 7 months ago (2016-05-11 07:29:03 UTC) #17
Closing this patch since thread safety of BlameContext will be handled
differently.

Powered by Google App Engine
This is Rietveld 408576698