Skip to content

Commit

Permalink
Fixes #10928. Fix race in LoadInBackground() handling.
Browse files Browse the repository at this point in the history
  • Loading branch information
daniel-kristjansson committed Jul 24, 2012
1 parent 483e06f commit 643ad3e
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 9 deletions.
2 changes: 1 addition & 1 deletion mythtv/libs/libmythbase/mythversion.h
Expand Up @@ -12,7 +12,7 @@
/// Update this whenever the plug-in API changes.
/// Including changes in the libmythbase, libmyth, libmythtv, libmythav* and
/// libmythui class methods used by plug-ins.
#define MYTH_BINARY_VERSION "0.26.20120721-1"
#define MYTH_BINARY_VERSION "0.26.20120724-1"

/** \brief Increment this whenever the MythTV network protocol changes.
*
Expand Down
27 changes: 21 additions & 6 deletions mythtv/libs/libmythui/mythscreentype.cpp
Expand Up @@ -22,16 +22,18 @@ QEvent::Type ScreenLoadCompletionEvent::kEventType =
class ScreenLoadTask : public QRunnable
{
public:
ScreenLoadTask(MythScreenType *parent) : m_parent(parent) {}
ScreenLoadTask(MythScreenType &parent) : m_parent(parent) {}

private:
void run()
void run(void)
{
if (m_parent)
m_parent->LoadInForeground();
m_parent.Load();
m_parent.m_IsLoaded = true;
m_parent.m_IsLoading = false;
m_parent.m_LoadLock.unlock();
}

MythScreenType *m_parent;
MythScreenType &m_parent;
};

MythScreenType::MythScreenType(MythScreenStack *parent, const QString &name,
Expand Down Expand Up @@ -80,6 +82,9 @@ MythScreenType::~MythScreenType()
// gCoreContext->SendSystemEvent(
// QString("SCREEN_TYPE DESTROYED %1").arg(objectName()));

// locking ensures background screen load can finish running
QMutexLocker locker(&m_LoadLock);

m_CurrentFocusWidget = NULL;
emit Exiting();
}
Expand Down Expand Up @@ -294,18 +299,26 @@ void MythScreenType::Load(void)

void MythScreenType::LoadInBackground(QString message)
{
m_LoadLock.lock();

m_IsLoading = true;
m_IsLoaded = false;

m_ScreenStack->AllowReInit();

OpenBusyPopup(message);

ScreenLoadTask *loadTask = new ScreenLoadTask(this);
ScreenLoadTask *loadTask = new ScreenLoadTask(*this);
MThreadPool::globalInstance()->start(loadTask, "ScreenLoad");
}

void MythScreenType::LoadInForeground(void)
{
QMutexLocker locker(&m_LoadLock);

m_IsLoading = true;
m_IsLoaded = false;

m_ScreenStack->AllowReInit();
Load();
m_IsLoaded = true;
Expand Down Expand Up @@ -365,6 +378,8 @@ bool MythScreenType::IsInitialized(void) const

void MythScreenType::doInit(void)
{
QMutexLocker locker(&m_LoadLock); // don't run while loading..

CloseBusyPopup();
Init();
m_IsInitialized = true;
Expand Down
11 changes: 9 additions & 2 deletions mythtv/libs/libmythui/mythscreentype.h
Expand Up @@ -5,8 +5,11 @@
#include "mythuitext.h"
#include "mythuiutils.h"

#include <QWaitCondition>
#include <QMutex>
#include <QHash>

class ScreenLoadTask;
class MythScreenStack;
class MythUIBusyDialog;

Expand Down Expand Up @@ -40,6 +43,8 @@ class MUI_PUBLIC MythScreenType : public MythUIType
{
Q_OBJECT

friend class ScreenLoadTask;

public:
MythScreenType(MythScreenStack *parent, const QString &name,
bool fullscreen = true);
Expand Down Expand Up @@ -108,8 +113,10 @@ class MUI_PUBLIC MythScreenType : public MythUIType

bool m_FullScreen;
bool m_IsDeleting;
bool m_IsLoading;
bool m_IsLoaded;

QMutex m_LoadLock;
volatile bool m_IsLoading;
volatile bool m_IsLoaded;
bool m_IsInitialized;

MythUIType *m_CurrentFocusWidget;
Expand Down

0 comments on commit 643ad3e

Please sign in to comment.