Hi guys,

This patch adds a 'mutexLogfile' and locks / unlocks it in the
MessageHandler when writing to the Logfile.

This ought to prevent, when the routine is called whilst still another
thread is still in there, the occasional segmentation fault when accessing
the Logfile (which can happen when aggressively using a MIDI controller,
causing multiple lines to get sent to the logfile at 'about the same time').

I have tested 2 versions: one with a mutex locked at the top of the
MessageHandler and unlocking it at the end; and this one, that locks it when
opening it, and locks it when trying to write to it. The latter seemed to
run more smoothly, so that's the one I'm sending :)

Cheers,
NG
Index: main.cpp
===================================================================
--- main.cpp	(revision 2738)
+++ main.cpp	(working copy)
@@ -100,10 +100,13 @@
 }
 
 QFile Logfile; // global logfile variable
+QMutex mutexLogfile; // for locking around access to the logfile
 
 
 void MessageToLogfile( QtMsgType type, const char * msg )
 {
+    mutexLogfile.lock();
+
     Q3TextStream Log( &Logfile );
     switch ( type ) {
     case QtDebugMsg:
@@ -123,9 +126,11 @@
     case QtFatalMsg:
         fprintf( stderr, "Fatal: %s\n", msg );
         QMessageBox::warning(0, "Mixxx", msg);
+		mutexLogfile.unlock();
         abort();
     }
     Logfile.flush();
+    mutexLogfile.unlock();
 }
 
 
@@ -141,20 +146,23 @@
     QByteArray ba = tmp.toLocal8Bit(); //necessary inner step to avoid memory corruption (otherwise the QByteArray is destroyed at the end of the next line which is BAD NEWS BEARS)
     const char* s = ba.constData();
     
-    
+
     if(!Logfile.isOpen())
     {
-    Logfile.setFileName("mixxx.log"); //XXX will there ever be a case that we can't write to our current working directory?
+        mutexLogfile.lock();
+        Logfile.setFileName("mixxx.log"); //XXX will there ever be a case that we can't write to our current working directory?
      
 #ifdef QT3_SUPPORT
-    Logfile.open(QIODevice::WriteOnly | QIODevice::Text);
+        Logfile.open(QIODevice::WriteOnly | QIODevice::Text);
 #else
-    Logfile.open(IO_WriteOnly | IO_Translate);
+        Logfile.open(IO_WriteOnly | IO_Translate);
 #endif
+        mutexLogfile.unlock();
     }
-      
+
     Q3TextStream Log( &Logfile );	
-    
+
+    mutexLogfile.lock();
     switch ( type ) {
     case QtDebugMsg:
 #ifdef __WIN32__  //wtf? -kousu 2/2009
@@ -188,7 +196,9 @@
         abort();
         break; //NOTREACHED
     }
-    Logfile.flush();
+
+    Logfile.flush( );
+    mutexLogfile.unlock( );
 }
 
 
@@ -212,10 +222,6 @@
 
 
 
-#ifdef __LADSPA__
-    //LADSPALoader ladspaloader;
-#endif
-
     QTranslator tor( 0 );
     // set the location where your .qm files are in load() below as the last parameter instead of "."
     // for development, use "/" to use the english original as
@@ -244,9 +250,10 @@
     }
     
     
+#ifdef __LADSPA__
     // set up the plugin paths...
     qDebug() << "Setting up plugin paths...";
-    /*
+/*
     plugin_paths = QStringList();
     QString ladspaPath = QString(getenv("LADSPA_PATH"));
 
@@ -278,8 +285,11 @@
          plugin_paths.push_back (programFiles+"\\Audacity\\Plug-Ins");
 #endif
     }
-    */
+    # LADSPALoader ladspaloader;
+*/
+
     qDebug() << "...done.";
+#endif
     
 #ifdef __APPLE__
      //XXX this should be wrapped in IF BUNDLED somehow
------------------------------------------------------------------------------
Apps built with the Adobe(R) Flex(R) framework and Flex Builder(TM) are
powering Web 2.0 with engaging, cross-platform capabilities. Quickly and
easily build your RIAs with Flex Builder, the Eclipse(TM)based development
software that enables intelligent coding and step-through debugging.
Download the free 60 day trial. http://p.sf.net/sfu/www-adobe-com
_______________________________________________
Mixxx-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mixxx-devel

Reply via email to