From fda042e289bef05ec9e1287b831f36e4a8f9b5bf Mon Sep 17 00:00:00 2001 From: Vikas batchu Date: Thu, 3 Mar 2022 18:00:27 +0530 Subject: [PATCH] displayconfig: Restrict the scope of death_service_mutex_ Multiple display config calls is causing deadlock when one of them is waiting for commit and there are no free binder threads. - Allow perform calls to run concurrently. - Execute service death callback exclusively. Change-Id: I804e72d4961315c6fac13f5f967788b5bbc0febe --- services/config/src/device_impl.cpp | 20 +++++++++++++------- services/config/src/device_impl.h | 2 ++ 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/services/config/src/device_impl.cpp b/services/config/src/device_impl.cpp index 4541368..c8f64dc 100644 --- a/services/config/src/device_impl.cpp +++ b/services/config/src/device_impl.cpp @@ -146,6 +146,7 @@ Return DeviceImpl::registerClient(const hidl_string &client_name, void DeviceImpl::serviceDied(uint64_t client_handle, const android::wp<::android::hidl::base::V1_0::IBase>& callback) { + std::lock_guard exclusive_lock(shared_mutex_); std::lock_guard lock(death_service_mutex_); auto itr = display_config_map_.find(client_handle); std::shared_ptr client = itr->second; @@ -989,16 +990,21 @@ void DeviceImpl::DeviceClientContext::ParseSetWiderModePreference(const ByteStre Return DeviceImpl::perform(uint64_t client_handle, uint32_t op_code, const ByteStream &input_params, const HandleStream &input_handles, perform_cb _hidl_cb) { + std::shared_lock shared_lock(shared_mutex_); int32_t error = 0; - std::lock_guard lock(death_service_mutex_); - auto itr = display_config_map_.find(client_handle); - if (itr == display_config_map_.end()) { - error = -EINVAL; - _hidl_cb(error, {}, {}); - return Void(); + std::shared_ptr client = nullptr; + + { + std::lock_guard lock(death_service_mutex_); + auto itr = display_config_map_.find(client_handle); + if (itr == display_config_map_.end()) { + error = -EINVAL; + _hidl_cb(error, {}, {}); + return Void(); + } + client = itr->second; } - std::shared_ptr client = itr->second; if (!client) { error = -EINVAL; _hidl_cb(error, {}, {}); diff --git a/services/config/src/device_impl.h b/services/config/src/device_impl.h index cf60366..3433d05 100644 --- a/services/config/src/device_impl.h +++ b/services/config/src/device_impl.h @@ -74,6 +74,7 @@ #include #include #include +#include #include "opcode_types.h" @@ -187,6 +188,7 @@ class DeviceImpl : public IDisplayConfig, public android::hardware::hidl_death_r std::map> display_config_map_; uint64_t client_id_ = 0; std::recursive_mutex death_service_mutex_; + std::shared_mutex shared_mutex_; static DeviceImpl *device_obj_; static std::mutex device_lock_; };