Wrap the global timeline event handler callback in a std::atomic (flutter/engine#32073)

This commit is contained in:
Jason Simmons
2022-03-16 16:10:06 -07:00
committed by GitHub
parent c502114887
commit c6a09145d7
2 changed files with 13 additions and 11 deletions

View File

@@ -19,7 +19,7 @@ namespace tracing {
namespace {
AsciiTrie gAllowlist;
TimelineEventHandler gTimelineEventHandler;
std::atomic<TimelineEventHandler> gTimelineEventHandler;
inline void FlutterTimelineEvent(const char* label,
int64_t timestamp0,
@@ -28,9 +28,11 @@ inline void FlutterTimelineEvent(const char* label,
intptr_t argument_count,
const char** argument_names,
const char** argument_values) {
if (gTimelineEventHandler && gAllowlist.Query(label)) {
gTimelineEventHandler(label, timestamp0, timestamp1_or_async_id, type,
argument_count, argument_names, argument_values);
TimelineEventHandler handler =
gTimelineEventHandler.load(std::memory_order_relaxed);
if (handler && gAllowlist.Query(label)) {
handler(label, timestamp0, timestamp1_or_async_id, type, argument_count,
argument_names, argument_values);
}
}
} // namespace

View File

@@ -147,13 +147,13 @@ using TraceIDArg = int64_t;
void TraceSetAllowlist(const std::vector<std::string>& allowlist);
using TimelineEventHandler = std::function<void(const char*,
int64_t,
int64_t,
Dart_Timeline_Event_Type,
intptr_t,
const char**,
const char**)>;
typedef void (*TimelineEventHandler)(const char*,
int64_t,
int64_t,
Dart_Timeline_Event_Type,
intptr_t,
const char**,
const char**);
void TraceSetTimelineEventHandler(TimelineEventHandler handler);