Skip to content

Commit

Permalink
dont attempt to reschedule timers that are deleted
Browse files Browse the repository at this point in the history
  • Loading branch information
braindigitalis committed Feb 19, 2024
1 parent 4b017b6 commit 37cb527
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
4 changes: 3 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@
"semaphore": "cpp",
"stop_token": "cpp",
"charconv": "cpp",
"any": "cpp"
"any": "cpp",
"ranges": "cpp",
"span": "cpp"
}
}
15 changes: 13 additions & 2 deletions src/dpp/cluster/timer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,21 @@ void cluster::tick_timers() {
}
}
for (auto & t : scheduled) {
timer handle = t->handle;
/* Call handler */
t->on_tick(t->handle);
/* Reschedule for next tick */
timer_reschedule(t);
/* Reschedule if it wasn't deleted.
* Note: We wrap the .contains() check in a lambda as it needs locking
* for thread safety, but timer_rescheudle also locks the container, so this
* is the cleanest way to do it.
*/
bool not_deleted = ([handle, this]() -> bool {
std::lock_guard<std::mutex> l(timer_guard);
return timer_list.contains(handle);
}());
if (not_deleted) {
timer_reschedule(t);
}
}
}

Expand Down

0 comments on commit 37cb527

Please sign in to comment.