Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Wrap the global timeline event handler callback in a std::atomic #32073

Merged
merged 1 commit into from
Mar 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions fml/trace_event.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ namespace tracing {

namespace {
AsciiTrie gAllowlist;
TimelineEventHandler gTimelineEventHandler;
std::atomic<TimelineEventHandler> gTimelineEventHandler;

inline void FlutterTimelineEvent(const char* label,
int64_t timestamp0,
Expand All @@ -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
Expand Down
14 changes: 7 additions & 7 deletions fml/trace_event.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down