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
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
/// Update this whenever the plug-in API changes. /// Update this whenever the plug-in API changes.
/// Including changes in the libmythbase, libmyth, libmythtv, libmythav* and /// Including changes in the libmythbase, libmyth, libmythtv, libmythav* and
/// libmythui class methods used by plug-ins. /// 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. /** \brief Increment this whenever the MythTV network protocol changes.
* *
Expand Down
27 changes: 21 additions & 6 deletions mythtv/libs/libmythui/mythscreentype.cpp
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -22,16 +22,18 @@ QEvent::Type ScreenLoadCompletionEvent::kEventType =
class ScreenLoadTask : public QRunnable class ScreenLoadTask : public QRunnable
{ {
public: public:
ScreenLoadTask(MythScreenType *parent) : m_parent(parent) {} ScreenLoadTask(MythScreenType &parent) : m_parent(parent) {}


private: private:
void run() void run(void)
{ {
if (m_parent) m_parent.Load();
m_parent->LoadInForeground(); 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, MythScreenType::MythScreenType(MythScreenStack *parent, const QString &name,
Expand Down Expand Up @@ -80,6 +82,9 @@ MythScreenType::~MythScreenType()
// gCoreContext->SendSystemEvent( // gCoreContext->SendSystemEvent(
// QString("SCREEN_TYPE DESTROYED %1").arg(objectName())); // QString("SCREEN_TYPE DESTROYED %1").arg(objectName()));


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

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


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

m_IsLoading = true; m_IsLoading = true;
m_IsLoaded = false;

m_ScreenStack->AllowReInit(); m_ScreenStack->AllowReInit();


OpenBusyPopup(message); OpenBusyPopup(message);


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


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

m_IsLoading = true; m_IsLoading = true;
m_IsLoaded = false;

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


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

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


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


class ScreenLoadTask;
class MythScreenStack; class MythScreenStack;
class MythUIBusyDialog; class MythUIBusyDialog;


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


friend class ScreenLoadTask;

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


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


MythUIType *m_CurrentFocusWidget; MythUIType *m_CurrentFocusWidget;
Expand Down

0 comments on commit 643ad3e

Please sign in to comment.