Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit c5dbcc28 authored by David Duarte's avatar David Duarte
Browse files

avrcp: Change device_map_lock into a recursive mutex

ConnectionHandler::CleanUp take the lock and calls
ConnectionHandler::AcceptorControlCB with AVRC_CLOSE_IND_EVT
which also takes the lock, so use a recursive_mutex.

Bug: 293248033
Bug: 292871599
Bug: 294942307
Bug: 294951334
Bug: 256938279
Test: manual, check that the disconnection sound effect
 of the headset is played when Bluetooth is turned off
Change-Id: I7e9a517c7c16937c549f851d5d535a67e33a90df
parent 2155829d
Loading
Loading
Loading
Loading
+9 −6
Original line number Diff line number Diff line
@@ -45,7 +45,10 @@ namespace avrcp {

ConnectionHandler* ConnectionHandler::instance_ = nullptr;

std::mutex device_map_lock;
// ConnectionHandler::CleanUp take the lock and calls
// ConnectionHandler::AcceptorControlCB with AVRC_CLOSE_IND_EVT
// which also takes the lock, so use a recursive_mutex.
std::recursive_mutex device_map_lock;

ConnectionHandler* ConnectionHandler::Get() {
  CHECK(instance_);
@@ -95,7 +98,7 @@ bool ConnectionHandler::CleanUp() {
  CHECK(instance_ != nullptr);

  // TODO (apanicke): Cleanup the SDP Entries here
  std::lock_guard<std::mutex> lock(device_map_lock);
  std::lock_guard<std::recursive_mutex> lock(device_map_lock);
  for (auto entry = instance_->device_map_.begin();
       entry != instance_->device_map_.end();) {
    auto curr = entry;
@@ -175,7 +178,7 @@ void ConnectionHandler::SetBipClientStatus(const RawAddress& bdaddr,
std::vector<std::shared_ptr<Device>> ConnectionHandler::GetListOfDevices()
    const {
  std::vector<std::shared_ptr<Device>> list;
  std::lock_guard<std::mutex> lock(device_map_lock);
  std::lock_guard<std::recursive_mutex> lock(device_map_lock);
  for (const auto& device : device_map_) {
    list.push_back(device.second);
  }
@@ -298,7 +301,7 @@ void ConnectionHandler::InitiatorControlCb(uint8_t handle, uint8_t event,
            << "Connection Close received from device that doesn't exist";
        return;
      }
      std::lock_guard<std::mutex> lock(device_map_lock);
      std::lock_guard<std::recursive_mutex> lock(device_map_lock);
      avrc_->Close(handle);
      feature_map_.erase(device_map_[handle]->GetAddress());
      device_map_[handle]->DeviceDisconnected();
@@ -344,7 +347,7 @@ void ConnectionHandler::AcceptorControlCb(uint8_t handle, uint8_t event,
          btif_av_peer_is_connected_source(*peer_addr)) {
        LOG(WARNING) << "peer is src, close new avrcp cback";
        if (device_map_.find(handle) != device_map_.end()) {
          std::lock_guard<std::mutex> lock(device_map_lock);
          std::lock_guard<std::recursive_mutex> lock(device_map_lock);
          feature_map_.erase(device_map_[handle]->GetAddress());
          device_map_[handle]->DeviceDisconnected();
          device_map_.erase(handle);
@@ -407,7 +410,7 @@ void ConnectionHandler::AcceptorControlCb(uint8_t handle, uint8_t event,
        return;
      }
      {
        std::lock_guard<std::mutex> lock(device_map_lock);
        std::lock_guard<std::recursive_mutex> lock(device_map_lock);
        feature_map_.erase(device_map_[handle]->GetAddress());
        device_map_[handle]->DeviceDisconnected();
        device_map_.erase(handle);