diff --git a/pvr.hts/addon.xml.in b/pvr.hts/addon.xml.in index 5a7f63c5..094b99b4 100644 --- a/pvr.hts/addon.xml.in +++ b/pvr.hts/addon.xml.in @@ -1,7 +1,7 @@ @ADDON_DEPENDS@ diff --git a/pvr.hts/changelog.txt b/pvr.hts/changelog.txt index f2907cd4..17e1b7bf 100644 --- a/pvr.hts/changelog.txt +++ b/pvr.hts/changelog.txt @@ -1,3 +1,6 @@ +v8.3.3 +- Fixed: Crash while restarting the add-on (due to stale HTSP connection thread after unloading add-on's shared lib). + v8.3.2 - Fixed: Timeshift issues after pausing and resuming Live TV (affects only demuxer-served channels). diff --git a/src/Tvheadend.cpp b/src/Tvheadend.cpp index a58ae0ca..1f05bb64 100644 --- a/src/Tvheadend.cpp +++ b/src/Tvheadend.cpp @@ -72,7 +72,7 @@ void CTvheadend::Stop() dmx->Close(); m_conn->Stop(); - StopThread(true); + StopThread(); } /* ************************************************************************** diff --git a/src/tvheadend/HTSPConnection.cpp b/src/tvheadend/HTSPConnection.cpp index b9235d39..80976a39 100644 --- a/src/tvheadend/HTSPConnection.cpp +++ b/src/tvheadend/HTSPConnection.cpp @@ -105,14 +105,15 @@ HTSPConnection::HTSPConnection(IHTSPConnectionListener& connListener) HTSPConnection::~HTSPConnection() { - StopThread(false); - Disconnect(); - StopThread(true); + Stop(); + StopThread(); delete m_regThread; } void HTSPConnection::Start() { + m_stopProcessing = false; + // Note: "connecting" must only be set one time, before the very first connection attempt, not on every reconnect. SetState(PVR_CONNECTION_STATE_CONNECTING); CreateThread(); @@ -120,7 +121,7 @@ void HTSPConnection::Start() void HTSPConnection::Stop() { - StopThread(false); + m_stopProcessing = true; Disconnect(); } @@ -656,7 +657,7 @@ void HTSPConnection::Process() static unsigned int retryAttempt = 0; const Settings& settings = Settings::GetInstance(); - while (!m_threadStop) + while (!ShouldStopProcessing()) { Logger::Log(LogLevel::LEVEL_DEBUG, "new connection requested"); @@ -681,13 +682,13 @@ void HTSPConnection::Process() } } - while (m_suspended && !m_threadStop) + while (m_suspended && !ShouldStopProcessing()) { /* Wait for wakeup */ Sleep(1000); } - if (m_threadStop) + if (ShouldStopProcessing()) break; if (!log) @@ -737,13 +738,13 @@ void HTSPConnection::Process() m_regThread->CreateThread(); /* Receive loop */ - while (!m_threadStop) + while (!ShouldStopProcessing()) { if (!ReadMessage()) break; } /* Stop connect thread (if not already) */ - m_regThread->StopThread(true); + m_regThread->StopThread(); } } diff --git a/src/tvheadend/HTSPConnection.h b/src/tvheadend/HTSPConnection.h index 190d420c..290cfd48 100644 --- a/src/tvheadend/HTSPConnection.h +++ b/src/tvheadend/HTSPConnection.h @@ -8,6 +8,7 @@ #pragma once +#include #include #include #include @@ -78,6 +79,8 @@ class HTSPConnection : public kodi::tools::CThread // CThread iplementation void Process() override; + bool ShouldStopProcessing() const { return m_stopProcessing || m_threadStop; } + void Register(); bool ReadMessage(); bool SendHello(std::unique_lock& lock); @@ -96,7 +99,7 @@ class HTSPConnection : public kodi::tools::CThread public: HTSPRegister(HTSPConnection* conn) : m_conn(conn) {} - ~HTSPRegister() override { StopThread(true); } + ~HTSPRegister() override { StopThread(); } private: // CThread implementation @@ -124,6 +127,8 @@ class HTSPConnection : public kodi::tools::CThread bool m_suspended; PVR_CONNECTION_STATE m_state; + + std::atomic m_stopProcessing = false; }; } // namespace tvheadend