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

View File

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

View File

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