diff options
author | Max Kellermann <max@musicpd.org> | 2018-02-16 22:38:55 +0100 |
---|---|---|
committer | Max Kellermann <max@musicpd.org> | 2018-02-16 22:38:55 +0100 |
commit | d29d186d623441b014e691310face12cbef762a8 (patch) | |
tree | 0a1bf0ad023dd76fa12b7bcce203eab240cfd1f3 /src/event | |
parent | 61f2ce67ddcd3d1e1f99395dee54c813b5ea9519 (diff) |
output/alsa: use a new I/O thread with real-time scheduling
The normal I/O event thread can have a large latency, e.g. when
libgnutls loads all TLS CA certificates for a https connect. This
makes it unreliable for the ALSA I/O notifications, and causes ring
buffer xruns. To avoid interfering with high latency events such as
CURL's, we move the ALSA I/O events to a separate I/O thread which
also obtains real-time scheduling (if possible).
Closes #221
Diffstat (limited to 'src/event')
-rw-r--r-- | src/event/Thread.cxx | 13 | ||||
-rw-r--r-- | src/event/Thread.hxx | 7 |
2 files changed, 17 insertions, 3 deletions
diff --git a/src/event/Thread.cxx b/src/event/Thread.cxx index f7c2b9a0b..d67585788 100644 --- a/src/event/Thread.cxx +++ b/src/event/Thread.cxx @@ -20,6 +20,8 @@ #include "config.h" #include "Thread.hxx" #include "thread/Name.hxx" +#include "thread/Util.hxx" +#include "Log.hxx" void EventThread::Start() @@ -41,7 +43,16 @@ EventThread::Stop() noexcept void EventThread::Run() noexcept { - SetThreadName("io"); + SetThreadName(realtime ? "rtio" : "io"); + + if (realtime) { + try { + SetThreadRealtime(); + } catch (...) { + LogError(std::current_exception(), + "RTIOThread could not get realtime scheduling, continuing anyway"); + } + } event_loop.Run(); } diff --git a/src/event/Thread.hxx b/src/event/Thread.hxx index b9d2d72b5..cbc773627 100644 --- a/src/event/Thread.hxx +++ b/src/event/Thread.hxx @@ -32,9 +32,12 @@ class EventThread final { Thread thread; + const bool realtime; + public: - EventThread() - :event_loop(ThreadId::Null()), thread(BIND_THIS_METHOD(Run)) {} + explicit EventThread(bool _realtime=false) + :event_loop(ThreadId::Null()), thread(BIND_THIS_METHOD(Run)), + realtime(_realtime) {} ~EventThread() noexcept { Stop(); |