Commit 620a39af authored by Max Kellermann's avatar Max Kellermann

thread/Slack: use std::chrono::duration

parent 14cee01b
......@@ -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");
......
......@@ -52,7 +52,7 @@ EventThread::Run() noexcept
SetThreadName(realtime ? "rtio" : "io");
if (realtime) {
SetThreadTimerSlackUS(10);
SetThreadTimerSlack(std::chrono::microseconds(10));
try {
SetThreadRealtime();
......
......@@ -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<Mutex> lock(mutex);
......
/*
* 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 <chrono>
#ifdef HAVE_PRCTL
#include <sys/prctl.h>
#endif
......@@ -41,16 +43,11 @@ SetThreadTimerSlackNS(unsigned long slack_ns) noexcept
#endif
}
static inline void
SetThreadTimerSlackUS(unsigned long slack_us) noexcept
{
SetThreadTimerSlackNS(slack_us * 1000ul);
}
static inline void
SetThreadTimerSlackMS(unsigned long slack_ms) noexcept
template<class Rep, class Period>
static inline auto
SetThreadTimerSlack(const std::chrono::duration<Rep,Period> &slack) noexcept
{
SetThreadTimerSlackNS(slack_ms * 1000000ul);
SetThreadTimerSlackNS(std::chrono::duration_cast<std::chrono::nanoseconds>(slack).count());
}
#endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment