mirror of
https://github.com/kidfromjupiter/nearby.git
synced 2026-09-14 14:46:12 -04:00
Fix use of deprecated MutexLock.
PiperOrigin-RevId: 877419825
This commit is contained in:
committed by
Copybara-Service
parent
e91e5fab0f
commit
574808daa6
@@ -27,54 +27,54 @@
|
||||
namespace nearby::connections::dart {
|
||||
|
||||
NC_INSTANCE NearbyConnectionsClientState::GetOpennedService() const {
|
||||
absl::MutexLock lock(&mutex_);
|
||||
absl::MutexLock lock(mutex_);
|
||||
return opened_instance_;
|
||||
}
|
||||
|
||||
void NearbyConnectionsClientState::SetOpennedService(NC_INSTANCE nc_instance) {
|
||||
absl::MutexLock lock(&mutex_);
|
||||
absl::MutexLock lock(mutex_);
|
||||
opened_instance_ = nc_instance;
|
||||
}
|
||||
|
||||
DiscoveryListenerDart*
|
||||
NearbyConnectionsClientState::GetDiscoveryListenerDart() {
|
||||
absl::MutexLock lock(&mutex_);
|
||||
absl::MutexLock lock(mutex_);
|
||||
return discovery_listener_dart_.get();
|
||||
}
|
||||
|
||||
void NearbyConnectionsClientState::SetDiscoveryListenerDart(
|
||||
std::unique_ptr<DiscoveryListenerDart> discovery_listener_dart) {
|
||||
absl::MutexLock lock(&mutex_);
|
||||
absl::MutexLock lock(mutex_);
|
||||
discovery_listener_dart_ = std::move(discovery_listener_dart);
|
||||
}
|
||||
|
||||
ConnectionListenerDart*
|
||||
NearbyConnectionsClientState::GetConnectionListenerDart() {
|
||||
absl::MutexLock lock(&mutex_);
|
||||
absl::MutexLock lock(mutex_);
|
||||
return connection_listener_dart_.get();
|
||||
}
|
||||
|
||||
void NearbyConnectionsClientState::SetConnectionListenerDart(
|
||||
std::unique_ptr<ConnectionListenerDart> connection_listener_dart) {
|
||||
absl::MutexLock lock(&mutex_);
|
||||
absl::MutexLock lock(mutex_);
|
||||
connection_listener_dart_ = std::move(connection_listener_dart);
|
||||
}
|
||||
|
||||
PayloadListenerDart* NearbyConnectionsClientState::GetPayloadListenerDart() {
|
||||
absl::MutexLock lock(&mutex_);
|
||||
absl::MutexLock lock(mutex_);
|
||||
return payload_listener_dart_.get();
|
||||
}
|
||||
|
||||
void NearbyConnectionsClientState::SetPayloadListenerDart(
|
||||
std::unique_ptr<PayloadListenerDart> payload_listener_dart) {
|
||||
absl::MutexLock lock(&mutex_);
|
||||
absl::MutexLock lock(mutex_);
|
||||
payload_listener_dart_ = std::move(payload_listener_dart);
|
||||
}
|
||||
|
||||
std::optional<Dart_Port>
|
||||
NearbyConnectionsClientState::PopNearbyConnectionsApiPort(
|
||||
NearbyConnectionsApi api) {
|
||||
absl::MutexLock lock(&mutex_);
|
||||
absl::MutexLock lock(mutex_);
|
||||
std::deque<Dart_Port>& port_list = nearby_connections_api_ports_[api];
|
||||
if (port_list.empty()) {
|
||||
return std::nullopt;
|
||||
@@ -87,13 +87,13 @@ NearbyConnectionsClientState::PopNearbyConnectionsApiPort(
|
||||
|
||||
void NearbyConnectionsClientState::PushNearbyConnectionsApiPort(
|
||||
NearbyConnectionsApi api, Dart_Port dart_port) {
|
||||
absl::MutexLock lock(&mutex_);
|
||||
absl::MutexLock lock(mutex_);
|
||||
std::deque<Dart_Port>& port_list = nearby_connections_api_ports_[api];
|
||||
port_list.push_back(dart_port);
|
||||
}
|
||||
|
||||
void NearbyConnectionsClientState::reset() {
|
||||
absl::MutexLock lock(&mutex_);
|
||||
absl::MutexLock lock(mutex_);
|
||||
opened_instance_ = nullptr;
|
||||
nearby_connections_api_ports_.clear();
|
||||
discovery_listener_dart_.reset();
|
||||
|
||||
@@ -137,7 +137,7 @@ class FeatureFlags {
|
||||
|
||||
// SetFlags for feature controlling
|
||||
void SetFlags(const Flags& flags) ABSL_LOCKS_EXCLUDED(mutex_) {
|
||||
absl::MutexLock lock(&mutex_);
|
||||
absl::MutexLock lock(mutex_);
|
||||
flags_ = flags;
|
||||
}
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@ namespace nearby {
|
||||
namespace apple {
|
||||
|
||||
BleL2capServerSocket::~BleL2capServerSocket() {
|
||||
absl::MutexLock lock(&mutex_);
|
||||
absl::MutexLock lock(mutex_);
|
||||
DoClose();
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@ void BleL2capServerSocket::SetPSM(int psm) { psm_ = psm; }
|
||||
|
||||
// TODO: b/399815436 - Refactor Accept() and AddPendingSocket() for better readability.
|
||||
std::unique_ptr<api::ble::BleL2capSocket> BleL2capServerSocket::Accept() {
|
||||
absl::MutexLock lock(&mutex_);
|
||||
absl::MutexLock lock(mutex_);
|
||||
while (!closed_ && pending_sockets_.empty()) {
|
||||
cond_.Wait(&mutex_);
|
||||
}
|
||||
@@ -48,7 +48,7 @@ std::unique_ptr<api::ble::BleL2capSocket> BleL2capServerSocket::Accept() {
|
||||
}
|
||||
|
||||
bool BleL2capServerSocket::AddPendingSocket(std::unique_ptr<BleL2capSocket> socket) {
|
||||
absl::MutexLock lock(&mutex_);
|
||||
absl::MutexLock lock(mutex_);
|
||||
if (closed_) {
|
||||
return false;
|
||||
}
|
||||
@@ -58,12 +58,12 @@ bool BleL2capServerSocket::AddPendingSocket(std::unique_ptr<BleL2capSocket> sock
|
||||
}
|
||||
|
||||
void BleL2capServerSocket::SetCloseNotifier(absl::AnyInvocable<void()> notifier) {
|
||||
absl::MutexLock lock(&mutex_);
|
||||
absl::MutexLock lock(mutex_);
|
||||
close_notifier_ = std::move(notifier);
|
||||
}
|
||||
|
||||
Exception BleL2capServerSocket::Close() {
|
||||
absl::MutexLock lock(&mutex_);
|
||||
absl::MutexLock lock(mutex_);
|
||||
return DoClose();
|
||||
}
|
||||
|
||||
|
||||
@@ -172,17 +172,17 @@ BleL2capSocket::BleL2capSocket(GNCBLEL2CAPConnection *connection,
|
||||
peripheral_id_(peripheral_id) {}
|
||||
|
||||
BleL2capSocket::~BleL2capSocket() {
|
||||
absl::MutexLock lock(&mutex_);
|
||||
absl::MutexLock lock(mutex_);
|
||||
DoClose();
|
||||
}
|
||||
|
||||
bool BleL2capSocket::IsClosed() const {
|
||||
absl::MutexLock lock(&mutex_);
|
||||
absl::MutexLock lock(mutex_);
|
||||
return closed_;
|
||||
}
|
||||
|
||||
Exception BleL2capSocket::Close() {
|
||||
absl::MutexLock lock(&mutex_);
|
||||
absl::MutexLock lock(mutex_);
|
||||
DoClose();
|
||||
return {Exception::kSuccess};
|
||||
}
|
||||
|
||||
@@ -522,11 +522,11 @@ std::unique_ptr<api::ble::BleL2capServerSocket> BleMedium::OpenL2capServerSocket
|
||||
__block NSError *blockPSMPublishedError = nil;
|
||||
auto l2cap_server_socket = std::make_unique<BleL2capServerSocket>();
|
||||
l2cap_server_socket->SetCloseNotifier([this]() {
|
||||
absl::MutexLock lock(&l2cap_server_socket_mutex_);
|
||||
absl::MutexLock lock(l2cap_server_socket_mutex_);
|
||||
l2cap_server_socket_ptr_ = nullptr;
|
||||
});
|
||||
{
|
||||
absl::MutexLock lock(&l2cap_server_socket_mutex_);
|
||||
absl::MutexLock lock(l2cap_server_socket_mutex_);
|
||||
l2cap_server_socket_ptr_ = l2cap_server_socket.get();
|
||||
}
|
||||
std::string service_id_str = service_id;
|
||||
@@ -538,7 +538,7 @@ std::unique_ptr<api::ble::BleL2capServerSocket> BleMedium::OpenL2capServerSocket
|
||||
return;
|
||||
}
|
||||
{
|
||||
absl::MutexLock lock(&l2cap_server_socket_mutex_);
|
||||
absl::MutexLock lock(l2cap_server_socket_mutex_);
|
||||
if (l2cap_server_socket_ptr_) {
|
||||
l2cap_server_socket_ptr_->SetPSM(PSM);
|
||||
}
|
||||
@@ -558,7 +558,7 @@ std::unique_ptr<api::ble::BleL2capServerSocket> BleMedium::OpenL2capServerSocket
|
||||
callbackQueue:connection_callback_queue_];
|
||||
auto socket = std::make_unique<BleL2capSocket>(connection);
|
||||
{
|
||||
absl::MutexLock lock(&l2cap_server_socket_mutex_);
|
||||
absl::MutexLock lock(l2cap_server_socket_mutex_);
|
||||
if (l2cap_server_socket_ptr_) {
|
||||
l2cap_server_socket_ptr_->AddPendingSocket(std::move(socket));
|
||||
}
|
||||
@@ -730,20 +730,20 @@ std::optional<api::ble::BlePeripheral::UniqueId> BleMedium::RetrieveBlePeriphera
|
||||
}
|
||||
|
||||
void BleMedium::ClearAdvertisementPacketsMap() {
|
||||
absl::MutexLock lock(&advertisement_packets_mutex_);
|
||||
absl::MutexLock lock(advertisement_packets_mutex_);
|
||||
advertisement_packets_map_.clear();
|
||||
last_timestamp_to_clean_expired_advertisement_packets_ = [NSDate date];
|
||||
}
|
||||
|
||||
NSDate *BleMedium::GetLastTimestampToCleanExpiredAdvertisementPackets() {
|
||||
absl::MutexLock lock(&advertisement_packets_mutex_);
|
||||
absl::MutexLock lock(advertisement_packets_mutex_);
|
||||
return last_timestamp_to_clean_expired_advertisement_packets_;
|
||||
}
|
||||
|
||||
bool BleMedium::ShouldReportAdvertisement(NSDate *now,
|
||||
api::ble::BlePeripheral::UniqueId peripheral_id,
|
||||
NSDictionary<CBUUID *, NSData *> *service_data) {
|
||||
absl::MutexLock lock(&advertisement_packets_mutex_);
|
||||
absl::MutexLock lock(advertisement_packets_mutex_);
|
||||
if (service_data == nil || service_data.count == 0) {
|
||||
return false;
|
||||
}
|
||||
@@ -775,19 +775,19 @@ bool BleMedium::ShouldReportAdvertisement(NSDate *now,
|
||||
|
||||
void BleMedium::AddAdvertisementPacketInfo(api::ble::BlePeripheral::UniqueId peripheral_id,
|
||||
NSDictionary<CBUUID *, NSData *> *service_data) {
|
||||
absl::MutexLock lock(&advertisement_packets_mutex_);
|
||||
absl::MutexLock lock(advertisement_packets_mutex_);
|
||||
advertisement_packets_map_[peripheral_id] = {[NSDate date], service_data};
|
||||
}
|
||||
|
||||
api::ble::BlePeripheral::UniqueId BleMedium::PeripheralsMap::Add(id<GNCPeripheral> peripheral) {
|
||||
absl::MutexLock lock(&mutex_);
|
||||
absl::MutexLock lock(mutex_);
|
||||
api::ble::BlePeripheral::UniqueId peripheral_id = peripheral.identifier.hash;
|
||||
peripherals_.insert({peripheral_id, peripheral});
|
||||
return peripheral_id;
|
||||
}
|
||||
|
||||
id<GNCPeripheral> BleMedium::PeripheralsMap::Get(api::ble::BlePeripheral::UniqueId peripheral_id) {
|
||||
absl::MutexLock lock(&mutex_);
|
||||
absl::MutexLock lock(mutex_);
|
||||
auto peripheral_it = peripherals_.find(peripheral_id);
|
||||
if (peripheral_it == peripherals_.end()) {
|
||||
return nil;
|
||||
@@ -796,7 +796,7 @@ id<GNCPeripheral> BleMedium::PeripheralsMap::Get(api::ble::BlePeripheral::Unique
|
||||
}
|
||||
|
||||
void BleMedium::PeripheralsMap::Clear() {
|
||||
absl::MutexLock lock(&mutex_);
|
||||
absl::MutexLock lock(mutex_);
|
||||
peripherals_.clear();
|
||||
}
|
||||
|
||||
|
||||
@@ -25,12 +25,12 @@ namespace nearby {
|
||||
namespace apple {
|
||||
|
||||
BleServerSocket::~BleServerSocket() {
|
||||
absl::MutexLock lock(&mutex_);
|
||||
absl::MutexLock lock(mutex_);
|
||||
DoClose();
|
||||
}
|
||||
|
||||
std::unique_ptr<api::ble::BleSocket> BleServerSocket::Accept() {
|
||||
absl::MutexLock lock(&mutex_);
|
||||
absl::MutexLock lock(mutex_);
|
||||
while (!closed_ && pending_sockets_.empty()) {
|
||||
cond_.Wait(&mutex_);
|
||||
}
|
||||
@@ -42,7 +42,7 @@ std::unique_ptr<api::ble::BleSocket> BleServerSocket::Accept() {
|
||||
}
|
||||
|
||||
bool BleServerSocket::Connect(std::unique_ptr<BleSocket> socket) {
|
||||
absl::MutexLock lock(&mutex_);
|
||||
absl::MutexLock lock(mutex_);
|
||||
if (closed_) {
|
||||
return false;
|
||||
}
|
||||
@@ -52,12 +52,12 @@ bool BleServerSocket::Connect(std::unique_ptr<BleSocket> socket) {
|
||||
}
|
||||
|
||||
void BleServerSocket::SetCloseNotifier(absl::AnyInvocable<void()> notifier) {
|
||||
absl::MutexLock lock(&mutex_);
|
||||
absl::MutexLock lock(mutex_);
|
||||
close_notifier_ = std::move(notifier);
|
||||
}
|
||||
|
||||
Exception BleServerSocket::Close() {
|
||||
absl::MutexLock lock(&mutex_);
|
||||
absl::MutexLock lock(mutex_);
|
||||
return DoClose();
|
||||
}
|
||||
|
||||
|
||||
@@ -185,23 +185,23 @@ BleSocket::BleSocket(id<GNCMConnection> connection, api::ble::BlePeripheral::Uni
|
||||
peripheral_id_(peripheral_id) {}
|
||||
|
||||
BleSocket::~BleSocket() {
|
||||
absl::MutexLock lock(&mutex_);
|
||||
absl::MutexLock lock(mutex_);
|
||||
DoClose();
|
||||
}
|
||||
|
||||
bool BleSocket::IsClosed() const {
|
||||
absl::MutexLock lock(&mutex_);
|
||||
absl::MutexLock lock(mutex_);
|
||||
return closed_;
|
||||
}
|
||||
|
||||
Exception BleSocket::Close() {
|
||||
absl::MutexLock lock(&mutex_);
|
||||
absl::MutexLock lock(mutex_);
|
||||
DoClose();
|
||||
return {Exception::kSuccess};
|
||||
}
|
||||
|
||||
void BleSocket::SetCloseNotifier(absl::AnyInvocable<void()> notifier) {
|
||||
absl::MutexLock lock(&mutex_);
|
||||
absl::MutexLock lock(mutex_);
|
||||
close_notifier_ = std::move(notifier);
|
||||
}
|
||||
|
||||
|
||||
@@ -21,19 +21,19 @@ namespace nearby {
|
||||
namespace apple {
|
||||
|
||||
Exception CountDownLatch::Await() {
|
||||
absl::MutexLock lock(&mutex_, absl::Condition(IsZeroOrNegative, &count_));
|
||||
absl::MutexLock lock(mutex_, absl::Condition(IsZeroOrNegative, &count_));
|
||||
return {Exception::kSuccess};
|
||||
}
|
||||
|
||||
ExceptionOr<bool> CountDownLatch::Await(absl::Duration timeout) {
|
||||
absl::MutexLock lock(&mutex_);
|
||||
absl::MutexLock lock(mutex_);
|
||||
bool condition = mutex_.AwaitWithTimeout(
|
||||
absl::Condition(IsZeroOrNegative, &count_), timeout);
|
||||
return ExceptionOr<bool>(condition);
|
||||
}
|
||||
|
||||
void CountDownLatch::CountDown() {
|
||||
absl::MutexLock lock(&mutex_);
|
||||
absl::MutexLock lock(mutex_);
|
||||
count_--;
|
||||
}
|
||||
|
||||
|
||||
@@ -38,7 +38,7 @@ bool Timer::Create(int delay, int interval, absl::AnyInvocable<void()> callback)
|
||||
return false;
|
||||
}
|
||||
|
||||
absl::MutexLock lock(&mutex_);
|
||||
absl::MutexLock lock(mutex_);
|
||||
if (timer_ != nullptr) {
|
||||
GNCLoggerError(@"Timer has already started.");
|
||||
return false;
|
||||
@@ -59,7 +59,7 @@ bool Timer::Create(int delay, int interval, absl::AnyInvocable<void()> callback)
|
||||
absl::AnyInvocable<void()> callback_to_run = nullptr;
|
||||
bool is_one_shot = (intervalInNanoseconds == DISPATCH_TIME_FOREVER);
|
||||
{
|
||||
absl::MutexLock lock(&mutex_);
|
||||
absl::MutexLock lock(mutex_);
|
||||
// If Stop() was called concurrently, the callback will be null.
|
||||
if (!callback_ || callback_running_) {
|
||||
return;
|
||||
@@ -76,7 +76,7 @@ bool Timer::Create(int delay, int interval, absl::AnyInvocable<void()> callback)
|
||||
callback_to_run();
|
||||
}
|
||||
{
|
||||
absl::MutexLock lock(&mutex_);
|
||||
absl::MutexLock lock(mutex_);
|
||||
if (!is_one_shot && callback_to_run) {
|
||||
// For periodic timers, move the callback back for the next run.
|
||||
callback_ = std::move(callback_to_run);
|
||||
@@ -93,7 +93,7 @@ bool Timer::Create(int delay, int interval, absl::AnyInvocable<void()> callback)
|
||||
}
|
||||
|
||||
bool Timer::Stop() {
|
||||
absl::MutexLock lock(&mutex_);
|
||||
absl::MutexLock lock(mutex_);
|
||||
if (timer_ != nullptr) {
|
||||
dispatch_source_cancel(timer_);
|
||||
timer_ = nullptr;
|
||||
|
||||
@@ -66,17 +66,17 @@ class WifiHotspotServerSocket : public api::WifiHotspotServerSocket {
|
||||
static std::string GetName(absl::string_view ip_address, int port);
|
||||
|
||||
void SetIPAddress(const std::string& ip_address) ABSL_LOCKS_EXCLUDED(mutex_) {
|
||||
absl::MutexLock lock(&mutex_);
|
||||
absl::MutexLock lock(mutex_);
|
||||
ip_address_ = ip_address;
|
||||
}
|
||||
|
||||
int GetPort() const override ABSL_LOCKS_EXCLUDED(mutex_) {
|
||||
absl::MutexLock lock(&mutex_);
|
||||
absl::MutexLock lock(mutex_);
|
||||
return port_;
|
||||
}
|
||||
|
||||
void SetPort(int port) ABSL_LOCKS_EXCLUDED(mutex_) {
|
||||
absl::MutexLock lock(&mutex_);
|
||||
absl::MutexLock lock(mutex_);
|
||||
port_ = port;
|
||||
}
|
||||
|
||||
|
||||
@@ -124,7 +124,7 @@ class FakeNearbyConnectionsManager : public NearbyConnectionsManager {
|
||||
|
||||
std::optional<std::vector<uint8_t>> connection_endpoint_info(
|
||||
absl::string_view endpoint_id) {
|
||||
absl::MutexLock lock(&endpoints_mutex_);
|
||||
absl::MutexLock lock(endpoints_mutex_);
|
||||
auto it = connection_endpoint_infos_.find(std::string(endpoint_id));
|
||||
if (it == connection_endpoint_infos_.end()) return std::nullopt;
|
||||
|
||||
@@ -132,7 +132,7 @@ class FakeNearbyConnectionsManager : public NearbyConnectionsManager {
|
||||
}
|
||||
|
||||
bool has_incoming_payloads() {
|
||||
absl::MutexLock lock(&incoming_payloads_mutex_);
|
||||
absl::MutexLock lock(incoming_payloads_mutex_);
|
||||
return !incoming_payloads_.empty();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user