It seems that my e-mail client destroyed the tabs. So I try to send the patch as an attachment. Hope it will work this time.

Am 23.06.15 um 00:50 schrieb Christian Halaszovich:
 From 48af12433916d9f20286ec4d8f9eac069f2f04d0 Mon Sep 17 00:00:00 2001
From: Christian Halaszovich <chalaszov...@gmail.com>
Date: Thu, 18 Jun 2015 10:38:32 +0200
Subject: [PATCH] Emit a warning if the OutputThread fails to get
realtime scheduling

This only applies to linux systems. Here, sched_setscheduler() is
called to get realtime scheduling. With this patch, the return value
of this function is now checked and a warning / error message is
generated if it fails.
---


>From 3f8a8679481f8fc01dd212663d1acb20ed5321a5 Mon Sep 17 00:00:00 2001
From: Christian Halaszovich <chalaszov...@gmail.com>
Date: Thu, 18 Jun 2015 10:38:32 +0200
Subject: [PATCH] Emit a warning if the OutputThread fails to get realtime
 scheduling

This only applies to linux systems. Here, sched_setscheduler() is
called to get realtime scheduling. With this patch, the return value
of this function is now checked and a warning / error message is
generated if it fails.
---
 src/output/OutputThread.cxx |  7 ++++++-
 src/thread/Util.hxx         | 19 +++++++++++++++----
 2 files changed, 21 insertions(+), 5 deletions(-)

diff --git a/src/output/OutputThread.cxx b/src/output/OutputThread.cxx
index badf8f6..44cf0dd 100644
--- a/src/output/OutputThread.cxx
+++ b/src/output/OutputThread.cxx
@@ -593,7 +593,12 @@ AudioOutput::Task()
 {
        FormatThreadName("output:%s", name);
 
-       SetThreadRealtime();
+       Error error;
+       if(!SetThreadRealtime(error)) {
+               LogError(error);
+               LogWarning(output_domain,
+                       "OutputThread could not get realtime scheduling, 
continuing anyway");
+       }
        SetThreadTimerSlackUS(100);
 
        mutex.lock();
diff --git a/src/thread/Util.hxx b/src/thread/Util.hxx
index ff8dbbe..bf9949b 100644
--- a/src/thread/Util.hxx
+++ b/src/thread/Util.hxx
@@ -30,6 +30,8 @@
 #ifndef THREAD_UTIL_HXX
 #define THREAD_UTIL_HXX
 
+#include "util/Error.hxx"
+
 #ifdef __linux__
 #include <sched.h>
 #include <sys/syscall.h>
@@ -81,9 +83,11 @@ 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)
  */
-static inline void
-SetThreadRealtime()
+static inline bool
+SetThreadRealtime(Error& error)
 {
 #ifdef __linux__
        struct sched_param sched_param;
@@ -94,8 +98,15 @@ SetThreadRealtime()
        policy |= SCHED_RESET_ON_FORK;
 #endif
 
-       sched_setscheduler(0, policy, &sched_param);
-#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
+#endif // __linux__
 };
 
 #endif
-- 
2.4.3

_______________________________________________
mpd-devel mailing list
mpd-devel@musicpd.org
http://mailman.blarg.de/listinfo/mpd-devel

Reply via email to