Commit d83604d5 authored by jimmyt857's avatar jimmyt857 Committed by Alex Hultman

Fix timer bug and switch to insertion sort (#555)

parent 4f2f6855
......@@ -72,14 +72,16 @@ struct Timer {
}
void start(void (*cb)(Timer *), int timeout, int repeat) {
loop->timepoint = std::chrono::system_clock::now();
std::chrono::system_clock::time_point timepoint = loop->timepoint + std::chrono::milliseconds(timeout);
loop->timers.push_back({cb, this, timepoint, repeat});
std::sort(loop->timers.begin(), loop->timers.end(), [](const Timepoint &a, const Timepoint &b) {
return a.timepoint < b.timepoint;
});
// insertion sort
Timepoint t = {cb, this, timepoint, repeat};
loop->timers.insert(
std::upper_bound(loop->timers.begin(), loop->timers.end(), t, [](const Timepoint &a, const Timepoint &b) {
return a.timepoint < b.timepoint;
}),
t
);
loop->delay = -1;
if (loop->timers.size()) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment