Commit f8fd9cfb by Etienne Bergeron Committed by Commit Bot

Fix racy GetCategory with trace_event

See racy trace_event: http://crbug.com/1091723 The trace event macros were racy because of this code: INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(...) The macro is using a static variable which is not thread-safe. The design of tracing was racy (by design) and rely on the fact that addTraceEvent(...) is threadsafe internally via TraceLog::lock_ This CL is replacing the static variable with a scope (C++11) pattern. The static variable is guaranted (C++) to be atomic and it is implemented efficiently. see: §6.7 [stmt.dcl] p4 " If control enters the declaration concurrently while the variable is being initialized, the concurrent execution shall wait for completion of the initialization. " Bug to track follow-up migration: http://anglebug.com/4702 Bug: chromium:1091259, chromium:1091723 Change-Id: If67b501e6e826ccf603eb2349c3f0aa6272c9a52 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/2233410 Commit-Queue: Jamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org>
parent 86a45a1a
...@@ -454,10 +454,9 @@ ...@@ -454,10 +454,9 @@
#define INTERNALTRACEEVENTUID(name_prefix) INTERNAL_TRACE_EVENT_UID2(name_prefix, __LINE__) #define INTERNALTRACEEVENTUID(name_prefix) INTERNAL_TRACE_EVENT_UID2(name_prefix, __LINE__)
// Implementation detail: internal macro to create static category. // Implementation detail: internal macro to create static category.
#define INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(platform, category) \ #define INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(platform, category) \
static const unsigned char *INTERNALTRACEEVENTUID(catstatic) = 0; \ static const unsigned char *INTERNALTRACEEVENTUID(catstatic) = \
if (!INTERNALTRACEEVENTUID(catstatic)) \ TRACE_EVENT_API_GET_CATEGORY_ENABLED(platform, category);
INTERNALTRACEEVENTUID(catstatic) = TRACE_EVENT_API_GET_CATEGORY_ENABLED(platform, category);
// Implementation detail: internal macro to create static category and add // Implementation detail: internal macro to create static category and add
// event if the category is enabled. // event if the category is 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