Commit 602aeb40 authored by Ali Ijaz Sheikh's avatar Ali Ijaz Sheikh Committed by Commit Bot

tracing: make GetCategoryGroupEnabled thread-safe

Change-Id: I29795e6df81f8ec719bdf62e5625cc06717861a5
Reviewed-on: https://chromium-review.googlesource.com/1183960Reviewed-by: 's avatarMichael Lippautz <mlippautz@chromium.org>
Commit-Queue: Ali Ijaz Sheikh <ofrobots@google.com>
Cr-Commit-Position: refs/heads/master@{#55318}
parent 54a59e00
......@@ -190,17 +190,21 @@ const uint8_t* TracingController::GetCategoryGroupEnabledInternal(
DCHECK(!strchr(category_group, '"'));
// The g_category_groups is append only, avoid using a lock for the fast path.
size_t current_category_index = v8::base::Acquire_Load(&g_category_index);
size_t category_index = base::Acquire_Load(&g_category_index);
// Search for pre-existing category group.
for (size_t i = 0; i < current_category_index; ++i) {
for (size_t i = 0; i < category_index; ++i) {
if (strcmp(g_category_groups[i], category_group) == 0) {
return &g_category_group_enabled[i];
}
}
// Slow path. Grab the lock.
base::LockGuard<base::Mutex> lock(mutex_.get());
// Check the list again with lock in hand.
unsigned char* category_group_enabled = nullptr;
size_t category_index = base::Acquire_Load(&g_category_index);
category_index = base::Acquire_Load(&g_category_index);
for (size_t i = 0; i < category_index; ++i) {
if (strcmp(g_category_groups[i], category_group) == 0) {
return &g_category_group_enabled[i];
......
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