powermeter refactor: make timestamp of last update atomic
the timestamp is potentially updated from a different thread, e.g., MQTT task, than the main loop, which typically reads that timestamp.
This commit is contained in:
parent
d4c07836d9
commit
9eb4f1714c
@ -1,6 +1,7 @@
|
|||||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <atomic>
|
||||||
#include "Configuration.h"
|
#include "Configuration.h"
|
||||||
|
|
||||||
class PowerMeterProvider {
|
class PowerMeterProvider {
|
||||||
@ -41,6 +42,9 @@ protected:
|
|||||||
private:
|
private:
|
||||||
virtual void doMqttPublish() const = 0;
|
virtual void doMqttPublish() const = 0;
|
||||||
|
|
||||||
uint32_t _lastUpdate = 0;
|
// gotUpdate() updates this variable potentially from a different thread
|
||||||
|
// than users that request to read this variable through getLastUpdate().
|
||||||
|
std::atomic<uint32_t> _lastUpdate = 0;
|
||||||
|
|
||||||
mutable uint32_t _lastMqttPublish = 0;
|
mutable uint32_t _lastMqttPublish = 0;
|
||||||
};
|
};
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user