From 574808daa6053a7248ca4e81c8776cf324bebf44 Mon Sep 17 00:00:00 2001 From: Francis Tsui Date: Mon, 2 Mar 2026 08:47:40 -0800 Subject: [PATCH] Fix use of deprecated MutexLock. PiperOrigin-RevId: 877419825 --- .../dart/nearby_connections_client_state.cc | 22 +++++++++---------- internal/platform/feature_flags.h | 2 +- .../apple/ble_l2cap_server_socket.mm | 10 ++++----- .../implementation/apple/ble_l2cap_socket.mm | 6 ++--- .../implementation/apple/ble_medium.mm | 22 +++++++++---------- .../implementation/apple/ble_server_socket.mm | 10 ++++----- .../implementation/apple/ble_socket.mm | 8 +++---- .../implementation/apple/count_down_latch.cc | 6 ++--- .../platform/implementation/apple/timer.mm | 8 +++---- .../platform/implementation/g3/wifi_hotspot.h | 6 ++--- sharing/fake_nearby_connections_manager.h | 4 ++-- 11 files changed, 52 insertions(+), 52 deletions(-) diff --git a/connections/dart/nearby_connections_client_state.cc b/connections/dart/nearby_connections_client_state.cc index 2aef752b..7049452d 100644 --- a/connections/dart/nearby_connections_client_state.cc +++ b/connections/dart/nearby_connections_client_state.cc @@ -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 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 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 payload_listener_dart) { - absl::MutexLock lock(&mutex_); + absl::MutexLock lock(mutex_); payload_listener_dart_ = std::move(payload_listener_dart); } std::optional NearbyConnectionsClientState::PopNearbyConnectionsApiPort( NearbyConnectionsApi api) { - absl::MutexLock lock(&mutex_); + absl::MutexLock lock(mutex_); std::deque& 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& 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(); diff --git a/internal/platform/feature_flags.h b/internal/platform/feature_flags.h index 8b492396..02a574bc 100644 --- a/internal/platform/feature_flags.h +++ b/internal/platform/feature_flags.h @@ -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; } diff --git a/internal/platform/implementation/apple/ble_l2cap_server_socket.mm b/internal/platform/implementation/apple/ble_l2cap_server_socket.mm index 557fda38..7c8392d0 100644 --- a/internal/platform/implementation/apple/ble_l2cap_server_socket.mm +++ b/internal/platform/implementation/apple/ble_l2cap_server_socket.mm @@ -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 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 BleL2capServerSocket::Accept() { } bool BleL2capServerSocket::AddPendingSocket(std::unique_ptr socket) { - absl::MutexLock lock(&mutex_); + absl::MutexLock lock(mutex_); if (closed_) { return false; } @@ -58,12 +58,12 @@ bool BleL2capServerSocket::AddPendingSocket(std::unique_ptr sock } void BleL2capServerSocket::SetCloseNotifier(absl::AnyInvocable 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(); } diff --git a/internal/platform/implementation/apple/ble_l2cap_socket.mm b/internal/platform/implementation/apple/ble_l2cap_socket.mm index c8176979..e44c6728 100644 --- a/internal/platform/implementation/apple/ble_l2cap_socket.mm +++ b/internal/platform/implementation/apple/ble_l2cap_socket.mm @@ -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}; } diff --git a/internal/platform/implementation/apple/ble_medium.mm b/internal/platform/implementation/apple/ble_medium.mm index ef458c36..afefac0b 100644 --- a/internal/platform/implementation/apple/ble_medium.mm +++ b/internal/platform/implementation/apple/ble_medium.mm @@ -522,11 +522,11 @@ std::unique_ptr BleMedium::OpenL2capServerSocket __block NSError *blockPSMPublishedError = nil; auto l2cap_server_socket = std::make_unique(); 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 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 BleMedium::OpenL2capServerSocket callbackQueue:connection_callback_queue_]; auto socket = std::make_unique(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 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 *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 *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 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 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 BleMedium::PeripheralsMap::Get(api::ble::BlePeripheral::Unique } void BleMedium::PeripheralsMap::Clear() { - absl::MutexLock lock(&mutex_); + absl::MutexLock lock(mutex_); peripherals_.clear(); } diff --git a/internal/platform/implementation/apple/ble_server_socket.mm b/internal/platform/implementation/apple/ble_server_socket.mm index 2bf3d898..d09def72 100644 --- a/internal/platform/implementation/apple/ble_server_socket.mm +++ b/internal/platform/implementation/apple/ble_server_socket.mm @@ -25,12 +25,12 @@ namespace nearby { namespace apple { BleServerSocket::~BleServerSocket() { - absl::MutexLock lock(&mutex_); + absl::MutexLock lock(mutex_); DoClose(); } std::unique_ptr 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 BleServerSocket::Accept() { } bool BleServerSocket::Connect(std::unique_ptr socket) { - absl::MutexLock lock(&mutex_); + absl::MutexLock lock(mutex_); if (closed_) { return false; } @@ -52,12 +52,12 @@ bool BleServerSocket::Connect(std::unique_ptr socket) { } void BleServerSocket::SetCloseNotifier(absl::AnyInvocable 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(); } diff --git a/internal/platform/implementation/apple/ble_socket.mm b/internal/platform/implementation/apple/ble_socket.mm index c1557c0e..e34eb9e1 100644 --- a/internal/platform/implementation/apple/ble_socket.mm +++ b/internal/platform/implementation/apple/ble_socket.mm @@ -185,23 +185,23 @@ BleSocket::BleSocket(id 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 notifier) { - absl::MutexLock lock(&mutex_); + absl::MutexLock lock(mutex_); close_notifier_ = std::move(notifier); } diff --git a/internal/platform/implementation/apple/count_down_latch.cc b/internal/platform/implementation/apple/count_down_latch.cc index 69641502..1ace533f 100644 --- a/internal/platform/implementation/apple/count_down_latch.cc +++ b/internal/platform/implementation/apple/count_down_latch.cc @@ -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 CountDownLatch::Await(absl::Duration timeout) { - absl::MutexLock lock(&mutex_); + absl::MutexLock lock(mutex_); bool condition = mutex_.AwaitWithTimeout( absl::Condition(IsZeroOrNegative, &count_), timeout); return ExceptionOr(condition); } void CountDownLatch::CountDown() { - absl::MutexLock lock(&mutex_); + absl::MutexLock lock(mutex_); count_--; } diff --git a/internal/platform/implementation/apple/timer.mm b/internal/platform/implementation/apple/timer.mm index 8b714520..a02b7ddf 100644 --- a/internal/platform/implementation/apple/timer.mm +++ b/internal/platform/implementation/apple/timer.mm @@ -38,7 +38,7 @@ bool Timer::Create(int delay, int interval, absl::AnyInvocable 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 callback) absl::AnyInvocable 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 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 callback) } bool Timer::Stop() { - absl::MutexLock lock(&mutex_); + absl::MutexLock lock(mutex_); if (timer_ != nullptr) { dispatch_source_cancel(timer_); timer_ = nullptr; diff --git a/internal/platform/implementation/g3/wifi_hotspot.h b/internal/platform/implementation/g3/wifi_hotspot.h index 75f83276..5c02dc5f 100644 --- a/internal/platform/implementation/g3/wifi_hotspot.h +++ b/internal/platform/implementation/g3/wifi_hotspot.h @@ -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; } diff --git a/sharing/fake_nearby_connections_manager.h b/sharing/fake_nearby_connections_manager.h index d62415c0..94b3dddb 100644 --- a/sharing/fake_nearby_connections_manager.h +++ b/sharing/fake_nearby_connections_manager.h @@ -124,7 +124,7 @@ class FakeNearbyConnectionsManager : public NearbyConnectionsManager { std::optional> 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(); }