16
16
#include " mythuigroup.h"
17
17
#include " mythlogging.h"
18
18
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
+
19
36
QEvent::Type ScreenLoadCompletionEvent::kEventType =
20
37
(QEvent::Type) QEvent::registerEventType();
21
38
@@ -30,15 +47,15 @@ class ScreenLoadTask : public QRunnable
30
47
m_parent.Load ();
31
48
m_parent.m_IsLoaded = true ;
32
49
m_parent.m_IsLoading = false ;
33
- m_parent.m_LoadLock .unlock ();
50
+ m_parent.m_LoadLock .release ();
34
51
}
35
52
36
53
MythScreenType &m_parent;
37
54
};
38
55
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 )
42
59
{
43
60
m_FullScreen = fullscreen;
44
61
m_CurrentFocusWidget = NULL ;
@@ -57,9 +74,9 @@ MythScreenType::MythScreenType(MythScreenStack *parent, const QString &name,
57
74
// QString("SCREEN_TYPE CREATED %1").arg(name));
58
75
}
59
76
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 )
63
80
{
64
81
m_FullScreen = fullscreen;
65
82
m_CurrentFocusWidget = NULL ;
@@ -83,7 +100,7 @@ MythScreenType::~MythScreenType()
83
100
// QString("SCREEN_TYPE DESTROYED %1").arg(objectName()));
84
101
85
102
// locking ensures background screen load can finish running
86
- QMutexLocker locker (&m_LoadLock);
103
+ SemaphoreLocker locker (&m_LoadLock);
87
104
88
105
m_CurrentFocusWidget = NULL ;
89
106
emit Exiting ();
@@ -299,7 +316,7 @@ void MythScreenType::Load(void)
299
316
300
317
void MythScreenType::LoadInBackground (QString message)
301
318
{
302
- m_LoadLock.lock ();
319
+ m_LoadLock.acquire ();
303
320
304
321
m_IsLoading = true ;
305
322
m_IsLoaded = false ;
@@ -314,7 +331,7 @@ void MythScreenType::LoadInBackground(QString message)
314
331
315
332
void MythScreenType::LoadInForeground (void )
316
333
{
317
- QMutexLocker locker (&m_LoadLock);
334
+ SemaphoreLocker locker (&m_LoadLock);
318
335
319
336
m_IsLoading = true ;
320
337
m_IsLoaded = false ;
@@ -378,7 +395,7 @@ bool MythScreenType::IsInitialized(void) const
378
395
379
396
void MythScreenType::doInit (void )
380
397
{
381
- QMutexLocker locker (&m_LoadLock); // don't run while loading..
398
+ SemaphoreLocker locker (&m_LoadLock); // don't run while loading..
382
399
383
400
CloseBusyPopup ();
384
401
Init ();
0 commit comments