diff --git a/input.cpp b/input.cpp --- a/input.cpp +++ b/input.cpp @@ -1460,6 +1460,7 @@ if (LogindIntegration::self()->hasSessionControl()) { setupLibInput(); } else { + LibInput::Connection::createThread(); if (LogindIntegration::self()->isConnected()) { LogindIntegration::self()->takeControl(); } else { diff --git a/libinput/connection.h b/libinput/connection.h --- a/libinput/connection.h +++ b/libinput/connection.h @@ -25,6 +25,7 @@ #include #include +#include #include #include #include @@ -91,6 +92,8 @@ void updateLEDs(KWin::Xkb::LEDs leds); + static void createThread(); + Q_SIGNALS: void keyChanged(quint32 key, KWin::InputRedirection::KeyboardKeyState, quint32 time, KWin::LibInput::Device *device); void pointerButtonChanged(quint32 button, KWin::InputRedirection::PointerButtonState state, quint32 time, KWin::LibInput::Device *device); @@ -149,7 +152,7 @@ Xkb::LEDs m_leds; KWIN_SINGLETON(Connection) - static QThread *s_thread; + static QPointer s_thread; }; } diff --git a/libinput/connection.cpp b/libinput/connection.cpp --- a/libinput/connection.cpp +++ b/libinput/connection.cpp @@ -81,7 +81,7 @@ }; Connection *Connection::s_self = nullptr; -QThread *Connection::s_thread = nullptr; +QPointer Connection::s_thread; static ConnectionAdaptor *s_adaptor = nullptr; static Context *s_context = nullptr; @@ -107,6 +107,16 @@ // only here to fix build, using will crash, BUG 343529 } +void Connection::createThread() +{ + if (s_thread) { + return; + } + s_thread = new QThread(); + s_thread->setObjectName(QStringLiteral("libinput-connection")); + s_thread->start(); +} + Connection *Connection::create(QObject *parent) { Q_ASSERT(!s_self); @@ -131,10 +141,9 @@ return nullptr; } } - s_thread = new QThread(); + Connection::createThread(); s_self = new Connection(s_context); s_self->moveToThread(s_thread); - s_thread->start(); QObject::connect(s_thread, &QThread::finished, s_self, &QObject::deleteLater); QObject::connect(s_thread, &QThread::finished, s_thread, &QObject::deleteLater); QObject::connect(parent, &QObject::destroyed, s_thread, &QThread::quit); diff --git a/main_wayland.cpp b/main_wayland.cpp --- a/main_wayland.cpp +++ b/main_wayland.cpp @@ -82,6 +82,28 @@ static void readDisplay(int pipe); +enum class RealTimeFlags +{ + DontReset, + ResetOnFork +}; + +namespace { +void gainRealTime(RealTimeFlags flags = RealTimeFlags::DontReset) +{ +#if HAVE_SCHED_RESET_ON_FORK + const int minPriority = sched_get_priority_min(SCHED_RR); + struct sched_param sp; + sp.sched_priority = minPriority; + int policy = SCHED_RR; + if (flags == RealTimeFlags::ResetOnFork) { + policy |= SCHED_RESET_ON_FORK; + } + sched_setscheduler(0, policy, &sp); +#endif +} +} + //************************************ // ApplicationWayland //************************************ @@ -139,6 +161,9 @@ // try creating the Wayland Backend createInput(); + // now libinput thread has been created, adjust scheduler to not leak into other processes + gainRealTime(RealTimeFlags::ResetOnFork); + VirtualKeyboard::create(this); createBackend(); } @@ -460,16 +485,6 @@ return; } -void gainRealTime() -{ -#if HAVE_SCHED_RESET_ON_FORK - const int minPriority = sched_get_priority_min(SCHED_RR); - struct sched_param sp; - sp.sched_priority = minPriority; - sched_setscheduler(0, SCHED_RR | SCHED_RESET_ON_FORK, &sp); -#endif -} - void dropNiceCapability() { #if HAVE_LIBCAP