Skip to content
Closed
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
2 changes: 1 addition & 1 deletion packages/react-native/Libraries/Image/RCTImageLoader.mm
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ static NSInteger RCTImageBytesForImage(UIImage *image)
return image.images ? image.images.count * singleImageBytes : singleImageBytes;
}

static auto currentRequestCount = std::atomic<uint64_t>(0);
static constinit auto currentRequestCount = std::atomic<uint64_t>(0);

static NSError *addResponseHeadersToError(NSError *originalError, NSHTTPURLResponse *response)
{
Expand Down
2 changes: 1 addition & 1 deletion packages/react-native/Libraries/Network/RCTNetworkTask.mm
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ @implementation RCTNetworkTask {
RCTNetworkTask *_selfReference;
}

static auto currentRequestId = std::atomic<NSUInteger>(0);
static constinit auto currentRequestId = std::atomic<NSUInteger>(0);

- (instancetype)initWithRequest:(NSURLRequest *)request
handler:(id<RCTURLRequestHandler>)handler
Expand Down
2 changes: 1 addition & 1 deletion packages/react-native/React/Base/RCTUtils.mm
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ UIDeviceOrientation RCTDeviceOrientation(void)

CGSize RCTScreenSize(void)
{
static std::atomic<CGSize> cachedSize;
static constinit std::atomic<CGSize> cachedSize;
__block CGSize size = cachedSize.load(std::memory_order_relaxed);

if (CGSizeEqualToSize(size, CGSizeZero)) {
Expand Down
2 changes: 1 addition & 1 deletion packages/react-native/React/CoreModules/RCTDevSettings.mm
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ - (void)_reloadWithDefaults:(NSDictionary *)defaultValues
#if RCT_DEV_SETTINGS_ENABLE_PACKAGER_CONNECTION
static RCTHandlerToken reloadToken;
static RCTHandlerToken devMenuToken;
static std::atomic<int> numInitializedModules{0};
static constinit std::atomic<int> numInitializedModules{0};
#endif

@interface RCTDevSettings () <RCTBridgeModule, RCTInvalidating, NativeDevSettingsSpec, RCTDevSettingsInspectable> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ lastResort(const char* tag, const char* msg, const char* arg = nullptr) {
namespace facebook::gloginit {

void initialize(const char* tag) {
static std::once_flag flag{};
static constinit std::once_flag flag{};
static auto failed = false;

std::call_once(flag, [tag] {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ static void hermesFatalHandler(const std::string& reason) {
__android_log_assert(nullptr, "Hermes", "%s", reason.c_str());
}

static std::once_flag flag;
static constinit std::once_flag flag;

static ::hermes::vm::RuntimeConfig makeRuntimeConfig(jlong heapSizeMB) {
namespace vm = ::hermes::vm;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const int kInstanceKey = 1;
}

void JReactMarker::setLogPerfMarkerIfNeeded() {
static std::once_flag flag{};
static constinit std::once_flag flag{};
std::call_once(flag, []() {
ReactMarker::logTaggedMarkerImpl = JReactMarker::logPerfMarker;
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ void ensureThreadDurationJNIEnvAttached() {
// > exits, and call DetachCurrentThread() from there.
// https://github.com/facebookincubator/fbjni/blob/7b7efda0d49b956acf1d3307510e3c73fc55b404/cxx/fbjni/detail/Environment.h#L101
// https://developer.android.com/training/articles/perf-jni#threads
static thread_local std::optional<jni::ThreadScope> threadScope;
static constinit thread_local std::optional<jni::ThreadScope> threadScope;

if (jni::detail::currentOrNull() == nullptr) {
threadScope.emplace();
Expand Down
2 changes: 1 addition & 1 deletion packages/react-native/ReactCommon/cxxreact/TraceSection.h
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ inline os_log_t instrumentsLogHandle = nullptr;

static inline os_log_t getOrCreateInstrumentsLogHandle()
{
static std::once_flag flag{};
static constinit std::once_flag flag{};
std::call_once(flag, []() {
if (!instrumentsLogHandle) {
instrumentsLogHandle = os_log_create("dev.reactnative.instruments", OS_LOG_CATEGORY_DYNAMIC_TRACING);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @generated SignedSource<<3acecfdec6d182a74c4616d6c8690e72>>
* @generated SignedSource<<c8699b32c5c6bade5ace861696a7526f>>
*/

/**
Expand All @@ -23,7 +23,7 @@ namespace facebook::react {

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wglobal-constructors"
std::unique_ptr<ReactNativeFeatureFlagsAccessor> accessor_;
constinit std::unique_ptr<ReactNativeFeatureFlagsAccessor> accessor_;
#pragma GCC diagnostic pop

bool ReactNativeFeatureFlags::commonTestFlag() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
namespace {
int32_t getUniqueId()
{
static std::atomic<int32_t> counter{0};
static constinit std::atomic<int32_t> counter{0};
return counter++;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ namespace facebook::react {

// Global function pointer for getting current time. Current time
// can be injected for testing purposes.
static TimePointFunction g_now = &std::chrono::steady_clock::now;
static constinit TimePointFunction g_now = &std::chrono::steady_clock::now;
void g_setNativeAnimatedNowTimestampFunction(TimePointFunction nowFunction) {
g_now = nowFunction;
}
Expand Down Expand Up @@ -91,7 +91,8 @@ void mergeObjects(folly::dynamic& out, const folly::dynamic& objectToMerge) {

} // namespace

thread_local bool NativeAnimatedNodesManager::isOnRenderThread_{false};
constinit thread_local bool NativeAnimatedNodesManager::isOnRenderThread_{
false};

NativeAnimatedNodesManager::NativeAnimatedNodesManager(
DirectManipulationCallback&& directManipulationCallback,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ class NativeAnimatedNodesManager : public std::enable_shared_from_this<NativeAni

std::unique_ptr<AnimatedNode> animatedNode(Tag tag, const folly::dynamic &config) noexcept;

static thread_local bool isOnRenderThread_;
static constinit thread_local bool isOnRenderThread_;

std::mutex animatedNodesCreatedAsyncMutex_;
std::unordered_map<Tag, std::unique_ptr<AnimatedNode>> animatedNodesCreatedAsync_;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ void BaseParagraphProps::setProp(
// of these fields together, and because there are some collisions between
// propnames parsed here and outside of ParagraphAttributes.
// This code is also duplicated in AndroidTextInput.
static auto paDefaults = ParagraphAttributes{};
static constinit auto paDefaults = ParagraphAttributes{};
switch (hash) {
REBUILD_FIELD_SWITCH_CASE(
paDefaults,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ void BaseTextInputProps::setProp(
// propnames parsed here and outside of ParagraphAttributes. For example,
// textBreakStrategy is duplicated.
// This code is also duplicated in ParagraphProps.
static auto paDefaults = ParagraphAttributes{};
static constinit auto paDefaults = ParagraphAttributes{};
switch (hash) {
REBUILD_FIELD_SWITCH_CASE(
paDefaults,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ static int FabricDefaultYogaLog(
return size_s;
}

thread_local LayoutContext threadLocalLayoutContext;
constinit thread_local LayoutContext threadLocalLayoutContext;

YogaLayoutableShadowNode::YogaLayoutableShadowNode(
const ShadowNodeFragment& fragment,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ void YogaStylableProps::setProp(
RawPropsPropNameHash hash,
const char* propName,
const RawValue& value) {
static const auto ygDefaults = yoga::Style{};
static constinit const auto ygDefaults = yoga::Style{};
static const auto defaults = YogaStylableProps{};

Props::setProp(context, hash, propName, value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ constexpr SurfaceId ROOT_VIEW_TAG_INCREMENT = 10;

SurfaceId getNextRootViewTag() noexcept {
// Numbering of these tags goes from 11, 21, 31, ..., 100501, ...
static std::atomic<SurfaceId> nextRootViewTag = 1;
static constinit std::atomic<SurfaceId> nextRootViewTag = 1;
return nextRootViewTag += ROOT_VIEW_TAG_INCREMENT;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ namespace facebook::react {
* tree simultaneously. This thread_local flag allows enabling the updates for
* chosen threads.
*/
thread_local bool useRuntimeShadowNodeReferenceUpdateOnThread{false}; // NOLINT
constinit thread_local bool useRuntimeShadowNodeReferenceUpdateOnThread{
false}; // NOLINT

/* static */ void ShadowNode::setUseRuntimeShadowNodeReferenceUpdateOnThread(
bool isEnabled) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,20 @@ namespace facebook::react {
#endif

const Props::Shared& ShadowNodeFragment::propsPlaceholder() {
NO_DESTROY static Props::Shared instance;
NO_DESTROY static constinit Props::Shared instance;
return instance;
}

const std::shared_ptr<const std::vector<std::shared_ptr<const ShadowNode>>>&
ShadowNodeFragment::childrenPlaceholder() {
NO_DESTROY static std::shared_ptr<
NO_DESTROY static constinit std::shared_ptr<
const std::vector<std::shared_ptr<const ShadowNode>>>
instance;
return instance;
}

const State::Shared& ShadowNodeFragment::statePlaceholder() {
NO_DESTROY static State::Shared instance;
NO_DESTROY static constinit State::Shared instance;
return instance;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,12 @@ SharedColor parsePlatformColor(
if (!resourcePaths.empty()) {
// Cache the (costly) JNI results. A cached nullopt is an explicit miss,
// distinct from a path that resolves to transparent (ARGB 0).
static std::mutex getColorCacheMutex;
static constinit std::mutex getColorCacheMutex;
static folly::EvictingCacheMap<size_t, std::optional<Color>>
getColorCache(64);

// Listen for appearance changes, which should invalidate the cache
static std::once_flag setupCacheInvalidation;
static constinit std::once_flag setupCacheInvalidation;
std::call_once(
setupCacheInvalidation,
configurePlatformColorCacheInvalidationHook,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ void RuntimeScheduler_Legacy::executeNowOnTheSameThread(
RawCallback&& callback) {
TraceSection s("RuntimeScheduler::executeNowOnTheSameThread");

static thread_local jsi::Runtime* runtimePtr = nullptr;
static constinit thread_local jsi::Runtime* runtimePtr = nullptr;

if (runtimePtr == nullptr) {
runtimeAccessRequests_ += 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ void RuntimeScheduler_Modern::executeNowOnTheSameThread(
RawCallback&& callback) {
TraceSection s("RuntimeScheduler::executeNowOnTheSameThread");

static thread_local jsi::Runtime* runtimePtr = nullptr;
static constinit thread_local jsi::Runtime* runtimePtr = nullptr;

auto currentTime = now_();
auto priority = SchedulerPriority::ImmediatePriority;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace facebook::react {
namespace {

inline uint64_t getNextId() noexcept {
static std::atomic<uint64_t> nextId = 1;
static constinit std::atomic<uint64_t> nextId = 1;
return nextId++;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@

namespace facebook::react {

thread_local TransactionTelemetry* threadLocalTransactionTelemetry = nullptr;
constinit thread_local TransactionTelemetry* threadLocalTransactionTelemetry =
nullptr;

TransactionTelemetry::TransactionTelemetry()
: TransactionTelemetry(telemetryTimePointNow) {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

namespace facebook::react {

std::once_flag perfettoInit;
constinit std::once_flag perfettoInit;
void initializePerfetto() {
std::call_once(perfettoInit, []() {
perfetto::TracingInitArgs args;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ OnScopeExit onScopeExit(^{
// Protects access to g_uiTask
std::mutex &g_mutex()
{
static std::mutex mutex;
static constinit std::mutex mutex;
return mutex;
}

Expand All @@ -65,13 +65,13 @@ OnScopeExit onScopeExit(^{

std::mutex &g_ticket()
{
static std::mutex ticket;
static constinit std::mutex ticket;
return ticket;
}

std::optional<UITask> &g_uiTask()
{
static std::optional<UITask> uiTaskQueue;
static constinit std::optional<UITask> uiTaskQueue;
return uiTaskQueue;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@

namespace facebook::yoga {

std::atomic<uint32_t> gCurrentGenerationCount(0);
constinit std::atomic<uint32_t> gCurrentGenerationCount(0);

static bool hasAutoHorizontalMargin(const Style& style) {
for (const auto direction : {Direction::LTR, Direction::RTL}) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ struct Node {
: subscriber{std::move(subscriber)} {}
};

std::atomic<Node*> subscribers{nullptr};
constinit std::atomic<Node*> subscribers{nullptr};

Node* push(Node* newHead) {
Node* oldHead = nullptr;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#include <mutex>

void initializePerfetto() {
static std::once_flag s_PerfettoIsInitialized;
static constinit std::once_flag s_PerfettoIsInitialized;

std::call_once(s_PerfettoIsInitialized, []() {
perfetto::TracingInitArgs args;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ namespace facebook::react {
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wglobal-constructors"
std::unique_ptr<ReactNativeFeatureFlagsAccessor> accessor_;
constinit std::unique_ptr<ReactNativeFeatureFlagsAccessor> accessor_;
#pragma GCC diagnostic pop
${Object.entries(definitions.common)
Expand Down
Loading