[mythtv] Shoutcast patch ; updated for svn 16380.

Zdzislaw Gorlicki zdzisekg at comcast.net
Tue Mar 11 05:51:22 UTC 2008


Otto Kolsi wrote:
> Steven Adeff wrote:
>   
>> On Fri, Mar 7, 2008 at 1:54 PM, Eskil Heyn Olsen <myth at eskil.org> wrote:
>>     
>>> Updated for svn 16380, to be found at http://eskil.org/mythtv. Only
>>>  changes since last version is that I removed a bunch of leftover
>>>  debuglog prints.
>>>       
>> Just tried to apply the patch to 16458 and it looks pretty good except for:
>> $ patch -Np0 <shoutcast-16380.patch
>> patching file mythtv/themes/default-wide/music-ui.xml
>> patching file mythtv/libs/libmyth/output.cpp
>> patching file mythtv/libs/libmyth/mythobservable.cpp
>> Hunk #1 FAILED at 12.
>> 1 out of 1 hunk FAILED -- saving rejects to file
>> mythtv/libs/libmyth/mythobservable.cpp.rej
>> patching file mythtv/libs/libmyth/mythobservable.h
>>     
>
> Going back to 16380 is now a no-go with a production system, I think 
> there is a schema update in between and also QString thread instability.
>
> I tried the patch 2-3 weeks ago but back then I got several segfaults. 
> I'd like to give it now another go. Updated patch would be greatly 
> appreciated :)
>   
I tried to send a manually corrected patch, but I guess it was too big 
for the mailing list. To resolve the failed hunk make the 
mythobservable.cpp portion of the patch look like this:

Index: mythtv/libs/libmyth/mythobservable.cpp
===================================================================
--- mythtv/libs/libmyth/mythobservable.cpp    (revision 16380)
+++ mythtv/libs/libmyth/mythobservable.cpp    (working copy)
@@ -12,48 +12,55 @@
 
 void MythObservable::addListener(QObject *listener)
 {
+    QMutexLocker locked(&m_mutex);
     if (m_listeners.find(listener) == -1)
         m_listeners.append(listener);
 }
 
 void MythObservable::removeListener(QObject *listener)
 {
+    QMutexLocker locked(&m_mutex);
     if (m_listeners.find(listener) != -1)
         m_listeners.remove(listener);
 }
 
-QObject* MythObservable::firstListener()
-{
-    return m_listeners.first();
-}
-
-QObject* MythObservable::nextListener()
-{
-    return m_listeners.next();
-}
-
 QPtrList<QObject> MythObservable::getListeners()
 {
+    QMutexLocker locked(&m_mutex);
     return m_listeners;
 }
 
 void MythObservable::dispatch(MythEvent &event)
 {
-    QObject *listener = firstListener();
-    while (listener)
+    // Copy the list and iterate on the copy, in case another thread
+    // modifies the list.
+
+    m_mutex.lock ();
+    QPtrList<QObject> listeners(m_listeners);
+    m_mutex.unlock ();
+
+    QPtrListIterator<QObject> it (listeners);
+    while (class QObject *listener = it.current ())
     {
         QApplication::postEvent(listener, event.clone());
-        listener = nextListener();
+        ++it;
     }
 }
 
 void MythObservable::dispatchNow(MythEvent &event)
 {
-    QObject *listener = firstListener();
-    while (listener)
+    // Copy the list and iterate on the copy, in case another thread
+    // modifies the list.
+
+    m_mutex.lock ();
+    QPtrList<QObject> listeners(m_listeners);
+    m_mutex.unlock ();
+
+    QPtrListIterator<QObject> it (listeners);
+    while (class QObject *listener = it.current ())
     {
         QApplication::sendEvent(listener, event.clone());
-        listener = nextListener();
+        ++it;
     }
 }
 


More information about the mythtv-dev mailing list