changeset 406:d095214ffbaf

* Fix deadlock in Serialiser
author Chris Cannam
date Tue, 29 Apr 2008 10:59:19 +0000
parents 65311fb86166
children 88ad01799040
files base/Serialiser.cpp base/Serialiser.h data/fileio/CSVFormat.cpp data/fileio/CodedAudioFileReader.cpp
diffstat 4 files changed, 17 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/base/Serialiser.cpp	Tue Apr 29 09:44:44 2008 +0000
+++ b/base/Serialiser.cpp	Tue Apr 29 10:59:19 2008 +0000
@@ -15,6 +15,8 @@
 
 #include "Serialiser.h"
 
+#include <iostream>
+
 QMutex
 Serialiser::m_mapMutex;
 
@@ -30,9 +32,18 @@
         m_mutexMap[m_id] = new QMutex;
     }
 
-    m_mutexMap[m_id]->lock();
+    // The id mutexes are never deleted, so once we have a reference
+    // to the one we need, we can hold on to it while we release the
+    // map mutex.  We need to release the map mutex, otherwise if the
+    // id mutex is currently held, it will never be released (because
+    // the destructor needs to hold the map mutex to release the id
+    // mutex).
+
+    QMutex *idMutex = m_mutexMap[m_id];
 
     m_mapMutex.unlock();
+
+    idMutex->lock();
 }
 
 Serialiser::~Serialiser()
--- a/base/Serialiser.h	Tue Apr 29 09:44:44 2008 +0000
+++ b/base/Serialiser.h	Tue Apr 29 10:59:19 2008 +0000
@@ -27,6 +27,8 @@
     Serialiser(QString id);
     ~Serialiser();
 
+    QString getId() const { return m_id; }
+
 protected:
     QString m_id;
     static QMutex m_mapMutex;
--- a/data/fileio/CSVFormat.cpp	Tue Apr 29 09:44:44 2008 +0000
+++ b/data/fileio/CSVFormat.cpp	Tue Apr 29 10:59:19 2008 +0000
@@ -82,7 +82,7 @@
                 }
             }
 
-            std::cerr << "separator = \"" << m_separator.toStdString() << "\"" << std::endl;
+//            std::cerr << "separator = \"" << m_separator.toStdString() << "\"" << std::endl;
 
             QStringList list = line.split(m_separator, m_behaviour);
             QStringList tidyList;
@@ -98,7 +98,7 @@
                     s = s.mid(1, s.length() - 2);
                 } else {
                     float f = s.toFloat(&numeric);
-                    std::cerr << "converted \"" << s.toStdString() << "\" to float, got " << f << " and success = " << numeric << std::endl;
+//                    std::cerr << "converted \"" << s.toStdString() << "\" to float, got " << f << " and success = " << numeric << std::endl;
                 }
 
                 tidyList.push_back(s);
--- a/data/fileio/CodedAudioFileReader.cpp	Tue Apr 29 09:44:44 2008 +0000
+++ b/data/fileio/CodedAudioFileReader.cpp	Tue Apr 29 10:59:19 2008 +0000
@@ -79,7 +79,7 @@
 void
 CodedAudioFileReader::endSerialised()
 {
-//    std::cerr << "CodedAudioFileReader::endSerialised" << std::endl;
+//    std::cerr << "CodedAudioFileReader(" << this << ")::endSerialised: id = " << (m_serialiser ? m_serialiser->getId().toStdString() : "(none)") << std::endl;
 
     delete m_serialiser;
     m_serialiser = 0;