From 4286cfb29c7ea0540e0c953054de3b9daad0123a Mon Sep 17 00:00:00 2001 From: Maximilian Seidler <78690852+PaideiaDilemma@users.noreply.github.com> Date: Sat, 2 Mar 2024 15:21:41 +0100 Subject: [PATCH] core: Fix unlock sync (#119) * core: error on repeated unlock * core: change termination points This seems to fix sporadic freezes when unlocking. --- src/core/hyprlock.cpp | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/core/hyprlock.cpp b/src/core/hyprlock.cpp index e2a9991..d0cf39c 100644 --- a/src/core/hyprlock.cpp +++ b/src/core/hyprlock.cpp @@ -322,12 +322,9 @@ void CHyprlock::run() { }; std::thread pollThr([this, &pollfds]() { - while (1) { + while (!m_bTerminate) { int ret = poll(pollfds, 1, 5000 /* 5 seconds, reasonable. It's because we might need to terminate */); - if (m_bTerminate) - break; - if (ret < 0) { Debug::log(CRIT, "[core] Polling fds failed with {}", errno); m_bTerminate = true; @@ -352,7 +349,7 @@ void CHyprlock::run() { }); std::thread timersThr([this]() { - while (1) { + while (!m_bTerminate) { // calc nearest thing m_sLoopState.timersMutex.lock(); @@ -369,9 +366,6 @@ void CHyprlock::run() { m_sLoopState.timerCV.wait_for(lk, std::chrono::milliseconds((int)least + 1), [this] { return m_sLoopState.timerEvent; }); m_sLoopState.timerEvent = false; - if (m_bTerminate) - break; - // notify main std::lock_guard lg2(m_sLoopState.eventLoopMutex); Debug::log(TRACE, "timer thread firing"); @@ -410,7 +404,7 @@ void CHyprlock::run() { do { ret = wl_display_dispatch_pending(m_sWaylandState.display); wl_display_flush(m_sWaylandState.display); - } while (ret > 0); + } while (ret > 0 && !m_bTerminate); // do timers m_sLoopState.timersMutex.lock(); @@ -717,6 +711,11 @@ void CHyprlock::lockSession() { void CHyprlock::unlockSession() { Debug::log(LOG, "Unlocking session"); + if (m_bTerminate && !m_sLockState.lock) { + Debug::log(ERR, "Unlock already happend?"); + return; + } + ext_session_lock_v1_unlock_and_destroy(m_sLockState.lock); m_sLockState.lock = nullptr;