event/TimerEvent: use auto_unlink hook

This commit is contained in:
Max Kellermann 2020-10-08 17:27:15 +02:00
parent 22bea5c97e
commit 263b0ffdbb
4 changed files with 6 additions and 23 deletions

View File

@ -131,14 +131,6 @@ EventLoop::AddTimer(TimerEvent &t, std::chrono::steady_clock::duration d) noexce
again = true; again = true;
} }
void
EventLoop::CancelTimer(TimerEvent &t) noexcept
{
assert(IsInside());
timers.erase(timers.iterator_to(t));
}
inline std::chrono::steady_clock::duration inline std::chrono::steady_clock::duration
EventLoop::HandleTimers() noexcept EventLoop::HandleTimers() noexcept
{ {

View File

@ -64,7 +64,7 @@ class EventLoop final : SocketMonitor
using TimerSet = using TimerSet =
boost::intrusive::multiset<TimerEvent, boost::intrusive::multiset<TimerEvent,
boost::intrusive::base_hook<boost::intrusive::set_base_hook<>>, boost::intrusive::base_hook<boost::intrusive::set_base_hook<boost::intrusive::link_mode<boost::intrusive::auto_unlink>>>,
boost::intrusive::compare<TimerCompare>, boost::intrusive::compare<TimerCompare>,
boost::intrusive::constant_time_size<false>>; boost::intrusive::constant_time_size<false>>;
TimerSet timers; TimerSet timers;
@ -186,7 +186,6 @@ public:
void AddTimer(TimerEvent &t, void AddTimer(TimerEvent &t,
std::chrono::steady_clock::duration d) noexcept; std::chrono::steady_clock::duration d) noexcept;
void CancelTimer(TimerEvent &t) noexcept;
/** /**
* Schedule a call to DeferEvent::RunDeferred(). * Schedule a call to DeferEvent::RunDeferred().

View File

@ -20,13 +20,6 @@
#include "TimerEvent.hxx" #include "TimerEvent.hxx"
#include "Loop.hxx" #include "Loop.hxx"
void
TimerEvent::Cancel() noexcept
{
if (IsActive())
loop.CancelTimer(*this);
}
void void
TimerEvent::Schedule(std::chrono::steady_clock::duration d) noexcept TimerEvent::Schedule(std::chrono::steady_clock::duration d) noexcept
{ {

View File

@ -37,7 +37,7 @@ class EventLoop;
* as thread-safe. * as thread-safe.
*/ */
class TimerEvent final class TimerEvent final
: public boost::intrusive::set_base_hook<> : public boost::intrusive::set_base_hook<boost::intrusive::link_mode<boost::intrusive::auto_unlink>>
{ {
friend class EventLoop; friend class EventLoop;
@ -57,10 +57,6 @@ public:
:loop(_loop), callback(_callback) { :loop(_loop), callback(_callback) {
} }
~TimerEvent() noexcept {
Cancel();
}
auto &GetEventLoop() const noexcept { auto &GetEventLoop() const noexcept {
return loop; return loop;
} }
@ -70,7 +66,10 @@ public:
} }
void Schedule(std::chrono::steady_clock::duration d) noexcept; void Schedule(std::chrono::steady_clock::duration d) noexcept;
void Cancel() noexcept;
void Cancel() noexcept {
unlink();
}
private: private:
void Run() noexcept { void Run() noexcept {