changeset 244:85bf384db35f

* Update to use new vamp-hostsdk instead of vamp-sdk * Make spectrogram adapt its paint block size depending on how long it actually takes to draw * Some thread debugging infrastructure
author Chris Cannam
date Fri, 02 Mar 2007 13:01:41 +0000
parents ff46f251139e
children 4cd620bd4c61
files base/Thread.cpp base/Thread.h data/fft/FFTDataServer.cpp plugin/plugin.pro
diffstat 4 files changed, 85 insertions(+), 17 deletions(-) [+]
line wrap: on
line diff
--- a/base/Thread.cpp	Thu Mar 01 17:12:50 2007 +0000
+++ b/base/Thread.cpp	Fri Mar 02 13:01:41 2007 +0000
@@ -19,6 +19,10 @@
 #include <pthread.h>
 #endif
 
+//#define DEBUG_MUTEX_LOCKER 1
+
+#include <iostream>
+
 Thread::Thread(Type type, QObject *parent) :
     QThread(parent),
     m_type(type)
@@ -53,3 +57,33 @@
 #endif
 }
 
+MutexLocker::MutexLocker(QMutex *mutex, const char *name) :
+    m_printer(name),
+    m_locker(mutex)
+{
+#ifdef DEBUG_MUTEX_LOCKER
+    std::cerr << "... locked mutex " << mutex << std::endl;
+#endif
+}
+
+MutexLocker::~MutexLocker()
+{
+}
+
+MutexLocker::Printer::Printer(const char *name) :
+    m_name(name)
+{
+#ifdef DEBUG_MUTEX_LOCKER
+    std::cerr << "MutexLocker: Locking   \"" << m_name << "\" in "
+              << (void *)QThread::currentThreadId() << std::endl;
+#endif
+}
+
+MutexLocker::Printer::~Printer()
+{
+#ifdef DEBUG_MUTEX_LOCKER
+    std::cerr << "MutexLocker: Unlocking \"" << m_name
+              << "\" in " << (void *)QThread::currentThreadId() << std::endl;
+#endif
+}
+
--- a/base/Thread.h	Thu Mar 01 17:12:50 2007 +0000
+++ b/base/Thread.h	Fri Mar 02 13:01:41 2007 +0000
@@ -17,6 +17,7 @@
 #define _THREAD_H_
 
 #include <QThread>
+#include <QMutexLocker>
 
 class Thread : public QThread
 {
@@ -34,4 +35,25 @@
     Type m_type;
 };
 
+
+class MutexLocker
+{
+public:
+    MutexLocker(QMutex *mutex, const char *name);
+    ~MutexLocker();
+
+private:
+    class Printer {
+    public:
+        Printer(const char *name);
+        ~Printer();
+
+    private:
+        const char *m_name;
+    };
+
+    Printer m_printer;
+    QMutexLocker m_locker;
+};
+
 #endif
--- a/data/fft/FFTDataServer.cpp	Thu Mar 01 17:12:50 2007 +0000
+++ b/data/fft/FFTDataServer.cpp	Fri Mar 02 13:01:41 2007 +0000
@@ -25,11 +25,11 @@
 #include "base/StorageAdviser.h"
 #include "base/Exceptions.h"
 #include "base/Profiler.h"
+#include "base/Thread.h" // for debug mutex locker
 
 #include <QMessageBox>
 #include <QApplication>
 
-
 //#define DEBUG_FFT_SERVER 1
 //#define DEBUG_FFT_SERVER_FILL 1
 
@@ -39,6 +39,7 @@
 #endif
 #endif
 
+
 FFTDataServer::ServerMap FFTDataServer::m_servers;
 FFTDataServer::ServerQueue FFTDataServer::m_releasedServers;
 QMutex FFTDataServer::m_serverMapMutex;
@@ -63,7 +64,7 @@
 
     FFTDataServer *server = 0;
     
-    QMutexLocker locker(&m_serverMapMutex);
+    MutexLocker locker(&m_serverMapMutex, "FFTDataServer::m_serverMapMutex[getInstance]");
 
     if ((server = findServer(n))) {
         return server;
@@ -138,7 +139,7 @@
     // or 1536, the model doesn't support this).
 
     {
-        QMutexLocker locker(&m_serverMapMutex);
+        MutexLocker locker(&m_serverMapMutex, "FFTDataServer::m_serverMapMutex[getFuzzyInstance]");
 
         ServerMap::iterator best = m_servers.end();
         int bestdist = -1;
@@ -255,7 +256,8 @@
 void
 FFTDataServer::claimInstance(FFTDataServer *server, bool needLock)
 {
-    QMutexLocker locker(needLock ? &m_serverMapMutex : 0);
+    MutexLocker locker(needLock ? &m_serverMapMutex : 0,
+                       "FFTDataServer::m_serverMapMutex[claimInstance]");
 
 #ifdef DEBUG_FFT_SERVER
     std::cerr << "FFTDataServer::claimInstance(" << server << ")" << std::endl;
@@ -299,7 +301,8 @@
 void
 FFTDataServer::releaseInstance(FFTDataServer *server, bool needLock)
 {    
-    QMutexLocker locker(needLock ? &m_serverMapMutex : 0);
+    MutexLocker locker(needLock ? &m_serverMapMutex : 0,
+                       "FFTDataServer::m_serverMapMutex[releaseInstance]");
 
 #ifdef DEBUG_FFT_SERVER
     std::cerr << "FFTDataServer::releaseInstance(" << server << ")" << std::endl;
@@ -426,7 +429,8 @@
 void
 FFTDataServer::modelAboutToBeDeleted(Model *model)
 {
-    QMutexLocker locker(&m_serverMapMutex);
+    MutexLocker locker(&m_serverMapMutex,
+                       "FFTDataServer::m_serverMapMutex[modelAboutToBeDeleted]");
 
 #ifdef DEBUG_FFT_SERVER
     std::cerr << "FFTDataServer::modelAboutToBeDeleted(" << model << ")"
@@ -618,7 +622,8 @@
         delete m_fillThread;
     }
 
-    QMutexLocker locker(&m_writeMutex);
+    MutexLocker locker(&m_writeMutex,
+                       "FFTDataServer::m_writeMutex[~FFTDataServer]");
 
     for (CacheVector::iterator i = m_caches.begin(); i != m_caches.end(); ++i) {
         if (*i) {
@@ -658,7 +663,8 @@
 #endif
     Profiler profiler("FFTDataServer::suspend", false);
 
-    QMutexLocker locker(&m_writeMutex);
+    MutexLocker locker(&m_writeMutex,
+                       "FFTDataServer::m_writeMutex[suspend]");
     m_suspended = true;
     for (CacheVector::iterator i = m_caches.begin(); i != m_caches.end(); ++i) {
         if (*i) (*i)->suspend();
@@ -704,7 +710,8 @@
     std::cerr << "FFTDataServer(" << this << " [" << (void *)QThread::currentThreadId() << "])::getCacheAux" << std::endl;
 #endif
 
-    QMutexLocker locker(&m_writeMutex);
+    MutexLocker locker(&m_writeMutex,
+                       "FFTDataServer::m_writeMutex[getCacheAux]");
 
     if (m_lastUsedCache == -1) {
         m_fillThread->start();
@@ -982,7 +989,8 @@
     FFTCache *cache = getCache(x, col);
     if (!cache) return;
 
-    QMutexLocker locker(&m_writeMutex);
+    MutexLocker locker(&m_writeMutex,
+                       "FFTDataServer::m_writeMutex[fillColumn]");
 
     if (cache->haveSetColumnAt(col)) return;
 
@@ -1142,9 +1150,11 @@
 #ifdef DEBUG_FFT_SERVER
                 std::cerr << "FFTDataServer(" << this << " [" << (void *)QThread::currentThreadId() << "]): suspended, waiting..." << std::endl;
 #endif
-                m_server.m_writeMutex.lock();
-                m_server.m_condition.wait(&m_server.m_writeMutex, 10000);
-                m_server.m_writeMutex.unlock();
+                {
+                    MutexLocker locker(&m_server.m_writeMutex,
+                                       "FFTDataServer::m_writeMutex[run/1]");
+                    m_server.m_condition.wait(&m_server.m_writeMutex, 10000);
+                }
 #ifdef DEBUG_FFT_SERVER
                 std::cerr << "FFTDataServer(" << this << " [" << (void *)QThread::currentThreadId() << "]): waited" << std::endl;
 #endif
@@ -1176,9 +1186,11 @@
 #ifdef DEBUG_FFT_SERVER
             std::cerr << "FFTDataServer(" << this << " [" << (void *)QThread::currentThreadId() << "]): suspended, waiting..." << std::endl;
 #endif
-            m_server.m_writeMutex.lock();
-            m_server.m_condition.wait(&m_server.m_writeMutex, 10000);
-            m_server.m_writeMutex.unlock();
+            {
+                MutexLocker locker(&m_server.m_writeMutex,
+                                   "FFTDataServer::m_writeMutex[run/2]");
+                m_server.m_condition.wait(&m_server.m_writeMutex, 10000);
+            }
             if (m_server.m_exiting) return;
         }
 		    
--- a/plugin/plugin.pro	Thu Mar 01 17:12:50 2007 +0000
+++ b/plugin/plugin.pro	Fri Mar 02 13:01:41 2007 +0000
@@ -1,6 +1,6 @@
 TEMPLATE = lib
 
-SV_UNIT_PACKAGES = vamp vamp-sdk lrdf raptor
+SV_UNIT_PACKAGES = vamp vamp-hostsdk lrdf raptor
 load(../sv.prf)
 
 CONFIG += sv staticlib qt thread warn_on stl rtti exceptions