Fix: move battery's lock_guard to updateSettings() (#566)

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.
This commit is contained in:
Bernhard Kirchen 2023-12-29 10:48:25 +01:00 committed by GitHub
parent 6ab706c87d
commit d769cdd30a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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;