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

Commit dda50e78 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 pi-dev

parents 18ddb604 2414e12c
Loading
Loading
Loading
Loading
+9 −0
Original line number Original line Diff line number Diff line
@@ -25,6 +25,7 @@
#include <base/strings/stringprintf.h>
#include <base/strings/stringprintf.h>
#include <string.h>
#include <string.h>
#include <map>
#include <map>
#include <mutex>


#include <hardware/bluetooth.h>
#include <hardware/bluetooth.h>
#include <hardware/bt_av.h>
#include <hardware/bt_av.h>
@@ -466,6 +467,7 @@ class BtifAvSource {
  std::map<RawAddress, BtifAvPeer*> peers_;
  std::map<RawAddress, BtifAvPeer*> peers_;
  RawAddress active_peer_;
  RawAddress active_peer_;
  std::map<uint8_t, tBTA_AV_HNDL> peer_id2bta_handle_;
  std::map<uint8_t, tBTA_AV_HNDL> peer_id2bta_handle_;
  std::mutex mutex_;
};
};


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


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


BtifAvPeer* BtifAvSource::FindOrCreatePeer(const RawAddress& peer_address,
BtifAvPeer* BtifAvSource::FindOrCreatePeer(const RawAddress& peer_address,
                                           tBTA_AV_HNDL bta_handle) {
                                           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__,
  BTIF_TRACE_DEBUG("%s: peer_address=%s bta_handle=0x%x", __PRETTY_FUNCTION__,
                   peer_address.ToString().c_str(), bta_handle);
                   peer_address.ToString().c_str(), bta_handle);


@@ -1048,6 +1052,7 @@ void BtifAvSource::RegisterAllBtaHandles() {
}
}


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


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


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


BtifAvPeer* BtifAvSink::FindOrCreatePeer(const RawAddress& peer_address,
BtifAvPeer* BtifAvSink::FindOrCreatePeer(const RawAddress& peer_address,
                                         tBTA_AV_HNDL bta_handle) {
                                         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__,
  BTIF_TRACE_DEBUG("%s: peer_address=%s bta_handle=0x%x", __PRETTY_FUNCTION__,
                   peer_address.ToString().c_str(), bta_handle);
                   peer_address.ToString().c_str(), bta_handle);


@@ -1234,6 +1241,7 @@ void BtifAvSink::RegisterAllBtaHandles() {
}
}


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


void BtifAvSink::BtaHandleRegistered(uint8_t peer_id, tBTA_AV_HNDL bta_handle) {
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));
  peer_id2bta_handle_.insert(std::make_pair(peer_id, bta_handle));


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