From 5cff22d7585195d64b48fe4daea76a3664abfe73 Mon Sep 17 00:00:00 2001 From: WarmUpTill Date: Fri, 26 Aug 2016 16:06:35 +0200 Subject: [PATCH] pause hotkey freeze fix (Scene Round Trip/ not done) --- switcher.cpp | 6 +++++- switcher.h | 3 +++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/switcher.cpp b/switcher.cpp index 29288a4b..dbab7b7c 100644 --- a/switcher.cpp +++ b/switcher.cpp @@ -26,6 +26,7 @@ void Switcher::switcherThreadFunc() { bool checkFullscreen = false; bool pauseSwitching = false; size_t sleepTime = 1000; + auto locked = unique_lock(mtx); while (isRunning) { //get Scene Name obs_source_t * transitionUsed = obs_get_output_source(0); @@ -183,7 +184,8 @@ void Switcher::switcherThreadFunc() { } } //sleep for a bit - this_thread::sleep_for(chrono::milliseconds(sleepTime)); + terminate.wait_for(locked, chrono::milliseconds(sleepTime)); + //this_thread::sleep_for(chrono::milliseconds(sleepTime)); sleepTime = 1000; } } @@ -279,6 +281,7 @@ void Switcher::load() { //start thread void Switcher::start() { + auto locked = unique_lock(mtx); isRunning = true; switcherThread = thread(&Switcher::switcherThreadFunc, this); } @@ -386,6 +389,7 @@ string Switcher::GetActiveWindowTitle() //tell the thread to stop void Switcher::stop() { + auto locked = unique_lock(mtx); isRunning = false; if (switcherThread.joinable()) switcherThread.join(); } diff --git a/switcher.h b/switcher.h index 1010d1e6..e8bfd53d 100644 --- a/switcher.h +++ b/switcher.h @@ -29,4 +29,7 @@ private: bool isWindowFullscreen(); string GetActiveWindowTitle(); pair getCursorXY(); + bool quit; + mutex mtx; + condition_variable terminate; };