From dcbb9fe07ce0c48ffaf6300167eb74276d129136 Mon Sep 17 00:00:00 2001
From: Max Kellermann <max@musicpd.org>
Date: Sun, 22 Dec 2019 11:58:15 +0100
Subject: [PATCH] event/Loop: round timeout up to avoid unnecessary wakeups

---
 NEWS               | 1 +
 src/event/Loop.cxx | 3 ++-
 2 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/NEWS b/NEWS
index 1c514b8dc..169a9610b 100644
--- a/NEWS
+++ b/NEWS
@@ -1,4 +1,5 @@
 ver 0.21.18 (not yet released)
+* reduce unnecessary CPU wakeups
 
 ver 0.21.17 (2019/12/16)
 * protocol
diff --git a/src/event/Loop.cxx b/src/event/Loop.cxx
index 644cacc39..d3de427c9 100644
--- a/src/event/Loop.cxx
+++ b/src/event/Loop.cxx
@@ -137,7 +137,8 @@ static constexpr int
 ExportTimeoutMS(std::chrono::steady_clock::duration timeout)
 {
 	return timeout >= timeout.zero()
-		? int(std::chrono::duration_cast<std::chrono::milliseconds>(timeout).count())
+		/* round up (+1) to avoid unnecessary wakeups */
+		? int(std::chrono::duration_cast<std::chrono::milliseconds>(timeout).count()) + 1
 		: -1;
 }