Commit 0ba3de60 authored by Clemens Hammacher's avatar Clemens Hammacher Committed by Commit Bot

[tracing] Fix data race

There is a data race if several background threads check for a tracing
flag concurrently. Both will call {GetCategoryGroupEnabledInternal}.
The first one not find the category in the {g_category_group_enabled}
array, and hence will add it and call {UpdateCategoryGroupEnabledFlag}
to initialize the flag. The second thread then finds the entry in the
array and reads it without any synchronization, which is a data race.

Since we do not really care about this race, we just use a
{Relaxed_Load} to read the field. TSan is fine with that.

R=yangguo@chromium.org
CC=ofrobots@google.com

Bug: v8:8221
Change-Id: Ie09141e3d845956d3c487a463f00b7d6cd413513
Reviewed-on: https://chromium-review.googlesource.com/1245424Reviewed-by: 's avatarBen Titzer <titzer@chromium.org>
Commit-Queue: Clemens Hammacher <clemensh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#56256}
parent 32c5c91d
......@@ -50,7 +50,7 @@ enum CategoryGroupEnabledFlags {
trace_event_internal::TraceID::WithScope(scope, id)
#define INTERNAL_TRACE_EVENT_CATEGORY_GROUP_ENABLED_FOR_RECORDING_MODE() \
*INTERNAL_TRACE_EVENT_UID(category_group_enabled) & \
TRACE_EVENT_API_LOAD_CATEGORY_GROUP_ENABLED() & \
(kEnabledForRecording_CategoryGroupEnabledFlags | \
kEnabledForEventCallback_CategoryGroupEnabledFlags)
......@@ -127,6 +127,9 @@ enum CategoryGroupEnabledFlags {
#define TRACE_EVENT_API_ATOMIC_LOAD(var) v8::base::Relaxed_Load(&(var))
#define TRACE_EVENT_API_ATOMIC_STORE(var, value) \
v8::base::Relaxed_Store(&(var), (value))
#define TRACE_EVENT_API_LOAD_CATEGORY_GROUP_ENABLED() \
v8::base::Relaxed_Load(reinterpret_cast<const v8::base::Atomic8*>( \
INTERNAL_TRACE_EVENT_UID(category_group_enabled)))
////////////////////////////////////////////////////////////////////////////////
......
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