Skip to content

Commit

Permalink
reactor: Generalize timer removal
Browse files Browse the repository at this point in the history
All three reactor::del_timer() implementations use the same logic that
fits naturally to timer_set itself. The original remove() method is kept
as memcached needs one, since it doesn't mess with expired lists.

Signed-off-by: Pavel Emelyanov <xemul@scylladb.com>
  • Loading branch information
xemul committed May 25, 2024
1 parent 351c870 commit 7a21331
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 18 deletions.
13 changes: 13 additions & 0 deletions include/seastar/core/timer-set.hh
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,19 @@ public:
}
}

/**
* Removes timer from the active set or the expired list, if the timer is expired
*/
void remove(Timer& timer, timer_list_t& expired) noexcept
{
if (timer._expired) {
expired.erase(expired.iterator_to(timer));
timer._expired = false;
} else {
remove(timer);
}
}

/**
* Expires active timers.
*
Expand Down
21 changes: 3 additions & 18 deletions src/core/reactor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2463,12 +2463,7 @@ bool reactor::queue_timer(timer<steady_clock_type>* tmr) noexcept {
}

void reactor::del_timer(timer<steady_clock_type>* tmr) noexcept {
if (tmr->_expired) {
_expired_timers.erase(_expired_timers.iterator_to(*tmr));
tmr->_expired = false;
} else {
_timers.remove(*tmr);
}
_timers.remove(*tmr, _expired_timers);
}

void reactor::add_timer(timer<lowres_clock>* tmr) noexcept {
Expand All @@ -2482,12 +2477,7 @@ bool reactor::queue_timer(timer<lowres_clock>* tmr) noexcept {
}

void reactor::del_timer(timer<lowres_clock>* tmr) noexcept {
if (tmr->_expired) {
_expired_lowres_timers.erase(_expired_lowres_timers.iterator_to(*tmr));
tmr->_expired = false;
} else {
_lowres_timers.remove(*tmr);
}
_lowres_timers.remove(*tmr, _expired_lowres_timers);
}

void reactor::add_timer(timer<manual_clock>* tmr) noexcept {
Expand All @@ -2499,12 +2489,7 @@ bool reactor::queue_timer(timer<manual_clock>* tmr) noexcept {
}

void reactor::del_timer(timer<manual_clock>* tmr) noexcept {
if (tmr->_expired) {
_expired_manual_timers.erase(_expired_manual_timers.iterator_to(*tmr));
tmr->_expired = false;
} else {
_manual_timers.remove(*tmr);
}
_manual_timers.remove(*tmr, _expired_manual_timers);
}

void reactor::at_exit(noncopyable_function<future<> ()> func) {
Expand Down

0 comments on commit 7a21331

Please sign in to comment.