From 12091fcfb17b7f0b3b118ee46ce880fbc32f5e66 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Sun, 4 Sep 2016 15:11:01 +0200 Subject: [PATCH] thread/Util: throw exception on error --- src/output/OutputThread.cxx | 13 ++++++++----- src/thread/Util.cxx | 17 +++++------------ src/thread/Util.hxx | 10 ++++------ 3 files changed, 17 insertions(+), 23 deletions(-) diff --git a/src/output/OutputThread.cxx b/src/output/OutputThread.cxx index e98c99244..6950f7a21 100644 --- a/src/output/OutputThread.cxx +++ b/src/output/OutputThread.cxx @@ -40,6 +40,8 @@ #include "Log.hxx" #include "Compiler.h" +#include + #include #include @@ -597,12 +599,13 @@ AudioOutput::Task() { FormatThreadName("output:%s", name); - Error error; - if(!SetThreadRealtime(error)) { - LogError(error); - LogWarning(output_domain, - "OutputThread could not get realtime scheduling, continuing anyway"); + try { + SetThreadRealtime(); + } catch (const std::runtime_error &e) { + LogError(e, + "OutputThread could not get realtime scheduling, continuing anyway"); } + SetThreadTimerSlackUS(100); mutex.lock(); diff --git a/src/thread/Util.cxx b/src/thread/Util.cxx index 1a01c298b..25301f432 100644 --- a/src/thread/Util.cxx +++ b/src/thread/Util.cxx @@ -27,9 +27,8 @@ * OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include "config.h" #include "Util.hxx" -#include "util/Error.hxx" +#include "system/Error.hxx" #ifdef __linux__ #include @@ -77,8 +76,8 @@ SetThreadIdlePriority() #endif }; -bool -SetThreadRealtime(Error& error) +void +SetThreadRealtime() { #ifdef __linux__ struct sched_param sched_param; @@ -89,13 +88,7 @@ SetThreadRealtime(Error& error) policy |= SCHED_RESET_ON_FORK; #endif - if(sched_setscheduler(0, policy, &sched_param)==0) { - return true; - } else { - error.FormatErrno("sched_setscheduler failed"); - return false; - } -#else - return true; // on non-linux systems, we pretend it worked + if (sched_setscheduler(0, policy, &sched_param) < 0) + throw MakeErrno("sched_setscheduler failed"); #endif // __linux__ }; diff --git a/src/thread/Util.hxx b/src/thread/Util.hxx index 0f8062c86..3344a9cb1 100644 --- a/src/thread/Util.hxx +++ b/src/thread/Util.hxx @@ -30,8 +30,6 @@ #ifndef THREAD_UTIL_HXX #define THREAD_UTIL_HXX -class Error; - /** * Lower the current thread's priority to "idle" (very low). */ @@ -40,10 +38,10 @@ SetThreadIdlePriority(); /** * Raise the current thread's priority to "real-time" (very high). - * @param[out] error Receives error information on failure - * @return true on success (always true on non-linux systems) + * + * Throws std::system_error on error. */ -bool -SetThreadRealtime(Error &error); +void +SetThreadRealtime(); #endif