event/IdleEvent: use class IntrusiveList<>
This commit is contained in:
parent
6f0ad2b6c5
commit
f64799622d
@ -22,17 +22,6 @@
|
|||||||
|
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
|
|
||||||
void
|
|
||||||
IdleEvent::Cancel() noexcept
|
|
||||||
{
|
|
||||||
assert(loop.IsInside());
|
|
||||||
|
|
||||||
if (!IsActive())
|
|
||||||
return;
|
|
||||||
|
|
||||||
loop.RemoveIdle(*this);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
void
|
||||||
IdleEvent::Schedule() noexcept
|
IdleEvent::Schedule() noexcept
|
||||||
{
|
{
|
||||||
|
@ -21,8 +21,7 @@
|
|||||||
#define MPD_SOCKET_IDLE_EVENT_HXX
|
#define MPD_SOCKET_IDLE_EVENT_HXX
|
||||||
|
|
||||||
#include "util/BindMethod.hxx"
|
#include "util/BindMethod.hxx"
|
||||||
|
#include "util/IntrusiveList.hxx"
|
||||||
#include <boost/intrusive/list_hook.hpp>
|
|
||||||
|
|
||||||
class EventLoop;
|
class EventLoop;
|
||||||
|
|
||||||
@ -34,10 +33,9 @@ class EventLoop;
|
|||||||
* thread that runs the #EventLoop, except where explicitly documented
|
* thread that runs the #EventLoop, except where explicitly documented
|
||||||
* as thread-safe.
|
* as thread-safe.
|
||||||
*/
|
*/
|
||||||
class IdleEvent
|
class IdleEvent final : public AutoUnlinkIntrusiveListHook {
|
||||||
: public boost::intrusive::list_base_hook<>
|
|
||||||
{
|
|
||||||
friend class EventLoop;
|
friend class EventLoop;
|
||||||
|
friend class IntrusiveList<IdleEvent>;
|
||||||
|
|
||||||
EventLoop &loop;
|
EventLoop &loop;
|
||||||
|
|
||||||
@ -51,15 +49,6 @@ public:
|
|||||||
IdleEvent(const IdleEvent &) = delete;
|
IdleEvent(const IdleEvent &) = delete;
|
||||||
IdleEvent &operator=(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 {
|
auto &GetEventLoop() const noexcept {
|
||||||
return loop;
|
return loop;
|
||||||
}
|
}
|
||||||
@ -69,7 +58,11 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Schedule() noexcept;
|
void Schedule() noexcept;
|
||||||
void Cancel() noexcept;
|
|
||||||
|
void Cancel() noexcept {
|
||||||
|
if (IsActive())
|
||||||
|
unlink();
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void Run() noexcept;
|
void Run() noexcept;
|
||||||
|
@ -129,14 +129,6 @@ EventLoop::AddIdle(IdleEvent &i) noexcept
|
|||||||
again = true;
|
again = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
|
||||||
EventLoop::RemoveIdle(IdleEvent &i) noexcept
|
|
||||||
{
|
|
||||||
assert(IsInside());
|
|
||||||
|
|
||||||
idle.erase(idle.iterator_to(i));
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
void
|
||||||
EventLoop::AddTimer(TimerEvent &t, Event::Duration d) noexcept
|
EventLoop::AddTimer(TimerEvent &t, Event::Duration d) noexcept
|
||||||
{
|
{
|
||||||
|
@ -25,6 +25,7 @@
|
|||||||
#include "SocketEvent.hxx"
|
#include "SocketEvent.hxx"
|
||||||
#include "event/Features.h"
|
#include "event/Features.h"
|
||||||
#include "util/Compiler.h"
|
#include "util/Compiler.h"
|
||||||
|
#include "util/IntrusiveList.hxx"
|
||||||
|
|
||||||
#ifdef HAVE_THREADED_EVENT_LOOP
|
#ifdef HAVE_THREADED_EVENT_LOOP
|
||||||
#include "WakeFD.hxx"
|
#include "WakeFD.hxx"
|
||||||
@ -77,10 +78,7 @@ class EventLoop final
|
|||||||
boost::intrusive::constant_time_size<false>>;
|
boost::intrusive::constant_time_size<false>>;
|
||||||
TimerSet timers;
|
TimerSet timers;
|
||||||
|
|
||||||
using IdleList =
|
using IdleList = IntrusiveList<IdleEvent>;
|
||||||
boost::intrusive::list<IdleEvent,
|
|
||||||
boost::intrusive::base_hook<boost::intrusive::list_base_hook<>>,
|
|
||||||
boost::intrusive::constant_time_size<false>>;
|
|
||||||
IdleList idle;
|
IdleList idle;
|
||||||
|
|
||||||
#ifdef HAVE_THREADED_EVENT_LOOP
|
#ifdef HAVE_THREADED_EVENT_LOOP
|
||||||
@ -214,7 +212,6 @@ public:
|
|||||||
bool AbandonFD(int fd) noexcept;
|
bool AbandonFD(int fd) noexcept;
|
||||||
|
|
||||||
void AddIdle(IdleEvent &i) noexcept;
|
void AddIdle(IdleEvent &i) noexcept;
|
||||||
void RemoveIdle(IdleEvent &i) noexcept;
|
|
||||||
|
|
||||||
void AddTimer(TimerEvent &t, Event::Duration d) noexcept;
|
void AddTimer(TimerEvent &t, Event::Duration d) noexcept;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user