event/IdleMonitor: refactor to IdleEvent

Instead of using this as a base class implementing a virtual method,
the new class IdleEvent can be used as a variable, decoupling
IdleMonitor's internal state from the derived class.

This is similar to commit 30a5dd267b
which refactored TimeoutMonitor to TimerEvent.
This commit is contained in:
Max Kellermann
2020-10-14 13:34:15 +02:00
parent 9f57732af2
commit 1686f4e857
12 changed files with 87 additions and 70 deletions

View File

@@ -24,7 +24,7 @@
#include "PollGroup.hxx"
#include "WakeFD.hxx"
#include "SocketMonitor.hxx"
#include "IdleMonitor.hxx"
#include "IdleEvent.hxx"
#include "DeferEvent.hxx"
#include "thread/Id.hxx"
#include "thread/Mutex.hxx"
@@ -52,7 +52,7 @@ class TimerEvent;
* thread that runs it, except where explicitly documented as
* thread-safe.
*
* @see SocketMonitor, MultiSocketMonitor, TimerEvent, IdleMonitor
* @see SocketMonitor, MultiSocketMonitor, TimerEvent, IdleEvent
*/
class EventLoop final : SocketMonitor
{
@@ -71,10 +71,10 @@ class EventLoop final : SocketMonitor
TimerSet timers;
using IdleList =
boost::intrusive::list<IdleMonitor,
boost::intrusive::member_hook<IdleMonitor,
IdleMonitor::ListHook,
&IdleMonitor::list_hook>,
boost::intrusive::list<IdleEvent,
boost::intrusive::member_hook<IdleEvent,
IdleEvent::ListHook,
&IdleEvent::list_hook>,
boost::intrusive::constant_time_size<false>>;
IdleList idle;
@@ -194,8 +194,8 @@ public:
bool RemoveFD(int fd) noexcept;
void AddIdle(IdleMonitor &i) noexcept;
void RemoveIdle(IdleMonitor &i) noexcept;
void AddIdle(IdleEvent &i) noexcept;
void RemoveIdle(IdleEvent &i) noexcept;
void AddTimer(TimerEvent &t, Event::Duration d) noexcept;