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

Commit 233c17c

Browse files
Wrap the global timeline event handler callback in a std::atomic (#32073)
1 parent fb0fd74 commit 233c17c

File tree

2 files changed

+13
-11
lines changed

2 files changed

+13
-11
lines changed

fml/trace_event.cc

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ namespace tracing {
1919

2020
namespace {
2121
AsciiTrie gAllowlist;
22-
TimelineEventHandler gTimelineEventHandler;
22+
std::atomic<TimelineEventHandler> gTimelineEventHandler;
2323

2424
inline void FlutterTimelineEvent(const char* label,
2525
int64_t timestamp0,
@@ -28,9 +28,11 @@ inline void FlutterTimelineEvent(const char* label,
2828
intptr_t argument_count,
2929
const char** argument_names,
3030
const char** argument_values) {
31-
if (gTimelineEventHandler && gAllowlist.Query(label)) {
32-
gTimelineEventHandler(label, timestamp0, timestamp1_or_async_id, type,
33-
argument_count, argument_names, argument_values);
31+
TimelineEventHandler handler =
32+
gTimelineEventHandler.load(std::memory_order_relaxed);
33+
if (handler && gAllowlist.Query(label)) {
34+
handler(label, timestamp0, timestamp1_or_async_id, type, argument_count,
35+
argument_names, argument_values);
3436
}
3537
}
3638
} // namespace

fml/trace_event.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -147,13 +147,13 @@ using TraceIDArg = int64_t;
147147

148148
void TraceSetAllowlist(const std::vector<std::string>& allowlist);
149149

150-
using TimelineEventHandler = std::function<void(const char*,
151-
int64_t,
152-
int64_t,
153-
Dart_Timeline_Event_Type,
154-
intptr_t,
155-
const char**,
156-
const char**)>;
150+
typedef void (*TimelineEventHandler)(const char*,
151+
int64_t,
152+
int64_t,
153+
Dart_Timeline_Event_Type,
154+
intptr_t,
155+
const char**,
156+
const char**);
157157

158158
void TraceSetTimelineEventHandler(TimelineEventHandler handler);
159159

0 commit comments

Comments
 (0)