From 977275f0690531626ea186221b011993f3555858 Mon Sep 17 00:00:00 2001 From: Aaron Yu Date: Mon, 3 Apr 2023 17:48:34 -0700 Subject: [PATCH] Add mutex guards for BLE publisher and watcher member variables to improve thread safety PiperOrigin-RevId: 521611021 --- internal/platform/implementation/windows/ble_medium.h | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/internal/platform/implementation/windows/ble_medium.h b/internal/platform/implementation/windows/ble_medium.h index bf932bf5..6604f92f 100644 --- a/internal/platform/implementation/windows/ble_medium.h +++ b/internal/platform/implementation/windows/ble_medium.h @@ -112,12 +112,14 @@ class BleMedium : public api::BleMedium { // WinRT objects ::winrt::Windows::Devices::Bluetooth::Advertisement:: - BluetoothLEAdvertisementPublisher publisher_ = nullptr; + BluetoothLEAdvertisementPublisher publisher_ ABSL_GUARDED_BY(mutex_) = + nullptr; ::winrt::Windows::Devices::Bluetooth::Advertisement:: - BluetoothLEAdvertisementWatcher watcher_ = nullptr; + BluetoothLEAdvertisementWatcher watcher_ ABSL_GUARDED_BY(mutex_) = + nullptr; - bool is_publisher_started_ = false; - bool is_watcher_started_ = false; + bool is_publisher_started_ ABSL_GUARDED_BY(mutex_) = false; + bool is_watcher_started_ ABSL_GUARDED_BY(mutex_) = false; ::winrt::event_token publisher_token_; ::winrt::event_token watcher_token_;