Remove shared mutex from FML and use the C++17 variants. (flutter/engine#54482)

We used to require this only on iOS because the standard library till iOS 9 didn't have support for this. We have moved past that version. No change on other platforms.
This commit is contained in:
Chinmay Garde 2024-08-09 15:59:58 -07:00 committed by GitHub
parent 109cffe312
commit c2992b3273
16 changed files with 34 additions and 231 deletions

View File

@ -42563,8 +42563,6 @@ ORIGIN: ../../../flutter/fml/platform/posix/native_library_posix.cc + ../../../f
ORIGIN: ../../../flutter/fml/platform/posix/paths_posix.cc + ../../../flutter/LICENSE ORIGIN: ../../../flutter/fml/platform/posix/paths_posix.cc + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/fml/platform/posix/posix_wrappers_posix.cc + ../../../flutter/LICENSE ORIGIN: ../../../flutter/fml/platform/posix/posix_wrappers_posix.cc + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/fml/platform/posix/process_posix.cc + ../../../flutter/LICENSE ORIGIN: ../../../flutter/fml/platform/posix/process_posix.cc + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/fml/platform/posix/shared_mutex_posix.cc + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/fml/platform/posix/shared_mutex_posix.h + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/fml/platform/win/command_line_win.cc + ../../../flutter/LICENSE ORIGIN: ../../../flutter/fml/platform/win/command_line_win.cc + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/fml/platform/win/errors_win.cc + ../../../flutter/LICENSE ORIGIN: ../../../flutter/fml/platform/win/errors_win.cc + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/fml/platform/win/errors_win.h + ../../../flutter/LICENSE ORIGIN: ../../../flutter/fml/platform/win/errors_win.h + ../../../flutter/LICENSE
@ -42593,9 +42591,6 @@ ORIGIN: ../../../flutter/fml/synchronization/count_down_latch.cc + ../../../flut
ORIGIN: ../../../flutter/fml/synchronization/count_down_latch.h + ../../../flutter/LICENSE ORIGIN: ../../../flutter/fml/synchronization/count_down_latch.h + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/fml/synchronization/semaphore.cc + ../../../flutter/LICENSE ORIGIN: ../../../flutter/fml/synchronization/semaphore.cc + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/fml/synchronization/semaphore.h + ../../../flutter/LICENSE ORIGIN: ../../../flutter/fml/synchronization/semaphore.h + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/fml/synchronization/shared_mutex.h + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/fml/synchronization/shared_mutex_std.cc + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/fml/synchronization/shared_mutex_std.h + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/fml/synchronization/sync_switch.cc + ../../../flutter/LICENSE ORIGIN: ../../../flutter/fml/synchronization/sync_switch.cc + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/fml/synchronization/sync_switch.h + ../../../flutter/LICENSE ORIGIN: ../../../flutter/fml/synchronization/sync_switch.h + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/fml/synchronization/waitable_event.cc + ../../../flutter/LICENSE ORIGIN: ../../../flutter/fml/synchronization/waitable_event.cc + ../../../flutter/LICENSE
@ -45400,8 +45395,6 @@ FILE: ../../../flutter/fml/platform/posix/native_library_posix.cc
FILE: ../../../flutter/fml/platform/posix/paths_posix.cc FILE: ../../../flutter/fml/platform/posix/paths_posix.cc
FILE: ../../../flutter/fml/platform/posix/posix_wrappers_posix.cc FILE: ../../../flutter/fml/platform/posix/posix_wrappers_posix.cc
FILE: ../../../flutter/fml/platform/posix/process_posix.cc FILE: ../../../flutter/fml/platform/posix/process_posix.cc
FILE: ../../../flutter/fml/platform/posix/shared_mutex_posix.cc
FILE: ../../../flutter/fml/platform/posix/shared_mutex_posix.h
FILE: ../../../flutter/fml/platform/win/command_line_win.cc FILE: ../../../flutter/fml/platform/win/command_line_win.cc
FILE: ../../../flutter/fml/platform/win/errors_win.cc FILE: ../../../flutter/fml/platform/win/errors_win.cc
FILE: ../../../flutter/fml/platform/win/errors_win.h FILE: ../../../flutter/fml/platform/win/errors_win.h
@ -45430,9 +45423,6 @@ FILE: ../../../flutter/fml/synchronization/count_down_latch.cc
FILE: ../../../flutter/fml/synchronization/count_down_latch.h FILE: ../../../flutter/fml/synchronization/count_down_latch.h
FILE: ../../../flutter/fml/synchronization/semaphore.cc FILE: ../../../flutter/fml/synchronization/semaphore.cc
FILE: ../../../flutter/fml/synchronization/semaphore.h FILE: ../../../flutter/fml/synchronization/semaphore.h
FILE: ../../../flutter/fml/synchronization/shared_mutex.h
FILE: ../../../flutter/fml/synchronization/shared_mutex_std.cc
FILE: ../../../flutter/fml/synchronization/shared_mutex_std.h
FILE: ../../../flutter/fml/synchronization/sync_switch.cc FILE: ../../../flutter/fml/synchronization/sync_switch.cc
FILE: ../../../flutter/fml/synchronization/sync_switch.h FILE: ../../../flutter/fml/synchronization/sync_switch.h
FILE: ../../../flutter/fml/synchronization/waitable_event.cc FILE: ../../../flutter/fml/synchronization/waitable_event.cc

View File

@ -78,7 +78,6 @@ source_set("fml") {
"synchronization/count_down_latch.h", "synchronization/count_down_latch.h",
"synchronization/semaphore.cc", "synchronization/semaphore.cc",
"synchronization/semaphore.h", "synchronization/semaphore.h",
"synchronization/shared_mutex.h",
"synchronization/sync_switch.cc", "synchronization/sync_switch.cc",
"synchronization/sync_switch.h", "synchronization/sync_switch.h",
"synchronization/waitable_event.cc", "synchronization/waitable_event.cc",
@ -136,15 +135,9 @@ source_set("fml") {
libs = [] libs = []
if (is_ios || is_mac) { if (is_ios || is_mac) {
sources += [ sources += [ "platform/darwin/concurrent_message_loop_factory.mm" ]
"platform/darwin/concurrent_message_loop_factory.mm",
"platform/posix/shared_mutex_posix.cc",
]
} else { } else {
sources += [ sources += [ "concurrent_message_loop_factory.cc" ]
"concurrent_message_loop_factory.cc",
"synchronization/shared_mutex_std.cc",
]
} }
if (is_ios || is_mac) { if (is_ios || is_mac) {

View File

@ -15,7 +15,6 @@
#include "flutter/fml/delayed_task.h" #include "flutter/fml/delayed_task.h"
#include "flutter/fml/macros.h" #include "flutter/fml/macros.h"
#include "flutter/fml/memory/ref_counted.h" #include "flutter/fml/memory/ref_counted.h"
#include "flutter/fml/synchronization/shared_mutex.h"
#include "flutter/fml/task_queue_id.h" #include "flutter/fml/task_queue_id.h"
#include "flutter/fml/task_source.h" #include "flutter/fml/task_source.h"
#include "flutter/fml/wakeable.h" #include "flutter/fml/wakeable.h"

View File

@ -1,35 +0,0 @@
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "flutter/fml/platform/posix/shared_mutex_posix.h"
#include "flutter/fml/logging.h"
namespace fml {
SharedMutex* SharedMutex::Create() {
return new SharedMutexPosix();
}
SharedMutexPosix::SharedMutexPosix() {
FML_CHECK(pthread_rwlock_init(&rwlock_, nullptr) == 0);
}
void SharedMutexPosix::Lock() {
pthread_rwlock_wrlock(&rwlock_);
}
void SharedMutexPosix::LockShared() {
pthread_rwlock_rdlock(&rwlock_);
}
void SharedMutexPosix::Unlock() {
pthread_rwlock_unlock(&rwlock_);
}
void SharedMutexPosix::UnlockShared() {
pthread_rwlock_unlock(&rwlock_);
}
} // namespace fml

View File

@ -1,30 +0,0 @@
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef FLUTTER_FML_PLATFORM_POSIX_SHARED_MUTEX_POSIX_H_
#define FLUTTER_FML_PLATFORM_POSIX_SHARED_MUTEX_POSIX_H_
#include <shared_mutex>
#include "flutter/fml/synchronization/shared_mutex.h"
namespace fml {
class SharedMutexPosix : public SharedMutex {
public:
virtual void Lock();
virtual void LockShared();
virtual void Unlock();
virtual void UnlockShared();
private:
friend SharedMutex* SharedMutex::Create();
SharedMutexPosix();
pthread_rwlock_t rwlock_;
};
} // namespace fml
#endif // FLUTTER_FML_PLATFORM_POSIX_SHARED_MUTEX_POSIX_H_

View File

@ -1,50 +0,0 @@
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef FLUTTER_FML_SYNCHRONIZATION_SHARED_MUTEX_H_
#define FLUTTER_FML_SYNCHRONIZATION_SHARED_MUTEX_H_
namespace fml {
// Interface for a reader/writer lock.
class SharedMutex {
public:
static SharedMutex* Create();
virtual ~SharedMutex() = default;
virtual void Lock() = 0;
virtual void LockShared() = 0;
virtual void Unlock() = 0;
virtual void UnlockShared() = 0;
};
// RAII wrapper that does a shared acquire of a SharedMutex.
class SharedLock {
public:
explicit SharedLock(SharedMutex& shared_mutex) : shared_mutex_(shared_mutex) {
shared_mutex_.LockShared();
}
~SharedLock() { shared_mutex_.UnlockShared(); }
private:
SharedMutex& shared_mutex_;
};
// RAII wrapper that does an exclusive acquire of a SharedMutex.
class UniqueLock {
public:
explicit UniqueLock(SharedMutex& shared_mutex) : shared_mutex_(shared_mutex) {
shared_mutex_.Lock();
}
~UniqueLock() { shared_mutex_.Unlock(); }
private:
SharedMutex& shared_mutex_;
};
} // namespace fml
#endif // FLUTTER_FML_SYNCHRONIZATION_SHARED_MUTEX_H_

View File

@ -1,29 +0,0 @@
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "flutter/fml/synchronization/shared_mutex_std.h"
namespace fml {
SharedMutex* SharedMutex::Create() {
return new SharedMutexStd();
}
void SharedMutexStd::Lock() {
mutex_.lock();
}
void SharedMutexStd::LockShared() {
mutex_.lock_shared();
}
void SharedMutexStd::Unlock() {
mutex_.unlock();
}
void SharedMutexStd::UnlockShared() {
mutex_.unlock_shared();
}
} // namespace fml

View File

@ -1,30 +0,0 @@
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef FLUTTER_FML_SYNCHRONIZATION_SHARED_MUTEX_STD_H_
#define FLUTTER_FML_SYNCHRONIZATION_SHARED_MUTEX_STD_H_
#include "flutter/fml/synchronization/shared_mutex.h"
#include <shared_mutex>
namespace fml {
class SharedMutexStd : public SharedMutex {
public:
virtual void Lock();
virtual void LockShared();
virtual void Unlock();
virtual void UnlockShared();
private:
friend SharedMutex* SharedMutex::Create();
SharedMutexStd() = default;
std::shared_timed_mutex mutex_;
};
} // namespace fml
#endif // FLUTTER_FML_SYNCHRONIZATION_SHARED_MUTEX_STD_H_

View File

@ -20,12 +20,10 @@ SyncSwitch::Handlers& SyncSwitch::Handlers::SetIfFalse(
return *this; return *this;
} }
SyncSwitch::SyncSwitch(bool value) SyncSwitch::SyncSwitch(bool value) : value_(value) {}
: mutex_(std::unique_ptr<fml::SharedMutex>(fml::SharedMutex::Create())),
value_(value) {}
void SyncSwitch::Execute(const SyncSwitch::Handlers& handlers) const { void SyncSwitch::Execute(const SyncSwitch::Handlers& handlers) const {
fml::SharedLock lock(*mutex_); std::shared_lock lock(mutex_);
if (value_) { if (value_) {
handlers.true_handler(); handlers.true_handler();
} else { } else {
@ -35,7 +33,7 @@ void SyncSwitch::Execute(const SyncSwitch::Handlers& handlers) const {
void SyncSwitch::SetSwitch(bool value) { void SyncSwitch::SetSwitch(bool value) {
{ {
fml::UniqueLock lock(*mutex_); std::unique_lock lock(mutex_);
value_ = value; value_ = value;
} }
for (Observer* observer : observers_) { for (Observer* observer : observers_) {
@ -44,7 +42,7 @@ void SyncSwitch::SetSwitch(bool value) {
} }
void SyncSwitch::AddObserver(Observer* observer) const { void SyncSwitch::AddObserver(Observer* observer) const {
fml::UniqueLock lock(*mutex_); std::unique_lock lock(mutex_);
if (std::find(observers_.begin(), observers_.end(), observer) == if (std::find(observers_.begin(), observers_.end(), observer) ==
observers_.end()) { observers_.end()) {
observers_.push_back(observer); observers_.push_back(observer);
@ -52,7 +50,7 @@ void SyncSwitch::AddObserver(Observer* observer) const {
} }
void SyncSwitch::RemoveObserver(Observer* observer) const { void SyncSwitch::RemoveObserver(Observer* observer) const {
fml::UniqueLock lock(*mutex_); std::unique_lock lock(mutex_);
observers_.erase(std::remove(observers_.begin(), observers_.end(), observer), observers_.erase(std::remove(observers_.begin(), observers_.end(), observer),
observers_.end()); observers_.end());
} }

View File

@ -7,10 +7,10 @@
#include <functional> #include <functional>
#include <memory> #include <memory>
#include <shared_mutex>
#include <vector> #include <vector>
#include "flutter/fml/macros.h" #include "flutter/fml/macros.h"
#include "flutter/fml/synchronization/shared_mutex.h"
namespace fml { namespace fml {
@ -70,7 +70,7 @@ class SyncSwitch {
void RemoveObserver(Observer* observer) const; void RemoveObserver(Observer* observer) const;
private: private:
mutable std::unique_ptr<fml::SharedMutex> mutex_; mutable std::shared_mutex mutex_;
mutable std::vector<Observer*> observers_; mutable std::vector<Observer*> observers_;
bool value_; bool value_;

View File

@ -10,9 +10,9 @@
#include <functional> #include <functional>
#include <memory> #include <memory>
#include <mutex> #include <mutex>
#include <shared_mutex>
#include <thread> #include <thread>
#include "flutter/fml/synchronization/shared_mutex.h"
#include "impeller/base/thread_safety.h" #include "impeller/base/thread_safety.h"
namespace impeller { namespace impeller {
@ -45,21 +45,20 @@ class IPLR_CAPABILITY("mutex") Mutex {
class IPLR_CAPABILITY("mutex") RWMutex { class IPLR_CAPABILITY("mutex") RWMutex {
public: public:
RWMutex() RWMutex() = default;
: mutex_(std::unique_ptr<fml::SharedMutex>(fml::SharedMutex::Create())) {}
~RWMutex() = default; ~RWMutex() = default;
void LockWriter() IPLR_ACQUIRE() { mutex_->Lock(); } void LockWriter() IPLR_ACQUIRE() { mutex_.lock(); }
void UnlockWriter() IPLR_RELEASE() { mutex_->Unlock(); } void UnlockWriter() IPLR_RELEASE() { mutex_.unlock(); }
void LockReader() IPLR_ACQUIRE_SHARED() { mutex_->LockShared(); } void LockReader() IPLR_ACQUIRE_SHARED() { mutex_.lock_shared(); }
void UnlockReader() IPLR_RELEASE_SHARED() { mutex_->UnlockShared(); } void UnlockReader() IPLR_RELEASE_SHARED() { mutex_.unlock_shared(); }
private: private:
std::unique_ptr<fml::SharedMutex> mutex_; std::shared_mutex mutex_;
RWMutex(const RWMutex&) = delete; RWMutex(const RWMutex&) = delete;

View File

@ -7,7 +7,6 @@
#include <atomic> #include <atomic>
#include "flutter/fml/logging.h" #include "flutter/fml/logging.h"
#include "flutter/fml/synchronization/shared_mutex.h"
#include "flutter/fml/trace_event.h" #include "flutter/fml/trace_event.h"
#include "flutter/lib/ui/ui_dart_state.h" #include "flutter/lib/ui/ui_dart_state.h"
#include "flutter/lib/ui/window/platform_configuration.h" #include "flutter/lib/ui/window/platform_configuration.h"

View File

@ -59,8 +59,7 @@ ServiceProtocol::ServiceProtocol()
kGetSkSLsExtensionName, kGetSkSLsExtensionName,
kEstimateRasterCacheMemoryExtensionName, kEstimateRasterCacheMemoryExtensionName,
kReloadAssetFonts, kReloadAssetFonts,
}), }) {}
handlers_mutex_(fml::SharedMutex::Create()) {}
ServiceProtocol::~ServiceProtocol() { ServiceProtocol::~ServiceProtocol() {
ToggleHooks(false); ToggleHooks(false);
@ -68,19 +67,19 @@ ServiceProtocol::~ServiceProtocol() {
void ServiceProtocol::AddHandler(Handler* handler, void ServiceProtocol::AddHandler(Handler* handler,
const Handler::Description& description) { const Handler::Description& description) {
fml::UniqueLock lock(*handlers_mutex_); std::unique_lock lock(handlers_mutex_);
handlers_.emplace(handler, description); handlers_.emplace(handler, description);
} }
void ServiceProtocol::RemoveHandler(Handler* handler) { void ServiceProtocol::RemoveHandler(Handler* handler) {
fml::UniqueLock lock(*handlers_mutex_); std::unique_lock lock(handlers_mutex_);
handlers_.erase(handler); handlers_.erase(handler);
} }
void ServiceProtocol::SetHandlerDescription( void ServiceProtocol::SetHandlerDescription(
Handler* handler, Handler* handler,
const Handler::Description& description) { const Handler::Description& description) {
fml::SharedLock lock(*handlers_mutex_); std::shared_lock lock(handlers_mutex_);
auto it = handlers_.find(handler); auto it = handlers_.find(handler);
if (it != handlers_.end()) { if (it != handlers_.end()) {
it->second.Store(description); it->second.Store(description);
@ -191,7 +190,7 @@ bool ServiceProtocol::HandleMessage(std::string_view method,
return HandleListViewsMethod(response); return HandleListViewsMethod(response);
} }
fml::SharedLock lock(*handlers_mutex_); std::shared_lock lock(handlers_mutex_);
if (handlers_.empty()) { if (handlers_.empty()) {
WriteServerErrorResponse(response, WriteServerErrorResponse(response,
@ -262,7 +261,7 @@ void ServiceProtocol::Handler::Description::Write(
bool ServiceProtocol::HandleListViewsMethod( bool ServiceProtocol::HandleListViewsMethod(
rapidjson::Document* response) const { rapidjson::Document* response) const {
fml::SharedLock lock(*handlers_mutex_); std::shared_lock lock(handlers_mutex_);
std::vector<std::pair<intptr_t, Handler::Description>> descriptions; std::vector<std::pair<intptr_t, Handler::Description>> descriptions;
descriptions.reserve(handlers_.size()); descriptions.reserve(handlers_.size());
for (const auto& handler : handlers_) { for (const auto& handler : handlers_) {

View File

@ -7,12 +7,12 @@
#include <map> #include <map>
#include <set> #include <set>
#include <shared_mutex>
#include <string> #include <string>
#include <string_view> #include <string_view>
#include "flutter/fml/macros.h" #include "flutter/fml/macros.h"
#include "flutter/fml/synchronization/atomic_object.h" #include "flutter/fml/synchronization/atomic_object.h"
#include "flutter/fml/synchronization/shared_mutex.h"
#include "flutter/fml/task_runner.h" #include "flutter/fml/task_runner.h"
#include "rapidjson/document.h" #include "rapidjson/document.h"
@ -75,7 +75,7 @@ class ServiceProtocol {
private: private:
const std::set<std::string_view> endpoints_; const std::set<std::string_view> endpoints_;
std::unique_ptr<fml::SharedMutex> handlers_mutex_; mutable std::shared_mutex handlers_mutex_;
std::map<Handler*, fml::AtomicObject<Handler::Description>> handlers_; std::map<Handler*, fml::AtomicObject<Handler::Description>> handlers_;
[[nodiscard]] static bool HandleMessage(const char* method, [[nodiscard]] static bool HandleMessage(const char* method,

View File

@ -7,6 +7,7 @@
#include <dwmapi.h> #include <dwmapi.h>
#include <filesystem> #include <filesystem>
#include <shared_mutex>
#include <sstream> #include <sstream>
#include "flutter/fml/logging.h" #include "flutter/fml/logging.h"
@ -150,7 +151,6 @@ FlutterWindowsEngine::FlutterWindowsEngine(
: project_(std::make_unique<FlutterProjectBundle>(project)), : project_(std::make_unique<FlutterProjectBundle>(project)),
windows_proc_table_(std::move(windows_proc_table)), windows_proc_table_(std::move(windows_proc_table)),
aot_data_(nullptr, nullptr), aot_data_(nullptr, nullptr),
views_mutex_(fml::SharedMutex::Create()),
lifecycle_manager_(std::make_unique<WindowsLifecycleManager>(this)) { lifecycle_manager_(std::make_unique<WindowsLifecycleManager>(this)) {
if (windows_proc_table_ == nullptr) { if (windows_proc_table_ == nullptr) {
windows_proc_table_ = std::make_shared<WindowsProcTable>(); windows_proc_table_ = std::make_shared<WindowsProcTable>();
@ -505,7 +505,7 @@ std::unique_ptr<FlutterWindowsView> FlutterWindowsEngine::CreateView(
{ {
// Add the view to the embedder. This must happen before the engine // Add the view to the embedder. This must happen before the engine
// is notified the view exists and starts presenting to it. // is notified the view exists and starts presenting to it.
fml::UniqueLock write_lock{*views_mutex_}; std::unique_lock write_lock(views_mutex_);
FML_DCHECK(views_.find(view_id) == views_.end()); FML_DCHECK(views_.find(view_id) == views_.end());
views_[view_id] = view.get(); views_[view_id] = view.get();
} }
@ -554,7 +554,7 @@ std::unique_ptr<FlutterWindowsView> FlutterWindowsEngine::CreateView(
// engine's state. This is unexpected and indicates a bug in the Windows // engine's state. This is unexpected and indicates a bug in the Windows
// embedder. // embedder.
FML_LOG(ERROR) << "FlutterEngineAddView failed to add view"; FML_LOG(ERROR) << "FlutterEngineAddView failed to add view";
fml::UniqueLock write_lock{*views_mutex_}; std::unique_lock write_lock(views_mutex_);
views_.erase(view_id); views_.erase(view_id);
return nullptr; return nullptr;
} }
@ -618,7 +618,7 @@ void FlutterWindowsEngine::RemoveView(FlutterViewId view_id) {
{ {
// The engine no longer presents to the view. Remove the view from the // The engine no longer presents to the view. Remove the view from the
// embedder. // embedder.
fml::UniqueLock write_lock{*views_mutex_}; std::unique_lock write_lock(views_mutex_);
FML_DCHECK(views_.find(view_id) != views_.end()); FML_DCHECK(views_.find(view_id) != views_.end());
views_.erase(view_id); views_.erase(view_id);
@ -654,7 +654,7 @@ std::chrono::nanoseconds FlutterWindowsEngine::FrameInterval() {
} }
FlutterWindowsView* FlutterWindowsEngine::view(FlutterViewId view_id) const { FlutterWindowsView* FlutterWindowsEngine::view(FlutterViewId view_id) const {
fml::SharedLock read_lock{*views_mutex_}; std::shared_lock read_lock(views_mutex_);
auto iterator = views_.find(view_id); auto iterator = views_.find(view_id);
if (iterator == views_.end()) { if (iterator == views_.end()) {
@ -884,7 +884,7 @@ bool FlutterWindowsEngine::DispatchSemanticsAction(
void FlutterWindowsEngine::UpdateSemanticsEnabled(bool enabled) { void FlutterWindowsEngine::UpdateSemanticsEnabled(bool enabled) {
if (engine_ && semantics_enabled_ != enabled) { if (engine_ && semantics_enabled_ != enabled) {
fml::SharedLock read_lock{*views_mutex_}; std::shared_lock read_lock(views_mutex_);
semantics_enabled_ = enabled; semantics_enabled_ = enabled;
embedder_api_.UpdateSemanticsEnabled(engine_, enabled); embedder_api_.UpdateSemanticsEnabled(engine_, enabled);
@ -951,7 +951,7 @@ void FlutterWindowsEngine::OnQuit(std::optional<HWND> hwnd,
} }
void FlutterWindowsEngine::OnDwmCompositionChanged() { void FlutterWindowsEngine::OnDwmCompositionChanged() {
fml::SharedLock read_lock{*views_mutex_}; std::shared_lock read_lock(views_mutex_);
for (auto iterator = views_.begin(); iterator != views_.end(); iterator++) { for (auto iterator = views_.begin(); iterator != views_.end(); iterator++) {
iterator->second->OnDwmCompositionChanged(); iterator->second->OnDwmCompositionChanged();
@ -987,7 +987,7 @@ bool FlutterWindowsEngine::Present(const FlutterPresentViewInfo* info) {
// This runs on the raster thread. Lock the views map for the entirety of the // This runs on the raster thread. Lock the views map for the entirety of the
// present operation to block the platform thread from destroying the // present operation to block the platform thread from destroying the
// view during the present. // view during the present.
fml::SharedLock read_lock{*views_mutex_}; std::shared_lock read_lock(views_mutex_);
auto iterator = views_.find(info->view_id); auto iterator = views_.find(info->view_id);
if (iterator == views_.end()) { if (iterator == views_.end()) {

View File

@ -9,6 +9,7 @@
#include <map> #include <map>
#include <memory> #include <memory>
#include <optional> #include <optional>
#include <shared_mutex>
#include <string> #include <string>
#include <string_view> #include <string_view>
#include <unordered_map> #include <unordered_map>
@ -16,7 +17,6 @@
#include "flutter/fml/closure.h" #include "flutter/fml/closure.h"
#include "flutter/fml/macros.h" #include "flutter/fml/macros.h"
#include "flutter/fml/synchronization/shared_mutex.h"
#include "flutter/shell/platform/common/accessibility_bridge.h" #include "flutter/shell/platform/common/accessibility_bridge.h"
#include "flutter/shell/platform/common/app_lifecycle_state.h" #include "flutter/shell/platform/common/app_lifecycle_state.h"
#include "flutter/shell/platform/common/client_wrapper/binary_messenger_impl.h" #include "flutter/shell/platform/common/client_wrapper/binary_messenger_impl.h"
@ -384,7 +384,7 @@ class FlutterWindowsEngine {
// The platform thread acquires a shared lock to access the view. // The platform thread acquires a shared lock to access the view.
// The platform thread acquires an exclusive lock before adding // The platform thread acquires an exclusive lock before adding
// a view to the engine or after removing a view from the engine. // a view to the engine or after removing a view from the engine.
std::unique_ptr<fml::SharedMutex> views_mutex_; mutable std::shared_mutex views_mutex_;
// Task runner for tasks posted from the engine. // Task runner for tasks posted from the engine.
std::unique_ptr<TaskRunner> task_runner_; std::unique_ptr<TaskRunner> task_runner_;