diff --git a/src/Main.cxx b/src/Main.cxx index 660ffa2bc..13bb756c9 100644 --- a/src/Main.cxx +++ b/src/Main.cxx @@ -589,7 +589,7 @@ mpd_main_after_fork(const ConfigData &raw_config, const Config &config) /* the MPD frontend does not care about timer slack; set it to a huge value to allow the kernel to reduce CPU wakeups */ - SetThreadTimerSlackMS(100); + SetThreadTimerSlack(std::chrono::milliseconds(100)); #ifdef ENABLE_SYSTEMD_DAEMON sd_notify(0, "READY=1"); diff --git a/src/event/Thread.cxx b/src/event/Thread.cxx index 211db54aa..dd8310669 100644 --- a/src/event/Thread.cxx +++ b/src/event/Thread.cxx @@ -52,7 +52,7 @@ EventThread::Run() noexcept SetThreadName(realtime ? "rtio" : "io"); if (realtime) { - SetThreadTimerSlackUS(10); + SetThreadTimerSlack(std::chrono::microseconds(10)); try { SetThreadRealtime(); diff --git a/src/output/Thread.cxx b/src/output/Thread.cxx index 03db6aa81..1d373499d 100644 --- a/src/output/Thread.cxx +++ b/src/output/Thread.cxx @@ -410,7 +410,7 @@ AudioOutputControl::Task() noexcept "OutputThread could not get realtime scheduling, continuing anyway"); } - SetThreadTimerSlackUS(100); + SetThreadTimerSlack(std::chrono::microseconds(100)); std::unique_lock lock(mutex); diff --git a/src/thread/Slack.hxx b/src/thread/Slack.hxx index 91e56b763..5909f9c5b 100644 --- a/src/thread/Slack.hxx +++ b/src/thread/Slack.hxx @@ -1,5 +1,5 @@ /* - * Copyright 2003-2018 The Music Player Daemon Project + * Copyright 2003-2019 The Music Player Daemon Project * http://www.musicpd.org * * This program is free software; you can redistribute it and/or modify @@ -22,6 +22,8 @@ #include "config.h" +#include + #ifdef HAVE_PRCTL #include #endif @@ -41,16 +43,11 @@ SetThreadTimerSlackNS(unsigned long slack_ns) noexcept #endif } -static inline void -SetThreadTimerSlackUS(unsigned long slack_us) noexcept +template +static inline auto +SetThreadTimerSlack(const std::chrono::duration &slack) noexcept { - SetThreadTimerSlackNS(slack_us * 1000ul); -} - -static inline void -SetThreadTimerSlackMS(unsigned long slack_ms) noexcept -{ - SetThreadTimerSlackNS(slack_ms * 1000000ul); + SetThreadTimerSlackNS(std::chrono::duration_cast(slack).count()); } #endif