diff options
author | Max Kellermann <max@musicpd.org> | 2017-08-29 13:34:08 +0200 |
---|---|---|
committer | Max Kellermann <max@musicpd.org> | 2017-08-29 14:13:09 +0200 |
commit | 71ed3ff992f2118e4d7ffe90cf186a071b129858 (patch) | |
tree | db1cd3b73212dce62aeac3f57df46a0a847b7618 /src/event | |
parent | d4266d0063e9205f7d6a54fc2b4659b838572ad4 (diff) |
event/Loop: move TimerRecord::due to class TimeoutMonitor
Prepare to eliminate the TimerRecord struct.
Diffstat (limited to 'src/event')
-rw-r--r-- | src/event/Loop.cxx | 17 | ||||
-rw-r--r-- | src/event/Loop.hxx | 19 | ||||
-rw-r--r-- | src/event/TimeoutMonitor.hxx | 6 |
3 files changed, 28 insertions, 14 deletions
diff --git a/src/event/Loop.cxx b/src/event/Loop.cxx index 8e2098851..5a9be77e7 100644 --- a/src/event/Loop.cxx +++ b/src/event/Loop.cxx @@ -27,6 +27,18 @@ #include <algorithm> +inline std::chrono::steady_clock::time_point +EventLoop::TimerRecord::GetDue() const noexcept +{ + return timer.due; +} + +inline bool +EventLoop::TimerRecord::operator<(const TimerRecord &other) const noexcept +{ + return timer.due < other.timer.due; +} + EventLoop::EventLoop(ThreadId _thread) :SocketMonitor(*this), thread(_thread) { @@ -93,7 +105,8 @@ EventLoop::AddTimer(TimeoutMonitor &t, std::chrono::steady_clock::duration d) { assert(IsInside()); - timers.insert(TimerRecord(t, now + d)); + t.due = now + d; + timers.insert(TimerRecord(t)); again = true; } @@ -150,7 +163,7 @@ EventLoop::Run() break; } - timeout = i->due - now; + timeout = i->GetDue() - now; if (timeout > timeout.zero()) break; diff --git a/src/event/Loop.hxx b/src/event/Loop.hxx index 895a7f553..2e1b6274c 100644 --- a/src/event/Loop.hxx +++ b/src/event/Loop.hxx @@ -51,21 +51,16 @@ class DeferredMonitor; class EventLoop final : SocketMonitor { struct TimerRecord { - /** - * Projected monotonic_clock_ms() value when this - * timer is due. - */ - const std::chrono::steady_clock::time_point due; - TimeoutMonitor &timer; - constexpr TimerRecord(TimeoutMonitor &_timer, - std::chrono::steady_clock::time_point _due) - :due(_due), timer(_timer) {} + explicit constexpr TimerRecord(TimeoutMonitor &_timer) + :timer(_timer) {} + + gcc_pure + std::chrono::steady_clock::time_point GetDue() const noexcept; - bool operator<(const TimerRecord &other) const { - return due < other.due; - } + gcc_pure + bool operator<(const TimerRecord &other) const noexcept; }; WakeFD wake_fd; diff --git a/src/event/TimeoutMonitor.hxx b/src/event/TimeoutMonitor.hxx index 28000c3f6..f29fbd8af 100644 --- a/src/event/TimeoutMonitor.hxx +++ b/src/event/TimeoutMonitor.hxx @@ -39,6 +39,12 @@ class TimeoutMonitor { EventLoop &loop; + /** + * When is this timer due? This is only valid if #active is + * true. + */ + std::chrono::steady_clock::time_point due; + bool active; public: |