Skip to content

Commit

Permalink
Refs #9993. Move SSDP and TaskQueue thread shutdown to mythcontext.
Browse files Browse the repository at this point in the history
These threads can be started by MythContext even when UPnP is otherwise disabled if we don't find a config.xml or mysql.txt so we always need to ensure that they are shutdown whenever MythContext is used.
  • Loading branch information
daniel-kristjansson committed Aug 18, 2011
1 parent 42dfafe commit 4a6dcb9
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 16 deletions.
3 changes: 3 additions & 0 deletions mythtv/libs/libmyth/mythcontext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1104,6 +1104,9 @@ MythContext::~MythContext()
MThreadPool::globalInstance()->waitForDone();
logStop();

SSDP::Shutdown();
TaskQueue::Shutdown();

delete gCoreContext;
gCoreContext = NULL;

Expand Down
15 changes: 11 additions & 4 deletions mythtv/libs/libmythupnp/ssdp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,17 @@ SSDP* SSDP::Instance()
QMutexLocker locker(&g_pSSDPCreationLock);
return g_pSSDP ? g_pSSDP : (g_pSSDP = new SSDP());
}

/////////////////////////////////////////////////////////////////////////////
//
/////////////////////////////////////////////////////////////////////////////

void SSDP::Shutdown()
{
QMutexLocker locker(&g_pSSDPCreationLock);
delete g_pSSDP;
g_pSSDP = NULL;
}

/////////////////////////////////////////////////////////////////////////////
//
Expand Down Expand Up @@ -132,11 +143,7 @@ SSDP::~SSDP()
}
}

QMutexLocker locker(&g_pSSDPCreationLock);
g_pSSDP = NULL;

LOG(VB_UPNP, LOG_INFO, "SSDP Thread Terminated." );

}

void SSDP::RequestTerminate(void)
Expand Down
1 change: 1 addition & 0 deletions mythtv/libs/libmythupnp/ssdp.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ class UPNP_PUBLIC SSDP : public MThread
public:

static SSDP* Instance();
static void Shutdown();

~SSDP();

Expand Down
12 changes: 12 additions & 0 deletions mythtv/libs/libmythupnp/taskqueue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
// Define Global instance
/////////////////////////////////////////////////////////////////////////////

static QMutex g_pTaskQueueCreationLock;
TaskQueue* TaskQueue::g_pTaskQueue = NULL;

/////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -75,9 +76,20 @@ Task::~Task()

TaskQueue* TaskQueue::Instance()
{
QMutexLocker locker(&g_pTaskQueueCreationLock);
return g_pTaskQueue ? g_pTaskQueue : (g_pTaskQueue = new TaskQueue());
}

/////////////////////////////////////////////////////////////////////////////
//
/////////////////////////////////////////////////////////////////////////////

void TaskQueue::Shutdown()
{
QMutexLocker locker(&g_pTaskQueueCreationLock);
delete g_pTaskQueue;
g_pTaskQueue = NULL;
}

/////////////////////////////////////////////////////////////////////////////
//
Expand Down
1 change: 1 addition & 0 deletions mythtv/libs/libmythupnp/taskqueue.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ class UPNP_PUBLIC TaskQueue : public MThread
public:

static TaskQueue* Instance();
static void Shutdown();

virtual ~TaskQueue();

Expand Down
12 changes: 0 additions & 12 deletions mythtv/programs/mythfrontend/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -229,18 +229,6 @@ namespace
g_pUPnp = NULL;
}

if (SSDP::Instance())
{
SSDP::Instance()->RequestTerminate();
SSDP::Instance()->wait();
}

if (TaskQueue::Instance())
{
TaskQueue::Instance()->RequestTerminate();
TaskQueue::Instance()->wait();
}

if (pmanager)
{
delete pmanager;
Expand Down

0 comments on commit 4a6dcb9

Please sign in to comment.