diff --git a/ReactCommon/fabric/imagemanager/ImageResponseObserverCoordinator.cpp b/ReactCommon/fabric/imagemanager/ImageResponseObserverCoordinator.cpp index 57b72966e..c4b5a3179 100644 --- a/ReactCommon/fabric/imagemanager/ImageResponseObserverCoordinator.cpp +++ b/ReactCommon/fabric/imagemanager/ImageResponseObserverCoordinator.cpp @@ -21,16 +21,16 @@ ImageResponseObserverCoordinator::~ImageResponseObserverCoordinator() {} void ImageResponseObserverCoordinator::addObserver( ImageResponseObserver *observer) const { ImageResponse::Status status = [this] { - std::shared_lock read(mutex_); + std::shared_lock read(mutex_); return status_; }(); if (status == ImageResponse::Status::Loading) { - std::unique_lock write(mutex_); + std::unique_lock write(mutex_); observers_.push_back(observer); } else if (status == ImageResponse::Status::Completed) { ImageResponse imageResponseCopy = [this] { - std::unique_lock read(mutex_); + std::unique_lock read(mutex_); return ImageResponse(imageData_); }(); observer->didReceiveImage(imageResponseCopy); @@ -41,7 +41,7 @@ void ImageResponseObserverCoordinator::addObserver( void ImageResponseObserverCoordinator::removeObserver( ImageResponseObserver *observer) const { - std::unique_lock write(mutex_); + std::unique_lock write(mutex_); auto position = std::find(observers_.begin(), observers_.end(), observer); if (position != observers_.end()) { @@ -52,7 +52,7 @@ void ImageResponseObserverCoordinator::removeObserver( void ImageResponseObserverCoordinator::nativeImageResponseProgress( float progress) const { std::vector observersCopy = [this] { - std::shared_lock read(mutex_); + std::shared_lock read(mutex_); return observers_; }(); @@ -64,19 +64,19 @@ void ImageResponseObserverCoordinator::nativeImageResponseProgress( void ImageResponseObserverCoordinator::nativeImageResponseComplete( const ImageResponse &imageResponse) const { { - std::unique_lock write(mutex_); + std::unique_lock write(mutex_); imageData_ = imageResponse.getImage(); status_ = ImageResponse::Status::Completed; } std::vector observersCopy = [this] { - std::shared_lock read(mutex_); + std::shared_lock read(mutex_); return observers_; }(); for (auto observer : observersCopy) { ImageResponse imageResponseCopy = [this] { - std::unique_lock read(mutex_); + std::unique_lock read(mutex_); return ImageResponse(imageData_); }(); observer->didReceiveImage(imageResponseCopy); @@ -85,12 +85,12 @@ void ImageResponseObserverCoordinator::nativeImageResponseComplete( void ImageResponseObserverCoordinator::nativeImageResponseFailed() const { { - std::unique_lock write(mutex_); + std::unique_lock write(mutex_); status_ = ImageResponse::Status::Failed; } std::vector observersCopy = [this] { - std::shared_lock read(mutex_); + std::shared_lock read(mutex_); return observers_; }(); diff --git a/ReactCommon/fabric/imagemanager/ImageResponseObserverCoordinator.h b/ReactCommon/fabric/imagemanager/ImageResponseObserverCoordinator.h index b5b22e402..1f0500ac6 100644 --- a/ReactCommon/fabric/imagemanager/ImageResponseObserverCoordinator.h +++ b/ReactCommon/fabric/imagemanager/ImageResponseObserverCoordinator.h @@ -10,8 +10,7 @@ #include #include -#include -#include +#include #include namespace facebook { @@ -84,7 +83,7 @@ class ImageResponseObserverCoordinator { /* * Observer and data mutex. */ - mutable folly::SharedMutex mutex_; + mutable better::shared_mutex mutex_; }; } // namespace react diff --git a/ReactCommon/fabric/uimanager/ShadowTree.cpp b/ReactCommon/fabric/uimanager/ShadowTree.cpp index 87d48e6e1..b008825bb 100644 --- a/ReactCommon/fabric/uimanager/ShadowTree.cpp +++ b/ReactCommon/fabric/uimanager/ShadowTree.cpp @@ -149,7 +149,7 @@ bool ShadowTree::tryCommit( { // Reading `rootShadowNode_` in shared manner. - std::shared_lock lock(commitMutex_); + std::shared_lock lock(commitMutex_); oldRootShadowNode = rootShadowNode_; } @@ -169,7 +169,7 @@ bool ShadowTree::tryCommit( { // Updating `rootShadowNode_` in unique manner if it hasn't changed. - std::unique_lock lock(commitMutex_); + std::unique_lock lock(commitMutex_); if (rootShadowNode_ != oldRootShadowNode) { return false; diff --git a/ReactCommon/fabric/uimanager/ShadowTree.h b/ReactCommon/fabric/uimanager/ShadowTree.h index 41f328292..328119197 100644 --- a/ReactCommon/fabric/uimanager/ShadowTree.h +++ b/ReactCommon/fabric/uimanager/ShadowTree.h @@ -5,9 +5,8 @@ #pragma once -#include +#include #include -#include #include #include @@ -84,7 +83,7 @@ class ShadowTree final { void emitLayoutEvents(const ShadowViewMutationList &mutations) const; const SurfaceId surfaceId_; - mutable folly::SharedMutex commitMutex_; + mutable better::shared_mutex commitMutex_; mutable SharedRootShadowNode rootShadowNode_; // Protected by `commitMutex_`. mutable int revision_{1}; // Protected by `commitMutex_`. ShadowTreeDelegate const *delegate_; diff --git a/ReactCommon/fabric/uimanager/ShadowTreeRegistry.cpp b/ReactCommon/fabric/uimanager/ShadowTreeRegistry.cpp index 24babca90..9275b50ba 100644 --- a/ReactCommon/fabric/uimanager/ShadowTreeRegistry.cpp +++ b/ReactCommon/fabric/uimanager/ShadowTreeRegistry.cpp @@ -9,14 +9,14 @@ namespace facebook { namespace react { void ShadowTreeRegistry::add(std::unique_ptr &&shadowTree) const { - std::unique_lock lock(mutex_); + std::unique_lock lock(mutex_); registry_.emplace(shadowTree->getSurfaceId(), std::move(shadowTree)); } std::unique_ptr ShadowTreeRegistry::remove( SurfaceId surfaceId) const { - std::unique_lock lock(mutex_); + std::unique_lock lock(mutex_); auto iterator = registry_.find(surfaceId); auto shadowTree = std::unique_ptr(iterator->second.release()); @@ -27,7 +27,7 @@ std::unique_ptr ShadowTreeRegistry::remove( bool ShadowTreeRegistry::visit( SurfaceId surfaceId, std::function callback) const { - std::shared_lock lock(mutex_); + std::shared_lock lock(mutex_); auto iterator = registry_.find(surfaceId); diff --git a/ReactCommon/fabric/uimanager/ShadowTreeRegistry.h b/ReactCommon/fabric/uimanager/ShadowTreeRegistry.h index 24ac33a88..06549953c 100644 --- a/ReactCommon/fabric/uimanager/ShadowTreeRegistry.h +++ b/ReactCommon/fabric/uimanager/ShadowTreeRegistry.h @@ -5,8 +5,7 @@ #pragma once -#include -#include +#include #include #include @@ -49,7 +48,7 @@ class ShadowTreeRegistry final { std::function callback) const; private: - mutable folly::SharedMutex mutex_; + mutable better::shared_mutex mutex_; mutable std::unordered_map> registry_; // Protected by `mutex_`. };