Chromium Code Reviews| Index: base/trace_event/trace_log.cc |
| diff --git a/base/trace_event/trace_log.cc b/base/trace_event/trace_log.cc |
| index f76393cf230a3e97772d3cee734ffac79b0ba5fc..4b21437c66114667b725e3dcfb1b70d7ea18f84b 100644 |
| --- a/base/trace_event/trace_log.cc |
| +++ b/base/trace_event/trace_log.cc |
| @@ -493,11 +493,18 @@ const unsigned char* TraceLog::GetCategoryGroupEnabled( |
| DCHECK(!CategoryRegistry::kCategoryAlreadyShutdown->is_enabled()); |
| return CategoryRegistry::kCategoryAlreadyShutdown->state_ptr(); |
| } |
| - TraceCategory* category = nullptr; |
| - bool is_new_category = |
| - CategoryRegistry::GetOrCreateCategoryByName(category_group, &category); |
|
Primiano Tucci (use gerrit)
2016/11/16 16:46:54
Essentially this was the core of the problem.
The
|
| - if (is_new_category) |
| - tracelog->UpdateCategoryState(category); |
| + TraceCategory* category = CategoryRegistry::GetCategoryByName(category_group); |
| + if (!category) { |
| + // Slow path: in the case of a new category we have to repeat the check |
| + // holding the lock, as multiple threads might have reached this point |
| + // at the same time. |
| + auto category_initializer = [](TraceCategory* category) { |
| + TraceLog::GetInstance()->UpdateCategoryState(category); |
| + }; |
| + AutoLock lock(tracelog->lock_); |
| + CategoryRegistry::GetOrCreateCategoryLocked( |
| + category_group, category_initializer, &category); |
| + } |
| DCHECK(category->state_ptr()); |
| return category->state_ptr(); |
| } |