Skip to content

Commit

Permalink
Implement synchronized setter/getter for logTaggedMarkerImpl
Browse files Browse the repository at this point in the history
  • Loading branch information
hakonk committed Jul 19, 2024
1 parent 2eb7bcb commit 6599883
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 6 deletions.
3 changes: 2 additions & 1 deletion packages/react-native/React/CxxBridge/RCTCxxBridge.mm
Original file line number Diff line number Diff line change
Expand Up @@ -163,10 +163,11 @@ static void mapReactMarkerToPerformanceLogger(
static void registerPerformanceLoggerHooks(RCTPerformanceLogger *performanceLogger)
{
__weak RCTPerformanceLogger *weakPerformanceLogger = performanceLogger;
ReactMarker::logTaggedMarkerImpl = [weakPerformanceLogger](
ReactMarker::LogTaggedMarker newMarker = [weakPerformanceLogger](
const ReactMarker::ReactMarkerId markerId, const char *tag) {
mapReactMarkerToPerformanceLogger(markerId, weakPerformanceLogger, tag);
};
ReactMarker::setLogTaggedMarkerImpl(newMarker);
}

@interface RCTCxxBridge () <RCTModuleDataCallInvokerProvider>
Expand Down
1 change: 0 additions & 1 deletion packages/react-native/ReactCommon/cxxreact/ReactMarker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ namespace ReactMarker {
#pragma clang diagnostic ignored "-Wglobal-constructors"
#endif

LogTaggedMarker logTaggedMarkerImpl = nullptr;
LogTaggedMarker logTaggedMarkerBridgelessImpl = nullptr;

#if __clang__
Expand Down
17 changes: 16 additions & 1 deletion packages/react-native/ReactCommon/cxxreact/ReactMarker.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#pragma once

#include <cmath>
#include <shared_mutex>

#ifdef __APPLE__
#include <functional>
Expand Down Expand Up @@ -51,7 +52,21 @@ typedef void (*LogTaggedMarkerBridgeless)(const ReactMarkerId, const char* tag);
#define RN_EXPORT __attribute__((visibility("default")))
#endif

extern RN_EXPORT LogTaggedMarker logTaggedMarkerImpl; // Bridge only
namespace {
std::shared_mutex logTaggedMarkerImplMutex;
LogTaggedMarker logTaggedMarkerImpl = nullptr;
}

extern RN_EXPORT inline LogTaggedMarker getLogTaggedMarkerImpl(void) {
std::shared_lock lock(logTaggedMarkerImplMutex);
return logTaggedMarkerImpl;
}

extern RN_EXPORT inline void setLogTaggedMarkerImpl(LogTaggedMarker marker) {
std::unique_lock lock(logTaggedMarkerImplMutex);
logTaggedMarkerImpl = marker;
}

extern RN_EXPORT LogTaggedMarker logTaggedMarkerBridgelessImpl;

extern RN_EXPORT void logMarker(const ReactMarkerId markerId); // Bridge only
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ void JSIExecutor::initializeRuntime() {
runtimeInstaller_(*runtime_);
}

bool hasLogger(ReactMarker::logTaggedMarkerImpl);
bool hasLogger(ReactMarker::getLogTaggedMarkerImpl());
if (hasLogger) {
ReactMarker::logMarker(ReactMarker::CREATE_REACT_CONTEXT_STOP);
}
Expand All @@ -151,7 +151,7 @@ void JSIExecutor::loadBundle(
std::string sourceURL) {
SystraceSection s("JSIExecutor::loadBundle");

bool hasLogger(ReactMarker::logTaggedMarkerImpl);
bool hasLogger(ReactMarker::getLogTaggedMarkerImpl());
std::string scriptName = simpleBasename(sourceURL);
if (hasLogger) {
ReactMarker::logTaggedMarker(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ void JSINativeModules::reset() {
std::optional<Object> JSINativeModules::createModule(
Runtime& rt,
const std::string& name) {
bool hasLogger(ReactMarker::logTaggedMarkerImpl);
bool hasLogger(ReactMarker::getLogTaggedMarkerImpl());
if (hasLogger) {
ReactMarker::logTaggedMarker(
ReactMarker::NATIVE_MODULE_SETUP_START, name.c_str());
Expand Down

0 comments on commit 6599883

Please sign in to comment.