From 2f77d9916173cb199197ee9a6158d0fec86dad76 Mon Sep 17 00:00:00 2001 From: WarmUpTill Date: Sat, 6 Jun 2020 18:51:26 +0200 Subject: [PATCH] Undo "Revert "do not use QThread::create"" This reverts commit 4b86849356aeec6e45b5a5c9503e1f3a22e93721. --- src/advanced-scene-switcher.cpp | 4 +++- src/headers/switcher-data-structs.hpp | 12 +++++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/advanced-scene-switcher.cpp b/src/advanced-scene-switcher.cpp index 57f8c432..df59e982 100644 --- a/src/advanced-scene-switcher.cpp +++ b/src/advanced-scene-switcher.cpp @@ -1569,7 +1569,7 @@ void SwitcherData::Start() { if (!(th && th->isRunning())) { stop = false; - switcher->th = QThread::create([]() { switcher->Thread(); }); + switcher->th = new SwitcherThread(); switcher->th->start((QThread::Priority)switcher->threadPriority); } } @@ -1582,6 +1582,8 @@ void SwitcherData::Stop() transitionCv.notify_one(); cv.notify_one(); th->wait(); + delete th; + th = nullptr; } } diff --git a/src/headers/switcher-data-structs.hpp b/src/headers/switcher-data-structs.hpp index b10e43af..bcdca7b2 100644 --- a/src/headers/switcher-data-structs.hpp +++ b/src/headers/switcher-data-structs.hpp @@ -253,11 +253,14 @@ struct TimeSwitch { typedef enum { NO_SWITCH = 0, SWITCH = 1, RANDOM_SWITCH = 2 } NoMatch; +class SwitcherThread; + /******************************************************************************** * SwitcherData ********************************************************************************/ struct SwitcherData { - QThread* th = nullptr; + SwitcherThread *th; + condition_variable cv; mutex m; bool transitionActive = false; @@ -482,3 +485,10 @@ struct SwitcherData { } inline ~SwitcherData() { Stop(); } }; + +extern SwitcherData *switcher; +class SwitcherThread : public QThread { +public: + explicit SwitcherThread(){}; + void run() { switcher->Thread(); }; +};