mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Use the same lock for fields cleared on Fabric native binding uninstall
Summary: Scheduler and JavaUIManager mutexes share the lifetime (between install-uninstall), so we can use singular shared lock to ensure that both sections are locked exclusively for install/uninstall and in shared mode for access. Changelog: [Internal] Reviewed By: mdvacca Differential Revision: D33130686 fbshipit-source-id: bf283fd5410e386d2635645e17680a9f4cb7f288
This commit is contained in:
committed by
Facebook GitHub Bot
parent
1d45b20b6c
commit
acda0fec48
@@ -223,13 +223,13 @@ jni::local_ref<Binding::jhybriddata> Binding::initHybrid(
|
||||
|
||||
// Thread-safe getter
|
||||
jni::global_ref<jobject> Binding::getJavaUIManager() {
|
||||
std::lock_guard<std::mutex> uiManagerLock(javaUIManagerMutex_);
|
||||
std::shared_lock<better::shared_mutex> lock(installMutex_);
|
||||
return javaUIManager_;
|
||||
}
|
||||
|
||||
// Thread-safe getter
|
||||
std::shared_ptr<Scheduler> Binding::getScheduler() {
|
||||
std::lock_guard<std::mutex> lock(schedulerMutex_);
|
||||
std::shared_lock<better::shared_mutex> lock(installMutex_);
|
||||
return scheduler_;
|
||||
}
|
||||
|
||||
@@ -521,10 +521,7 @@ void Binding::installFabricUIManager(
|
||||
|
||||
// Use std::lock and std::adopt_lock to prevent deadlocks by locking mutexes
|
||||
// at the same time
|
||||
std::lock(schedulerMutex_, javaUIManagerMutex_);
|
||||
std::lock_guard<std::mutex> schedulerLock(schedulerMutex_, std::adopt_lock);
|
||||
std::lock_guard<std::mutex> uiManagerLock(
|
||||
javaUIManagerMutex_, std::adopt_lock);
|
||||
std::unique_lock<better::shared_mutex> lock(installMutex_);
|
||||
|
||||
javaUIManager_ = make_global(javaUIManager);
|
||||
|
||||
@@ -625,13 +622,8 @@ void Binding::uninstallFabricUIManager() {
|
||||
LOG(WARNING) << "Binding::uninstallFabricUIManager() was called (address: "
|
||||
<< this << ").";
|
||||
}
|
||||
// Use std::lock and std::adopt_lock to prevent deadlocks by locking mutexes
|
||||
// at the same time
|
||||
std::lock(schedulerMutex_, javaUIManagerMutex_);
|
||||
std::lock_guard<std::mutex> schedulerLock(schedulerMutex_, std::adopt_lock);
|
||||
std::lock_guard<std::mutex> uiManagerLock(
|
||||
javaUIManagerMutex_, std::adopt_lock);
|
||||
|
||||
std::unique_lock<better::shared_mutex> lock(installMutex_);
|
||||
animationDriver_ = nullptr;
|
||||
scheduler_ = nullptr;
|
||||
javaUIManager_ = nullptr;
|
||||
|
||||
@@ -178,8 +178,9 @@ class Binding : public jni::HybridClass<Binding>,
|
||||
void uninstallFabricUIManager();
|
||||
|
||||
// Private member variables
|
||||
better::shared_mutex installMutex_;
|
||||
jni::global_ref<jobject> javaUIManager_;
|
||||
std::mutex javaUIManagerMutex_;
|
||||
std::shared_ptr<Scheduler> scheduler_;
|
||||
|
||||
// LayoutAnimations
|
||||
void onAnimationStarted() override;
|
||||
@@ -187,9 +188,6 @@ class Binding : public jni::HybridClass<Binding>,
|
||||
std::shared_ptr<LayoutAnimationDriver> animationDriver_;
|
||||
std::unique_ptr<JBackgroundExecutor> backgroundExecutor_;
|
||||
|
||||
std::shared_ptr<Scheduler> scheduler_;
|
||||
std::mutex schedulerMutex_;
|
||||
|
||||
better::map<SurfaceId, SurfaceHandler> surfaceHandlerRegistry_{};
|
||||
better::shared_mutex
|
||||
surfaceHandlerRegistryMutex_; // Protects `surfaceHandlerRegistry_`.
|
||||
|
||||
Reference in New Issue
Block a user