mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Fix data race in TraceSection.h (#48774)
Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/48774 [Changelog] [Internal] - Fix data race in TraceSection.h ## Issue The `instrumentsLogHandle` variable is a static variable that is initialized lazily when the `getOrCreateInstrumentsLogHandle()` function is called. However, this initialization is not thread-safe. Multiple threads may call this function simultaneously, leading to a data race on the `instrumentsLogHandle` variable. Reviewed By: lyahdav, javache Differential Revision: D68366837 fbshipit-source-id: d61b85a0299a8d42b9fbcfdbecae78eb410d748f
This commit is contained in:
committed by
Facebook GitHub Bot
parent
e31ff4212b
commit
d154cd5ba1
@@ -117,10 +117,13 @@ static auto render(const T& t)
|
||||
inline os_log_t instrumentsLogHandle = nullptr;
|
||||
|
||||
static inline os_log_t getOrCreateInstrumentsLogHandle() {
|
||||
if (!instrumentsLogHandle) {
|
||||
instrumentsLogHandle = os_log_create(
|
||||
"dev.reactnative.instruments", OS_LOG_CATEGORY_DYNAMIC_TRACING);
|
||||
}
|
||||
static std::once_flag flag{};
|
||||
std::call_once(flag, []() {
|
||||
if (!instrumentsLogHandle) {
|
||||
instrumentsLogHandle = os_log_create(
|
||||
"dev.reactnative.instruments", OS_LOG_CATEGORY_DYNAMIC_TRACING);
|
||||
}
|
||||
});
|
||||
return instrumentsLogHandle;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user