display: Handle service died request in a pending queue

CRs-Fixed: 3330287
Change-Id: Ie16c74a43d8ff849b7c555e88e653b1de684872a
diff --git a/services/config/src/device_impl.cpp b/services/config/src/device_impl.cpp
index 8c32a89..39bb02d 100644
--- a/services/config/src/device_impl.cpp
+++ b/services/config/src/device_impl.cpp
@@ -146,17 +146,9 @@
 
 void DeviceImpl::serviceDied(uint64_t client_handle,
                              const android::wp<::android::hidl::base::V1_0::IBase>& callback) {
-  std::lock_guard<std::shared_mutex> exclusive_lock(shared_mutex_);
   std::lock_guard<std::recursive_mutex> lock(death_service_mutex_);
-  auto itr = display_config_map_.find(client_handle);
-  std::shared_ptr<DeviceClientContext> client = itr->second;
-  if (client != NULL) {
-    ConfigInterface *intf = client->GetDeviceConfigIntf();
-    intf_->UnRegisterClientContext(intf);
-    client.reset();
+  pending_display_config_.push_back(client_handle);
     ALOGW("Client id:%lu service died", client_handle);
-    display_config_map_.erase(itr);
-  }
 }
 
 DeviceImpl::DeviceClientContext::DeviceClientContext(
@@ -899,12 +891,24 @@
 Return<void> 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<std::shared_mutex> shared_lock(shared_mutex_);
   int32_t error = 0;
   std::shared_ptr<DeviceClientContext> client = nullptr;
 
   {
     std::lock_guard<std::recursive_mutex> lock(death_service_mutex_);
+    for (auto& pending_client_handle : pending_display_config_) {
+      auto itr = display_config_map_.find(pending_client_handle);
+      std::shared_ptr<DeviceClientContext> pending_client = itr->second;
+      if (pending_client != NULL) {
+        ConfigInterface *pending_intf = pending_client->GetDeviceConfigIntf();
+        intf_->UnRegisterClientContext(pending_intf);
+        pending_client.reset();
+        ALOGI("clear old client id:%lu ", pending_client_handle);
+      }
+      display_config_map_.erase(itr);
+    }
+    pending_display_config_.clear();
+
     auto itr = display_config_map_.find(client_handle);
     if (itr == display_config_map_.end()) {
       error = -EINVAL;
diff --git a/services/config/src/device_impl.h b/services/config/src/device_impl.h
index c89be31..dd0e536 100644
--- a/services/config/src/device_impl.h
+++ b/services/config/src/device_impl.h
@@ -179,9 +179,9 @@
 
   ClientContext *intf_ = nullptr;
   std::map<uint64_t, std::shared_ptr<DeviceClientContext>> display_config_map_;
+  std::vector<uint64_t> pending_display_config_;
   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_;
 };