From 93edcf2a07920e263eb9bc80115627b0d0818516 Mon Sep 17 00:00:00 2001 From: Anduin1109 Date: Fri, 5 Sep 2025 16:33:22 +0800 Subject: [PATCH 1/2] add mutex for setPortRole Signed-off-by: Anduin1109 --- services/native/src/usb_port_manager.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/services/native/src/usb_port_manager.cpp b/services/native/src/usb_port_manager.cpp index 48d65b98..8c8b931f 100644 --- a/services/native/src/usb_port_manager.cpp +++ b/services/native/src/usb_port_manager.cpp @@ -177,6 +177,8 @@ bool UsbPortManager::IsReverseCharge() int32_t UsbPortManager::SetPortRole(int32_t portId, int32_t powerRole, int32_t dataRole) { + USB_HILOGI(MODULE_USB_SERVICE, "UsbPortManager SetPortRole enter"); + std::lock_guard guard(mutex_); #ifdef USB_MANAGER_V2_0 if (usbPortInterface_ == nullptr) { USB_HILOGE(MODULE_USB_SERVICE, "UsbPortManager::SetPortRole usbPortInterface_ is nullptr"); -- Gitee From 99b2bc6daeee46684ce16ee34d6240a4b9a72b09 Mon Sep 17 00:00:00 2001 From: Anduin1109 Date: Fri, 5 Sep 2025 16:51:24 +0800 Subject: [PATCH 2/2] add mutex for setPortRole Signed-off-by: Anduin1109 --- services/native/include/usb_port_manager.h | 1 + services/native/src/usb_port_manager.cpp | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/services/native/include/usb_port_manager.h b/services/native/include/usb_port_manager.h index 3354467e..dec0b343 100644 --- a/services/native/include/usb_port_manager.h +++ b/services/native/include/usb_port_manager.h @@ -71,6 +71,7 @@ private: int32_t currentMode, int32_t currentDataRole, int32_t currentPowerRole); void AddSupportedMode(); std::mutex mutex_; + std::mutex setPortRoleMutex_; std::map portMap_; std::map supportedModeMap_; sptr usbd_ = nullptr; diff --git a/services/native/src/usb_port_manager.cpp b/services/native/src/usb_port_manager.cpp index 8c8b931f..8e4d3304 100644 --- a/services/native/src/usb_port_manager.cpp +++ b/services/native/src/usb_port_manager.cpp @@ -178,7 +178,7 @@ bool UsbPortManager::IsReverseCharge() int32_t UsbPortManager::SetPortRole(int32_t portId, int32_t powerRole, int32_t dataRole) { USB_HILOGI(MODULE_USB_SERVICE, "UsbPortManager SetPortRole enter"); - std::lock_guard guard(mutex_); + std::lock_guard guard(setPortRoleMutex_); #ifdef USB_MANAGER_V2_0 if (usbPortInterface_ == nullptr) { USB_HILOGE(MODULE_USB_SERVICE, "UsbPortManager::SetPortRole usbPortInterface_ is nullptr"); -- Gitee