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

Commit c8984335 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "DO NOT MERGE Add mutex for std::map in btif_av.cc" into qt-dev

parents 633784fc 8af1a3e4
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@
#include <base/strings/stringprintf.h>
#include <string.h>
#include <map>
#include <mutex>

#include <hardware/bluetooth.h>
#include <hardware/bt_av.h>
@@ -530,6 +531,7 @@ class BtifAvSource {
  std::set<RawAddress> silenced_peers_;
  RawAddress active_peer_;
  std::map<uint8_t, tBTA_AV_HNDL> peer_id2bta_handle_;
  std::mutex mutex_;
};

class BtifAvSink {
@@ -647,6 +649,7 @@ class BtifAvSink {
  std::map<RawAddress, BtifAvPeer*> peers_;
  RawAddress active_peer_;
  std::map<uint8_t, tBTA_AV_HNDL> peer_id2bta_handle_;
  std::mutex mutex_;
};

/*****************************************************************************
@@ -1023,6 +1026,7 @@ BtifAvPeer* BtifAvSource::FindPeerByPeerId(uint8_t peer_id) {

BtifAvPeer* BtifAvSource::FindOrCreatePeer(const RawAddress& peer_address,
                                           tBTA_AV_HNDL bta_handle) {
  std::unique_lock<std::mutex> lock(mutex_);
  BTIF_TRACE_DEBUG("%s: peer_address=%s bta_handle=0x%x", __PRETTY_FUNCTION__,
                   peer_address.ToString().c_str(), bta_handle);

@@ -1122,6 +1126,7 @@ void BtifAvSource::RegisterAllBtaHandles() {
}

void BtifAvSource::DeregisterAllBtaHandles() {
  std::unique_lock<std::mutex> lock(mutex_);
  for (auto it : peer_id2bta_handle_) {
    tBTA_AV_HNDL bta_handle = it.second;
    BTA_AvDeregister(bta_handle);
@@ -1131,6 +1136,7 @@ void BtifAvSource::DeregisterAllBtaHandles() {

void BtifAvSource::BtaHandleRegistered(uint8_t peer_id,
                                       tBTA_AV_HNDL bta_handle) {
  std::unique_lock<std::mutex> lock(mutex_);
  peer_id2bta_handle_.insert(std::make_pair(peer_id, bta_handle));

  // Set the BTA Handle for the Peer (if exists)
@@ -1210,6 +1216,7 @@ BtifAvPeer* BtifAvSink::FindPeerByPeerId(uint8_t peer_id) {

BtifAvPeer* BtifAvSink::FindOrCreatePeer(const RawAddress& peer_address,
                                         tBTA_AV_HNDL bta_handle) {
  std::unique_lock<std::mutex> lock(mutex_);
  BTIF_TRACE_DEBUG("%s: peer_address=%s bta_handle=0x%x", __PRETTY_FUNCTION__,
                   peer_address.ToString().c_str(), bta_handle);

@@ -1313,6 +1320,7 @@ void BtifAvSink::RegisterAllBtaHandles() {
}

void BtifAvSink::DeregisterAllBtaHandles() {
  std::unique_lock<std::mutex> lock(mutex_);
  for (auto it : peer_id2bta_handle_) {
    tBTA_AV_HNDL bta_handle = it.second;
    BTA_AvDeregister(bta_handle);
@@ -1321,6 +1329,7 @@ void BtifAvSink::DeregisterAllBtaHandles() {
}

void BtifAvSink::BtaHandleRegistered(uint8_t peer_id, tBTA_AV_HNDL bta_handle) {
  std::unique_lock<std::mutex> lock(mutex_);
  peer_id2bta_handle_.insert(std::make_pair(peer_id, bta_handle));

  // Set the BTA Handle for the Peer (if exists)