From f64799622db3036e5936793d9fde308e8acaf67f Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Sun, 18 Oct 2020 19:21:47 +0200 Subject: [PATCH] event/IdleEvent: use class IntrusiveList<> --- src/event/IdleEvent.cxx | 11 ----------- src/event/IdleEvent.hxx | 23 ++++++++--------------- src/event/Loop.cxx | 8 -------- src/event/Loop.hxx | 7 ++----- 4 files changed, 10 insertions(+), 39 deletions(-) diff --git a/src/event/IdleEvent.cxx b/src/event/IdleEvent.cxx index 2910cf92d..8dc5c72ee 100644 --- a/src/event/IdleEvent.cxx +++ b/src/event/IdleEvent.cxx @@ -22,17 +22,6 @@ #include -void -IdleEvent::Cancel() noexcept -{ - assert(loop.IsInside()); - - if (!IsActive()) - return; - - loop.RemoveIdle(*this); -} - void IdleEvent::Schedule() noexcept { diff --git a/src/event/IdleEvent.hxx b/src/event/IdleEvent.hxx index af48275b7..17ca3c7e3 100644 --- a/src/event/IdleEvent.hxx +++ b/src/event/IdleEvent.hxx @@ -21,8 +21,7 @@ #define MPD_SOCKET_IDLE_EVENT_HXX #include "util/BindMethod.hxx" - -#include +#include "util/IntrusiveList.hxx" class EventLoop; @@ -34,10 +33,9 @@ class EventLoop; * thread that runs the #EventLoop, except where explicitly documented * as thread-safe. */ -class IdleEvent - : public boost::intrusive::list_base_hook<> -{ +class IdleEvent final : public AutoUnlinkIntrusiveListHook { friend class EventLoop; + friend class IntrusiveList; EventLoop &loop; @@ -51,15 +49,6 @@ public: IdleEvent(const IdleEvent &) = delete; IdleEvent &operator=(const IdleEvent &) = delete; - ~IdleEvent() noexcept { -#ifndef NDEBUG - /* this check is redundant, it is only here to avoid - the assertion in Cancel() */ - if (IsActive()) -#endif - Cancel(); - } - auto &GetEventLoop() const noexcept { return loop; } @@ -69,7 +58,11 @@ public: } void Schedule() noexcept; - void Cancel() noexcept; + + void Cancel() noexcept { + if (IsActive()) + unlink(); + } private: void Run() noexcept; diff --git a/src/event/Loop.cxx b/src/event/Loop.cxx index e540f796a..a5475c3fb 100644 --- a/src/event/Loop.cxx +++ b/src/event/Loop.cxx @@ -129,14 +129,6 @@ EventLoop::AddIdle(IdleEvent &i) noexcept again = true; } -void -EventLoop::RemoveIdle(IdleEvent &i) noexcept -{ - assert(IsInside()); - - idle.erase(idle.iterator_to(i)); -} - void EventLoop::AddTimer(TimerEvent &t, Event::Duration d) noexcept { diff --git a/src/event/Loop.hxx b/src/event/Loop.hxx index a44cda78c..a1d7be855 100644 --- a/src/event/Loop.hxx +++ b/src/event/Loop.hxx @@ -25,6 +25,7 @@ #include "SocketEvent.hxx" #include "event/Features.h" #include "util/Compiler.h" +#include "util/IntrusiveList.hxx" #ifdef HAVE_THREADED_EVENT_LOOP #include "WakeFD.hxx" @@ -77,10 +78,7 @@ class EventLoop final boost::intrusive::constant_time_size>; TimerSet timers; - using IdleList = - boost::intrusive::list>, - boost::intrusive::constant_time_size>; + using IdleList = IntrusiveList; IdleList idle; #ifdef HAVE_THREADED_EVENT_LOOP @@ -214,7 +212,6 @@ public: bool AbandonFD(int fd) noexcept; void AddIdle(IdleEvent &i) noexcept; - void RemoveIdle(IdleEvent &i) noexcept; void AddTimer(TimerEvent &t, Event::Duration d) noexcept;