Skip to content

Commit

Permalink
Merge pull request #517 from ksooo/8-3-3
Browse files Browse the repository at this point in the history
8.3.3: Fixed crash while restarting the add-on.
  • Loading branch information
ksooo authored Jul 13, 2021
2 parents 261638f + 9462ba0 commit 1a44daf
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 12 deletions.
2 changes: 1 addition & 1 deletion pvr.hts/addon.xml.in
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<addon
id="pvr.hts"
version="8.3.2"
version="8.3.3"
name="Tvheadend HTSP Client"
provider-name="Adam Sutton, Sam Stenvall, Lars Op den Kamp, Kai Sommerfeld">
<requires>@ADDON_DEPENDS@</requires>
Expand Down
3 changes: 3 additions & 0 deletions pvr.hts/changelog.txt
Original file line number Diff line number Diff line change
@@ -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).

Expand Down
2 changes: 1 addition & 1 deletion src/Tvheadend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ void CTvheadend::Stop()
dmx->Close();

m_conn->Stop();
StopThread(true);
StopThread();
}

/* **************************************************************************
Expand Down
19 changes: 10 additions & 9 deletions src/tvheadend/HTSPConnection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,22 +105,23 @@ 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();
}

void HTSPConnection::Stop()
{
StopThread(false);
m_stopProcessing = true;
Disconnect();
}

Expand Down Expand Up @@ -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");

Expand All @@ -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)
Expand Down Expand Up @@ -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();
}
}
7 changes: 6 additions & 1 deletion src/tvheadend/HTSPConnection.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#pragma once

#include <atomic>
#include <condition_variable>
#include <map>
#include <mutex>
Expand Down Expand Up @@ -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<std::recursive_mutex>& lock);
Expand All @@ -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
Expand Down Expand Up @@ -124,6 +127,8 @@ class HTSPConnection : public kodi::tools::CThread

bool m_suspended;
PVR_CONNECTION_STATE m_state;

std::atomic<bool> m_stopProcessing = false;
};

} // namespace tvheadend

0 comments on commit 1a44daf

Please sign in to comment.