From c52ded2d734dbb0b535fa312c3f6987219cc3f49 Mon Sep 17 00:00:00 2001 From: Bernhard Kirchen Date: Fri, 10 Jan 2025 21:03:47 +0100 Subject: [PATCH] Fix: huawei grid charger: prevent deadlock on mutex the huawei grid charger's loop() uses the private method _setParameter() to update PSU settings. the loop() already holds the mutex, so _setParamater() must not try to lock the mutex again. move the lock guard to the public setParameter() method, which resolves the issue. --- src/gridcharger/huawei/Controller.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/gridcharger/huawei/Controller.cpp b/src/gridcharger/huawei/Controller.cpp index cec5ed8e9..2a4e24178 100644 --- a/src/gridcharger/huawei/Controller.cpp +++ b/src/gridcharger/huawei/Controller.cpp @@ -287,6 +287,8 @@ void Controller::loop() void Controller::setParameter(float val, HardwareInterface::Setting setting) { + std::lock_guard lock(_mutex); + if (_mode == HUAWEI_MODE_AUTO_INT && setting != HardwareInterface::Setting::OfflineVoltage && setting != HardwareInterface::Setting::OfflineCurrent) { return; } @@ -296,7 +298,7 @@ void Controller::setParameter(float val, HardwareInterface::Setting setting) void Controller::_setParameter(float val, HardwareInterface::Setting setting) { - std::lock_guard lock(_mutex); + // NOTE: the mutex is locked by any method calling this private method if (!_upHardwareInterface) { return; }