From e20d9c82e17815e37d153d1c15cda50f65a486d9 Mon Sep 17 00:00:00 2001 From: lee Date: Sat, 23 Aug 2025 15:00:49 +0800 Subject: [PATCH] condition_variable_6.0 --- frameworks/inner/src/bluetooth_gatt_client.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/frameworks/inner/src/bluetooth_gatt_client.cpp b/frameworks/inner/src/bluetooth_gatt_client.cpp index 5999b16e..3fc0d3c7 100644 --- a/frameworks/inner/src/bluetooth_gatt_client.cpp +++ b/frameworks/inner/src/bluetooth_gatt_client.cpp @@ -415,12 +415,12 @@ int GattClient::impl::DiscoverStart() { std::unique_lock lock(discoverInformation_.mutex_); - while (discoverInformation_.isDiscovering_) { - auto ret = discoverInformation_.condition_.wait_for(lock, std::chrono::seconds(WAIT_TIMEOUT)); - if (ret == std::cv_status::timeout) { - HILOGE("timeout"); - return BT_ERR_INTERNAL_ERROR; - } + auto ret = discoverInformation_.condition_.wait_for(lock, std::chrono::seconds(WAIT_TIMEOUT), [this] { + return !discoverInformation_.isDiscovering_; + }); + if (ret == false) { + HILOGE("timeout"); + return BT_ERR_INTERNAL_ERROR; } discoverInformation_.isDiscovering_ = true; } @@ -890,7 +890,7 @@ int GattClient::SetNotifyCharacteristicInner(GattCharacteristic &characteristic, CHECK_AND_RETURN_LOG_RET(IS_BLE_ENABLED(), BT_ERR_INVALID_STATE, "bluetooth is off."); bool isValid = (pimpl != nullptr && pimpl->Init(weak_from_this())); CHECK_AND_RETURN_LOG_RET(isValid, BT_ERR_INTERNAL_ERROR, "pimpl or gatt client proxy is nullptr"); - + std::lock_guard lockConn(pimpl->connStateMutex_); if (pimpl->connectionState_ != static_cast(BTConnectState::CONNECTED)) { HILOGE("Request not supported"); -- Gitee