Skip to content

Commit 8e3bc06

Browse files
Fixes #10981. Refs #10928. Convert QMutex to QSemaphore.
Since m_LoadLock is locked in the UI thread and unlocked in the worker thread it needs to use a QSemaphore instead of a QMutex. Thanks go to Lawrence Rust for discovering the issue.
1 parent 7b81b2a commit 8e3bc06

File tree

3 files changed

+31
-15
lines changed

3 files changed

+31
-15
lines changed

mythtv/libs/libmythbase/mythversion.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
/// Update this whenever the plug-in API changes.
1313
/// Including changes in the libmythbase, libmyth, libmythtv, libmythav* and
1414
/// libmythui class methods used by plug-ins.
15-
#define MYTH_BINARY_VERSION "0.26.20120730-1"
15+
#define MYTH_BINARY_VERSION "0.26.20120807-1"
1616

1717
/** \brief Increment this whenever the MythTV network protocol changes.
1818
*

mythtv/libs/libmythui/mythscreentype.cpp

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,23 @@
1616
#include "mythuigroup.h"
1717
#include "mythlogging.h"
1818

19+
class SemaphoreLocker
20+
{
21+
public:
22+
SemaphoreLocker(QSemaphore *lock) : m_lock(lock)
23+
{
24+
if (m_lock)
25+
m_lock->acquire();
26+
}
27+
~SemaphoreLocker()
28+
{
29+
if (m_lock)
30+
m_lock->release();
31+
}
32+
private:
33+
QSemaphore *m_lock;
34+
};
35+
1936
QEvent::Type ScreenLoadCompletionEvent::kEventType =
2037
(QEvent::Type) QEvent::registerEventType();
2138

@@ -30,15 +47,15 @@ class ScreenLoadTask : public QRunnable
3047
m_parent.Load();
3148
m_parent.m_IsLoaded = true;
3249
m_parent.m_IsLoading = false;
33-
m_parent.m_LoadLock.unlock();
50+
m_parent.m_LoadLock.release();
3451
}
3552

3653
MythScreenType &m_parent;
3754
};
3855

39-
MythScreenType::MythScreenType(MythScreenStack *parent, const QString &name,
40-
bool fullscreen)
41-
: MythUIType(parent, name)
56+
MythScreenType::MythScreenType(
57+
MythScreenStack *parent, const QString &name, bool fullscreen) :
58+
MythUIType(parent, name), m_LoadLock(1)
4259
{
4360
m_FullScreen = fullscreen;
4461
m_CurrentFocusWidget = NULL;
@@ -57,9 +74,9 @@ MythScreenType::MythScreenType(MythScreenStack *parent, const QString &name,
5774
// QString("SCREEN_TYPE CREATED %1").arg(name));
5875
}
5976

60-
MythScreenType::MythScreenType(MythUIType *parent, const QString &name,
61-
bool fullscreen)
62-
: MythUIType(parent, name)
77+
MythScreenType::MythScreenType(
78+
MythUIType *parent, const QString &name, bool fullscreen) :
79+
MythUIType(parent, name), m_LoadLock(1)
6380
{
6481
m_FullScreen = fullscreen;
6582
m_CurrentFocusWidget = NULL;
@@ -83,7 +100,7 @@ MythScreenType::~MythScreenType()
83100
// QString("SCREEN_TYPE DESTROYED %1").arg(objectName()));
84101

85102
// locking ensures background screen load can finish running
86-
QMutexLocker locker(&m_LoadLock);
103+
SemaphoreLocker locker(&m_LoadLock);
87104

88105
m_CurrentFocusWidget = NULL;
89106
emit Exiting();
@@ -299,7 +316,7 @@ void MythScreenType::Load(void)
299316

300317
void MythScreenType::LoadInBackground(QString message)
301318
{
302-
m_LoadLock.lock();
319+
m_LoadLock.acquire();
303320

304321
m_IsLoading = true;
305322
m_IsLoaded = false;
@@ -314,7 +331,7 @@ void MythScreenType::LoadInBackground(QString message)
314331

315332
void MythScreenType::LoadInForeground(void)
316333
{
317-
QMutexLocker locker(&m_LoadLock);
334+
SemaphoreLocker locker(&m_LoadLock);
318335

319336
m_IsLoading = true;
320337
m_IsLoaded = false;
@@ -378,7 +395,7 @@ bool MythScreenType::IsInitialized(void) const
378395

379396
void MythScreenType::doInit(void)
380397
{
381-
QMutexLocker locker(&m_LoadLock); // don't run while loading..
398+
SemaphoreLocker locker(&m_LoadLock); // don't run while loading..
382399

383400
CloseBusyPopup();
384401
Init();

mythtv/libs/libmythui/mythscreentype.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@
55
#include "mythuitext.h"
66
#include "mythuiutils.h"
77

8-
#include <QWaitCondition>
9-
#include <QMutex>
8+
#include <QSemaphore>
109
#include <QHash>
1110

1211
class ScreenLoadTask;
@@ -114,7 +113,7 @@ class MUI_PUBLIC MythScreenType : public MythUIType
114113
bool m_FullScreen;
115114
bool m_IsDeleting;
116115

117-
QMutex m_LoadLock;
116+
QSemaphore m_LoadLock;
118117
volatile bool m_IsLoading;
119118
volatile bool m_IsLoaded;
120119
bool m_IsInitialized;

0 commit comments

Comments
 (0)