Ticket #3553: mythcontext.13589.txt

File mythcontext.13589.txt, 1.7 KB (added by Russell Bryant <russell@…>, 12 years ago)

Updated patch to simplify the loop in waitPrivEvent

Line 
1Index: libs/libmyth/mythcontext.cpp
2===================================================================
3--- libs/libmyth/mythcontext.cpp        (revision 13591)
4+++ libs/libmyth/mythcontext.cpp        (working copy)
5@@ -284,7 +284,7 @@
6 
7     DisplayRes *display_res;
8 
9-    QMutex *m_priv_mutex;
10+    QMutex m_priv_mutex;
11     queue<MythPrivRequest> m_priv_requests;
12     QWaitCondition m_priv_queued;
13 
14@@ -321,7 +321,6 @@
15       m_logenable(-1), m_logmaxcount(-1), m_logprintlevel(-1),
16       screensaverEnabled(false),
17       display_res(NULL),
18-      m_priv_mutex(new QMutex(true)),
19       useSettingsCache(false)
20 {
21     GetInstallPrefixPath( m_installprefix, m_installlibdir );
22@@ -462,8 +461,6 @@
23         serverSock->DownRef();
24     if (eventSock)
25         eventSock->DownRef();
26-    if (m_priv_mutex)
27-        delete m_priv_mutex;
28     if (screensaver)
29         delete screensaver;
30 }
31@@ -2874,24 +2871,22 @@
32 
33 void MythContext::addPrivRequest(MythPrivRequest::Type t, void *data)
34 {
35-    QMutexLocker lockit(d->m_priv_mutex);
36+    QMutexLocker lockit(&d->m_priv_mutex);
37     d->m_priv_requests.push(MythPrivRequest(t, data));
38     d->m_priv_queued.wakeAll();
39 }
40 
41 void MythContext::waitPrivRequest() const
42 {
43-    while (true)
44-    {
45-        d->m_priv_queued.wait();
46-        if (!d->m_priv_requests.empty())
47-            return;
48-    }
49+    d->m_priv_mutex.lock();
50+    while (d->m_priv_requests.empty())
51+        d->m_priv_queued.wait(&d->m_priv_mutex);
52+    d->m_priv_mutex.unlock();
53 }
54 
55 MythPrivRequest MythContext::popPrivRequest()
56 {
57-    QMutexLocker lockit(d->m_priv_mutex);
58+    QMutexLocker lockit(&d->m_priv_mutex);
59     MythPrivRequest ret_val(MythPrivRequest::PrivEnd, NULL);
60     if (!d->m_priv_requests.empty()) {
61         ret_val = d->m_priv_requests.front();