Skip to content

Commit

Permalink
chore(Worklets): SingleInstanceChecker (#6694)
Browse files Browse the repository at this point in the history
## Summary

Moving `SingleInstanceChecker` to Worklets and applying it there.

## Test plan

🚀
  • Loading branch information
tjzel authored Nov 21, 2024
1 parent d5789d6 commit 254af50
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 7 deletions.
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

0 comments on commit 254af50

Please sign in to comment.