Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(Worklets): SingleInstanceChecker #6694

Merged
merged 2 commits into from
Nov 21, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#include <reanimated/LayoutAnimations/LayoutAnimationsManager.h>
#include <reanimated/NativeModules/NativeReanimatedModuleSpec.h>
#include <reanimated/Tools/PlatformDepMethodsHolder.h>
#include <reanimated/Tools/SingleInstanceChecker.h>

#ifdef RCT_NEW_ARCH_ENABLED
#include <reanimated/Fabric/PropsRegistry.h>
Expand All @@ -16,6 +15,7 @@
#include <worklets/NativeModules/NativeWorkletsModule.h>
#include <worklets/Registries/EventHandlerRegistry.h>
#include <worklets/Tools/JSScheduler.h>
#include <worklets/Tools/SingleInstanceChecker.h>
#include <worklets/Tools/UIScheduler.h>

#ifdef RCT_NEW_ARCH_ENABLED
Expand Down Expand Up @@ -243,8 +243,9 @@ class NativeReanimatedModule : public NativeReanimatedModuleSpec {
const KeyboardEventUnsubscribeFunction unsubscribeFromKeyboardEventsFunction_;

#ifndef NDEBUG
SingleInstanceChecker<NativeReanimatedModule> singleInstanceChecker_;
#endif
worklets::SingleInstanceChecker<NativeReanimatedModule>
singleInstanceChecker_;
#endif // NDEBUG
};

} // namespace reanimated
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include <cxxreact/MessageQueueThread.h>
#include <worklets/NativeModules/NativeWorkletsModuleSpec.h>
#include <worklets/Tools/SingleInstanceChecker.h>
#include <string>

namespace worklets {
Expand All @@ -18,6 +19,9 @@ class NativeWorkletsModule : public NativeWorkletsModuleSpec {

private:
const std::string valueUnpackerCode_;
#ifndef NDEBUG
SingleInstanceChecker<NativeWorkletsModule> singleInstanceChecker_;
#endif // NDEBUG
};

} // namespace worklets
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@
#include <cxxabi.h>

#include <atomic>
#include <cassert>
#include <iostream>
#include <string>

#ifdef ANDROID
#include <android/log.h>
#endif
#endif // ANDROID

namespace reanimated {
namespace worklets {

// This is a class that counts how many instances of a different class there
// are. It is meant only to be used with classes that should only have one
Expand Down Expand Up @@ -66,6 +67,6 @@ SingleInstanceChecker<T>::~SingleInstanceChecker() {
instanceCount_--;
}

} // namespace reanimated
} // namespace worklets

#endif // NDEBUG
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@
#endif // RCT_NEW_ARCH_ENABLED

#import <reanimated/RuntimeDecorators/RNRuntimeDecorator.h>
#import <reanimated/Tools/SingleInstanceChecker.h>
#import <reanimated/apple/REAModule.h>
#import <reanimated/apple/REANodesManager.h>
#import <reanimated/apple/REAUIKit.h>
#import <reanimated/apple/native/NativeProxy.h>

#import <worklets/Tools/ReanimatedJSIUtils.h>
#import <worklets/Tools/SingleInstanceChecker.h>
#import <worklets/WorkletRuntime/WorkletRuntime.h>
#import <worklets/WorkletRuntime/WorkletRuntimeCollector.h>
#import <worklets/apple/WorkletsModule.h>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#import <React/RCTBridge+Private.h>
#import <worklets/WorkletRuntime/RNRuntimeWorkletDecorator.h>
#import <worklets/apple/WorkletsModule.h>
#import <worklets/tools/SingleInstanceChecker.h>

using worklets::NativeWorkletsModule;
using worklets::RNRuntimeWorkletDecorator;
Expand All @@ -16,6 +17,9 @@ - (void)_tryAndHandleError:(dispatch_block_t)block;

@implementation WorkletsModule {
std::shared_ptr<NativeWorkletsModule> nativeWorkletsModule_;
#ifndef NDEBUG
worklets::SingleInstanceChecker<WorkletsModule> singleInstanceChecker_;
#endif // NDEBUG
}

- (std::shared_ptr<NativeWorkletsModule>)getNativeWorkletsModule
Expand Down
Loading