Skip to content

Commit

Permalink
Revert "Guard the service protocol's global handlers list with a read…
Browse files Browse the repository at this point in the history
…er/writer lock (#6888)" (#6893)

This reverts commit 9352360.

(shared_timed_mutex is unavailable in the iOS build)
jason-simmons authored Nov 17, 2018

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent 517e525 commit 9ba5561
Showing 5 changed files with 11 additions and 43 deletions.
1 change: 0 additions & 1 deletion ci/licenses_golden/licenses_flutter
Original file line number Diff line number Diff line change
@@ -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
1 change: 0 additions & 1 deletion fml/BUILD.gn
Original file line number Diff line number Diff line change
@@ -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",
30 changes: 0 additions & 30 deletions fml/synchronization/atomic_object.h

This file was deleted.

15 changes: 8 additions & 7 deletions runtime/service_protocol.cc
Original file line number Diff line number Diff line change
@@ -53,21 +53,21 @@ ServiceProtocol::~ServiceProtocol() {

void ServiceProtocol::AddHandler(Handler* handler,
Handler::Description description) {
std::unique_lock<std::shared_timed_mutex> lock(handlers_mutex_);
std::lock_guard<std::mutex> lock(handlers_mutex_);
handlers_.emplace(handler, description);
}

void ServiceProtocol::RemoveHandler(Handler* handler) {
std::unique_lock<std::shared_timed_mutex> lock(handlers_mutex_);
std::lock_guard<std::mutex> lock(handlers_mutex_);
handlers_.erase(handler);
}

void ServiceProtocol::SetHandlerDescription(Handler* handler,
Handler::Description description) {
std::shared_lock<std::shared_timed_mutex> lock(handlers_mutex_);
std::lock_guard<std::mutex> 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<std::shared_timed_mutex> lock(handlers_mutex_);
std::lock_guard<std::mutex> 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<std::shared_timed_mutex> lock(handlers_mutex_);
// Collect handler descriptions on their respective task runners.
std::lock_guard<std::mutex> lock(handlers_mutex_);
std::vector<std::pair<intptr_t, Handler::Description>> descriptions;
for (const auto& handler : handlers_) {
descriptions.emplace_back(reinterpret_cast<intptr_t>(handler.first),
handler.second.Load());
handler.second);
}

auto& allocator = response.GetAllocator();
7 changes: 3 additions & 4 deletions runtime/service_protocol.h
Original file line number Diff line number Diff line change
@@ -6,14 +6,13 @@
#define FLUTTER_RUNTIME_SERVICE_PROTOCOL_H_

#include <map>
#include <mutex>
#include <set>
#include <shared_mutex>
#include <string>

#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<fml::StringView> endpoints_;
mutable std::shared_timed_mutex handlers_mutex_;
std::map<Handler*, fml::AtomicObject<Handler::Description>> handlers_;
mutable std::mutex handlers_mutex_;
std::map<Handler*, Handler::Description> handlers_;

FML_WARN_UNUSED_RESULT
static bool HandleMessage(const char* method,

0 comments on commit 9ba5561

Please sign in to comment.