event/TimerList: use IntrusiveTreeSet instead of boost::intrusive::multiset

This commit is contained in:
Max Kellermann 2024-04-02 20:27:12 +02:00 committed by Max Kellermann
parent 5a0bad3b2f
commit c5e607a310
3 changed files with 21 additions and 9 deletions

View File

@ -11,7 +11,7 @@
#ifdef NO_BOOST #ifdef NO_BOOST
#include "util/IntrusiveList.hxx" #include "util/IntrusiveList.hxx"
#else #else
#include <boost/intrusive/set_hook.hpp> #include "util/IntrusiveTreeSet.hxx"
#endif #endif
#include <cassert> #include <cassert>
@ -33,7 +33,7 @@ class FineTimerEvent final :
#ifdef NO_BOOST #ifdef NO_BOOST
AutoUnlinkIntrusiveListHook AutoUnlinkIntrusiveListHook
#else #else
public boost::intrusive::set_base_hook<boost::intrusive::link_mode<boost::intrusive::auto_unlink>> public IntrusiveTreeSetHook<IntrusiveHookMode::AUTO_UNLINK>
#endif #endif
{ {
friend class TimerList; friend class TimerList;

View File

@ -5,6 +5,14 @@
#include "TimerList.hxx" #include "TimerList.hxx"
#include "FineTimerEvent.hxx" #include "FineTimerEvent.hxx"
constexpr Event::TimePoint
TimerList::GetDue::operator()(const FineTimerEvent &timer) const noexcept
{
return timer.due;
}
#ifdef NO_BOOST
constexpr bool constexpr bool
TimerList::Compare::operator()(const FineTimerEvent &a, TimerList::Compare::operator()(const FineTimerEvent &a,
const FineTimerEvent &b) const noexcept const FineTimerEvent &b) const noexcept
@ -12,6 +20,8 @@ TimerList::Compare::operator()(const FineTimerEvent &a,
return a.due < b.due; return a.due < b.due;
} }
#endif
TimerList::TimerList() = default; TimerList::TimerList() = default;
TimerList::~TimerList() noexcept TimerList::~TimerList() noexcept
@ -41,7 +51,7 @@ TimerList::Run(const Event::TimePoint now) noexcept
#ifdef NO_BOOST #ifdef NO_BOOST
t.Cancel(); t.Cancel();
#else #else
timers.erase(i); timers.pop_front();
#endif #endif
t.Run(); t.Run();

View File

@ -10,7 +10,7 @@
#ifdef NO_BOOST #ifdef NO_BOOST
#include "util/IntrusiveSortedList.hxx" #include "util/IntrusiveSortedList.hxx"
#else #else
#include <boost/intrusive/set.hpp> #include "util/IntrusiveTreeSet.hxx"
#endif #endif
class FineTimerEvent; class FineTimerEvent;
@ -19,21 +19,23 @@ class FineTimerEvent;
* A list of #FineTimerEvent instances sorted by due time point. * A list of #FineTimerEvent instances sorted by due time point.
*/ */
class TimerList final { class TimerList final {
struct GetDue {
constexpr Event::TimePoint operator()(const FineTimerEvent &timer) const noexcept;
};
#ifdef NO_BOOST
struct Compare { struct Compare {
constexpr bool operator()(const FineTimerEvent &a, constexpr bool operator()(const FineTimerEvent &a,
const FineTimerEvent &b) const noexcept; const FineTimerEvent &b) const noexcept;
}; };
#ifdef NO_BOOST
/* when building without Boost, then this is just a sorted /* when building without Boost, then this is just a sorted
doubly-linked list - this doesn't scale well, but is good doubly-linked list - this doesn't scale well, but is good
enough for most programs */ enough for most programs */
IntrusiveSortedList<FineTimerEvent, Compare> timers; IntrusiveSortedList<FineTimerEvent, Compare> timers;
#else #else
boost::intrusive::multiset<FineTimerEvent, IntrusiveTreeSet<FineTimerEvent,
boost::intrusive::base_hook<boost::intrusive::set_base_hook<boost::intrusive::link_mode<boost::intrusive::auto_unlink>>>, IntrusiveTreeSetOperators<FineTimerEvent, GetDue>> timers;
boost::intrusive::compare<Compare>,
boost::intrusive::constant_time_size<false>> timers;
#endif #endif
public: public: