From 9ba5561566dedfa5dace0609532959d3d3919606 Mon Sep 17 00:00:00 2001 From: Jason Simmons Date: Sat, 17 Nov 2018 12:27:06 -0800 Subject: [PATCH] Revert "Guard the service protocol's global handlers list with a reader/writer lock (#6888)" (#6893) This reverts commit 9352360c8bdc14bc746f8db1142925f960cf2c38. (shared_timed_mutex is unavailable in the iOS build) --- ci/licenses_golden/licenses_flutter | 1 - fml/BUILD.gn | 1 - fml/synchronization/atomic_object.h | 30 ----------------------------- runtime/service_protocol.cc | 15 ++++++++------- runtime/service_protocol.h | 7 +++---- 5 files changed, 11 insertions(+), 43 deletions(-) delete mode 100644 fml/synchronization/atomic_object.h diff --git a/ci/licenses_golden/licenses_flutter b/ci/licenses_golden/licenses_flutter index 3fb752a625..2fc0c7a9f6 100644 --- a/ci/licenses_golden/licenses_flutter +++ b/ci/licenses_golden/licenses_flutter @@ -176,7 +176,6 @@ FILE: ../../../flutter/fml/platform/win/wstring_conversion.h FILE: ../../../flutter/fml/string_view.cc FILE: ../../../flutter/fml/string_view.h FILE: ../../../flutter/fml/string_view_unittest.cc -FILE: ../../../flutter/fml/synchronization/atomic_object.h FILE: ../../../flutter/fml/synchronization/count_down_latch.cc FILE: ../../../flutter/fml/synchronization/count_down_latch.h FILE: ../../../flutter/fml/synchronization/count_down_latch_unittests.cc diff --git a/fml/BUILD.gn b/fml/BUILD.gn index 10d8e01c7c..f73f7f4071 100644 --- a/fml/BUILD.gn +++ b/fml/BUILD.gn @@ -46,7 +46,6 @@ source_set("fml") { "paths.h", "string_view.cc", "string_view.h", - "synchronization/atomic_object.h", "synchronization/count_down_latch.cc", "synchronization/count_down_latch.h", "synchronization/thread_annotations.h", diff --git a/fml/synchronization/atomic_object.h b/fml/synchronization/atomic_object.h deleted file mode 100644 index c14af79acf..0000000000 --- a/fml/synchronization/atomic_object.h +++ /dev/null @@ -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. - -#include - -namespace fml { - -template -class AtomicObject { - public: - AtomicObject() = default; - AtomicObject(T object) : object_(object) {} - - T Load() const { - std::lock_guard lock(mutex_); - return object_; - } - - void Store(const T& object) { - std::lock_guard lock(mutex_); - object_ = object; - } - - private: - mutable std::mutex mutex_; - T object_; -}; - -} // namespace fml diff --git a/runtime/service_protocol.cc b/runtime/service_protocol.cc index 449f1b2cd1..602ebccf64 100644 --- a/runtime/service_protocol.cc +++ b/runtime/service_protocol.cc @@ -53,21 +53,21 @@ ServiceProtocol::~ServiceProtocol() { void ServiceProtocol::AddHandler(Handler* handler, Handler::Description description) { - std::unique_lock lock(handlers_mutex_); + std::lock_guard lock(handlers_mutex_); handlers_.emplace(handler, description); } void ServiceProtocol::RemoveHandler(Handler* handler) { - std::unique_lock lock(handlers_mutex_); + std::lock_guard lock(handlers_mutex_); handlers_.erase(handler); } void ServiceProtocol::SetHandlerDescription(Handler* handler, Handler::Description description) { - std::shared_lock lock(handlers_mutex_); + std::lock_guard lock(handlers_mutex_); auto it = handlers_.find(handler); if (it != handlers_.end()) - it->second.Store(description); + it->second = description; } void ServiceProtocol::ToggleHooks(bool set) { @@ -175,7 +175,7 @@ bool ServiceProtocol::HandleMessage(fml::StringView method, return HandleListViewsMethod(response); } - std::shared_lock lock(handlers_mutex_); + std::lock_guard lock(handlers_mutex_); if (handlers_.size() == 0) { WriteServerErrorResponse(response, @@ -246,11 +246,12 @@ void ServiceProtocol::Handler::Description::Write( bool ServiceProtocol::HandleListViewsMethod( rapidjson::Document& response) const { - std::shared_lock lock(handlers_mutex_); + // Collect handler descriptions on their respective task runners. + std::lock_guard lock(handlers_mutex_); std::vector> descriptions; for (const auto& handler : handlers_) { descriptions.emplace_back(reinterpret_cast(handler.first), - handler.second.Load()); + handler.second); } auto& allocator = response.GetAllocator(); diff --git a/runtime/service_protocol.h b/runtime/service_protocol.h index 5392cae337..401702e5d5 100644 --- a/runtime/service_protocol.h +++ b/runtime/service_protocol.h @@ -6,14 +6,13 @@ #define FLUTTER_RUNTIME_SERVICE_PROTOCOL_H_ #include +#include #include -#include #include #include "flutter/fml/compiler_specific.h" #include "flutter/fml/macros.h" #include "flutter/fml/string_view.h" -#include "flutter/fml/synchronization/atomic_object.h" #include "flutter/fml/synchronization/thread_annotations.h" #include "flutter/fml/task_runner.h" #include "rapidjson/document.h" @@ -73,8 +72,8 @@ class ServiceProtocol { private: const std::set endpoints_; - mutable std::shared_timed_mutex handlers_mutex_; - std::map> handlers_; + mutable std::mutex handlers_mutex_; + std::map handlers_; FML_WARN_UNUSED_RESULT static bool HandleMessage(const char* method, -- GitLab