From 79ef679768b264679240ecbdcebb46e45f4dd319 Mon Sep 17 00:00:00 2001 From: Vivien Nicolas Date: Tue, 7 Mar 2023 13:40:00 +0100 Subject: [PATCH] [darwin] Race when BleConnection stop is called --- .../Darwin/BleConnectionDelegateImpl.mm | 98 ++++++++++++------- 1 file changed, 62 insertions(+), 36 deletions(-) diff --git a/src/platform/Darwin/BleConnectionDelegateImpl.mm b/src/platform/Darwin/BleConnectionDelegateImpl.mm index 004a33bfb0e963..3468fee7e9d598 100644 --- a/src/platform/Darwin/BleConnectionDelegateImpl.mm +++ b/src/platform/Darwin/BleConnectionDelegateImpl.mm @@ -32,6 +32,7 @@ #include #include #include +#include #include #import "UUIDHelper.h" @@ -40,10 +41,10 @@ constexpr uint64_t kScanningWithDiscriminatorTimeoutInSeconds = 60; constexpr uint64_t kScanningWithoutDiscriminatorTimeoutInSeconds = 120; +constexpr const char * kBleWorkQueueName = "org.csa-iot.matter.framework.ble.workqueue"; @interface BleConnection : NSObject -@property (strong, nonatomic) dispatch_queue_t workQueue; @property (strong, nonatomic) dispatch_queue_t chipWorkQueue; @property (strong, nonatomic) CBCentralManager * centralManager; @property (strong, nonatomic) CBPeripheral * peripheral; @@ -58,7 +59,8 @@ @interface BleConnection : NSObject CloseAllBleConnections(); + dispatch_sync(_chipWorkQueue, ^{ + _mBleLayer->CloseAllBleConnections(); + }); + _peripheral = nil; }