Skip to content

Commit

Permalink
Fix: huawei grid charger: prevent deadlock on mutex
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
schlimmchen committed Jan 10, 2025
1 parent 0ad1626 commit c52ded2
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/gridcharger/huawei/Controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,8 @@ void Controller::loop()

void Controller::setParameter(float val, HardwareInterface::Setting setting)
{
std::lock_guard<std::mutex> lock(_mutex);

if (_mode == HUAWEI_MODE_AUTO_INT &&
setting != HardwareInterface::Setting::OfflineVoltage &&
setting != HardwareInterface::Setting::OfflineCurrent) { return; }
Expand All @@ -296,7 +298,7 @@ void Controller::setParameter(float val, HardwareInterface::Setting setting)

void Controller::_setParameter(float val, HardwareInterface::Setting setting)
{
std::lock_guard<std::mutex> lock(_mutex);
// NOTE: the mutex is locked by any method calling this private method

if (!_upHardwareInterface) { return; }

Expand Down

0 comments on commit c52ded2

Please sign in to comment.