Skip to content

Commit

Permalink
Fix: move battery's lock_guard to updateSettings() (#566)
Browse files Browse the repository at this point in the history
the updateSettings method is called from the web server's context and
therefore accesses _upProvider in a different context than the
TaskScheduler. the lock_guard needs to protect _upProvider.
  • Loading branch information
schlimmchen authored Dec 29, 2023
1 parent 6ab706c commit d769cdd
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/Battery.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,14 @@ void BatteryClass::init(Scheduler& scheduler)
_loopTask.setCallback(std::bind(&BatteryClass::loop, this));
_loopTask.setIterations(TASK_FOREVER);
_loopTask.enable();
std::lock_guard<std::mutex> lock(_mutex);

this->updateSettings();
}

void BatteryClass::updateSettings()
{
std::lock_guard<std::mutex> lock(_mutex);

if (_upProvider) {
_upProvider->deinit();
_upProvider = nullptr;
Expand Down

0 comments on commit d769cdd

Please sign in to comment.