From 96f28189159d6ae61cb8ef9e35ac706d5a146a96 Mon Sep 17 00:00:00 2001 From: Vaxry Date: Tue, 20 Feb 2024 00:31:11 +0000 Subject: [PATCH] core: fixup timer thread operations --- src/core/hyprlock.cpp | 14 ++++++++++++-- src/core/hyprlock.hpp | 1 + 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/core/hyprlock.cpp b/src/core/hyprlock.cpp index 672d63d..2aaf297 100644 --- a/src/core/hyprlock.cpp +++ b/src/core/hyprlock.cpp @@ -165,7 +165,11 @@ void CHyprlock::run() { m_sLoopState.timersMutex.unlock(); std::unique_lock lk(m_sLoopState.timerRequestMutex); - m_sLoopState.timerCV.wait_for(lk, std::chrono::milliseconds((int)least + 1), [this] { return m_sLoopState.event; }); + 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); @@ -230,6 +234,9 @@ void CHyprlock::run() { } while (ret > 0); } + std::lock_guard lg2(m_sLoopState.timerRequestMutex); + m_sLoopState.timerCV.notify_all(); + Debug::log(LOG, "Reached the end, exiting"); } @@ -493,5 +500,8 @@ size_t CHyprlock::getPasswordBufferLen() { std::shared_ptr CHyprlock::addTimer(const std::chrono::system_clock::duration& timeout, std::function self, void* data)> cb_, void* data) { std::lock_guard lg(m_sLoopState.timersMutex); - return m_vTimers.emplace_back(std::make_shared(timeout, cb_, data)); + const auto T = m_vTimers.emplace_back(std::make_shared(timeout, cb_, data)); + m_sLoopState.timerEvent = true; + m_sLoopState.timerCV.notify_all(); + return T; } diff --git a/src/core/hyprlock.hpp b/src/core/hyprlock.hpp index 82684bd..3295260 100644 --- a/src/core/hyprlock.hpp +++ b/src/core/hyprlock.hpp @@ -81,6 +81,7 @@ class CHyprlock { std::condition_variable timerCV; std::mutex timerRequestMutex; + bool timerEvent = false; } m_sLoopState; std::vector> m_vOutputs;