mirror of
https://github.com/xoseperez/espurna.git
synced 2026-03-03 15:04:17 +01:00
system: do not disarm non-repeating timer
This commit is contained in:
@@ -142,11 +142,13 @@ void loop() {
|
||||
// One-time callbacks, registered some time during runtime
|
||||
// Notice that callback container is LIFO, most recently added
|
||||
// callback is called first. Copy to allow container modifications.
|
||||
decltype(internal::once_callbacks) once_callbacks;
|
||||
once_callbacks.swap(internal::once_callbacks);
|
||||
if (!internal::once_callbacks.empty()) {
|
||||
decltype(internal::once_callbacks) once_callbacks;
|
||||
once_callbacks.swap(internal::once_callbacks);
|
||||
|
||||
for (const auto& callback : once_callbacks) {
|
||||
callback();
|
||||
for (const auto& callback : once_callbacks) {
|
||||
callback();
|
||||
}
|
||||
}
|
||||
|
||||
espurna::time::delay(internal::loop_delay);
|
||||
|
||||
@@ -341,9 +341,9 @@ void SystemTimer::start(Duration duration, Callback callback, bool repeat) {
|
||||
if (!_timer) {
|
||||
_timer.reset(new os_timer_t{});
|
||||
}
|
||||
_armed = _timer.get();
|
||||
|
||||
_callback = std::move(callback);
|
||||
_armed = _timer.get();
|
||||
_repeat = repeat;
|
||||
|
||||
os_timer_setfn(_timer.get(),
|
||||
@@ -372,10 +372,14 @@ void SystemTimer::start(Duration duration, Callback callback, bool repeat) {
|
||||
void SystemTimer::stop() {
|
||||
if (_armed) {
|
||||
os_timer_disarm(_armed);
|
||||
_armed = nullptr;
|
||||
_callback = nullptr;
|
||||
_tick = nullptr;
|
||||
}
|
||||
reset();
|
||||
}
|
||||
|
||||
void SystemTimer::reset() {
|
||||
_armed = nullptr;
|
||||
_callback = Callback();
|
||||
_tick = nullptr;
|
||||
}
|
||||
|
||||
void SystemTimer::callback() {
|
||||
@@ -395,7 +399,7 @@ void SystemTimer::callback() {
|
||||
return;
|
||||
}
|
||||
|
||||
stop();
|
||||
reset();
|
||||
}
|
||||
|
||||
void SystemTimer::schedule_once(Duration duration, Callback callback) {
|
||||
|
||||
@@ -243,6 +243,7 @@ private:
|
||||
// with current implementation we use division by 2 until we reach value less than this one
|
||||
static constexpr Duration DurationMax = Duration(6870947);
|
||||
|
||||
void reset();
|
||||
void start(Duration, Callback, bool repeat);
|
||||
void callback();
|
||||
|
||||
@@ -251,7 +252,8 @@ private:
|
||||
size_t count;
|
||||
};
|
||||
|
||||
Callback _callback { nullptr };
|
||||
Callback _callback;
|
||||
|
||||
os_timer_t* _armed { nullptr };
|
||||
bool _repeat { false };
|
||||
|
||||
|
||||
Reference in New Issue
Block a user