Fix TRACE_EVENT wasn't thread safe.
TRACE_EVENT uses INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO and INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO reads and writes to a static variable on multiple threads. Fix by using std::atomic for the static variable. Bug: dawn:1700 Change-Id: I914bb73352e400f0adeafb64518d61099276270d Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/123680 Reviewed-by: Corentin Wallez <cwallez@chromium.org> Kokoro: Kokoro <noreply+kokoro@google.com> Reviewed-by: Austin Eng <enga@chromium.org> Commit-Queue: Quyen Le <lehoangquyen@chromium.org>
This commit is contained in:
parent
655c6c9b40
commit
c173a0ea88
|
@ -152,6 +152,7 @@
|
||||||
#ifndef SRC_DAWN_PLATFORM_TRACING_TRACEEVENT_H_
|
#ifndef SRC_DAWN_PLATFORM_TRACING_TRACEEVENT_H_
|
||||||
#define SRC_DAWN_PLATFORM_TRACING_TRACEEVENT_H_
|
#define SRC_DAWN_PLATFORM_TRACING_TRACEEVENT_H_
|
||||||
|
|
||||||
|
#include <atomic>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include "dawn/platform/tracing/EventTracer.h"
|
#include "dawn/platform/tracing/EventTracer.h"
|
||||||
|
@ -670,10 +671,16 @@
|
||||||
#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 std::atomic<const unsigned char*> INTERNALTRACEEVENTUID(atomicCatstatic)(nullptr); \
|
||||||
if (!INTERNALTRACEEVENTUID(catstatic)) \
|
const unsigned char* INTERNALTRACEEVENTUID(catstatic) = \
|
||||||
INTERNALTRACEEVENTUID(catstatic) = TRACE_EVENT_API_GET_CATEGORY_ENABLED(platform, category);
|
INTERNALTRACEEVENTUID(atomicCatstatic).load(std::memory_order_acquire); \
|
||||||
|
if (!INTERNALTRACEEVENTUID(catstatic)) { \
|
||||||
|
INTERNALTRACEEVENTUID(catstatic) = \
|
||||||
|
TRACE_EVENT_API_GET_CATEGORY_ENABLED(platform, category); \
|
||||||
|
INTERNALTRACEEVENTUID(atomicCatstatic) \
|
||||||
|
.store(INTERNALTRACEEVENTUID(catstatic), std::memory_order_release); \
|
||||||
|
}
|
||||||
|
|
||||||
// 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.
|
||||||
|
|
Loading…
Reference in New Issue