comparison data/fft/FFTDataServer.cpp @ 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 3e6fee4e4257
children d7eeffbb8aaf
comparison
equal deleted inserted replaced
243:ff46f251139e 244:85bf384db35f
23 #include "system/System.h" 23 #include "system/System.h"
24 24
25 #include "base/StorageAdviser.h" 25 #include "base/StorageAdviser.h"
26 #include "base/Exceptions.h" 26 #include "base/Exceptions.h"
27 #include "base/Profiler.h" 27 #include "base/Profiler.h"
28 #include "base/Thread.h" // for debug mutex locker
28 29
29 #include <QMessageBox> 30 #include <QMessageBox>
30 #include <QApplication> 31 #include <QApplication>
31
32 32
33 //#define DEBUG_FFT_SERVER 1 33 //#define DEBUG_FFT_SERVER 1
34 //#define DEBUG_FFT_SERVER_FILL 1 34 //#define DEBUG_FFT_SERVER_FILL 1
35 35
36 #ifdef DEBUG_FFT_SERVER_FILL 36 #ifdef DEBUG_FFT_SERVER_FILL
37 #ifndef DEBUG_FFT_SERVER 37 #ifndef DEBUG_FFT_SERVER
38 #define DEBUG_FFT_SERVER 1 38 #define DEBUG_FFT_SERVER 1
39 #endif 39 #endif
40 #endif 40 #endif
41
41 42
42 FFTDataServer::ServerMap FFTDataServer::m_servers; 43 FFTDataServer::ServerMap FFTDataServer::m_servers;
43 FFTDataServer::ServerQueue FFTDataServer::m_releasedServers; 44 FFTDataServer::ServerQueue FFTDataServer::m_releasedServers;
44 QMutex FFTDataServer::m_serverMapMutex; 45 QMutex FFTDataServer::m_serverMapMutex;
45 46
61 fftSize, 62 fftSize,
62 polar); 63 polar);
63 64
64 FFTDataServer *server = 0; 65 FFTDataServer *server = 0;
65 66
66 QMutexLocker locker(&m_serverMapMutex); 67 MutexLocker locker(&m_serverMapMutex, "FFTDataServer::m_serverMapMutex[getInstance]");
67 68
68 if ((server = findServer(n))) { 69 if ((server = findServer(n))) {
69 return server; 70 return server;
70 } 71 }
71 72
136 // multiple of the smaller (e.g. even though in principle you can 137 // multiple of the smaller (e.g. even though in principle you can
137 // draw the results at increment 256 from those at increment 768 138 // draw the results at increment 256 from those at increment 768
138 // or 1536, the model doesn't support this). 139 // or 1536, the model doesn't support this).
139 140
140 { 141 {
141 QMutexLocker locker(&m_serverMapMutex); 142 MutexLocker locker(&m_serverMapMutex, "FFTDataServer::m_serverMapMutex[getFuzzyInstance]");
142 143
143 ServerMap::iterator best = m_servers.end(); 144 ServerMap::iterator best = m_servers.end();
144 int bestdist = -1; 145 int bestdist = -1;
145 146
146 for (ServerMap::iterator i = m_servers.begin(); i != m_servers.end(); ++i) { 147 for (ServerMap::iterator i = m_servers.begin(); i != m_servers.end(); ++i) {
253 } 254 }
254 255
255 void 256 void
256 FFTDataServer::claimInstance(FFTDataServer *server, bool needLock) 257 FFTDataServer::claimInstance(FFTDataServer *server, bool needLock)
257 { 258 {
258 QMutexLocker locker(needLock ? &m_serverMapMutex : 0); 259 MutexLocker locker(needLock ? &m_serverMapMutex : 0,
260 "FFTDataServer::m_serverMapMutex[claimInstance]");
259 261
260 #ifdef DEBUG_FFT_SERVER 262 #ifdef DEBUG_FFT_SERVER
261 std::cerr << "FFTDataServer::claimInstance(" << server << ")" << std::endl; 263 std::cerr << "FFTDataServer::claimInstance(" << server << ")" << std::endl;
262 #endif 264 #endif
263 265
297 } 299 }
298 300
299 void 301 void
300 FFTDataServer::releaseInstance(FFTDataServer *server, bool needLock) 302 FFTDataServer::releaseInstance(FFTDataServer *server, bool needLock)
301 { 303 {
302 QMutexLocker locker(needLock ? &m_serverMapMutex : 0); 304 MutexLocker locker(needLock ? &m_serverMapMutex : 0,
305 "FFTDataServer::m_serverMapMutex[releaseInstance]");
303 306
304 #ifdef DEBUG_FFT_SERVER 307 #ifdef DEBUG_FFT_SERVER
305 std::cerr << "FFTDataServer::releaseInstance(" << server << ")" << std::endl; 308 std::cerr << "FFTDataServer::releaseInstance(" << server << ")" << std::endl;
306 #endif 309 #endif
307 310
424 } 427 }
425 428
426 void 429 void
427 FFTDataServer::modelAboutToBeDeleted(Model *model) 430 FFTDataServer::modelAboutToBeDeleted(Model *model)
428 { 431 {
429 QMutexLocker locker(&m_serverMapMutex); 432 MutexLocker locker(&m_serverMapMutex,
433 "FFTDataServer::m_serverMapMutex[modelAboutToBeDeleted]");
430 434
431 #ifdef DEBUG_FFT_SERVER 435 #ifdef DEBUG_FFT_SERVER
432 std::cerr << "FFTDataServer::modelAboutToBeDeleted(" << model << ")" 436 std::cerr << "FFTDataServer::modelAboutToBeDeleted(" << model << ")"
433 << std::endl; 437 << std::endl;
434 #endif 438 #endif
616 if (m_fillThread) { 620 if (m_fillThread) {
617 m_fillThread->wait(); 621 m_fillThread->wait();
618 delete m_fillThread; 622 delete m_fillThread;
619 } 623 }
620 624
621 QMutexLocker locker(&m_writeMutex); 625 MutexLocker locker(&m_writeMutex,
626 "FFTDataServer::m_writeMutex[~FFTDataServer]");
622 627
623 for (CacheVector::iterator i = m_caches.begin(); i != m_caches.end(); ++i) { 628 for (CacheVector::iterator i = m_caches.begin(); i != m_caches.end(); ++i) {
624 if (*i) { 629 if (*i) {
625 delete *i; 630 delete *i;
626 } else { 631 } else {
656 #ifdef DEBUG_FFT_SERVER 661 #ifdef DEBUG_FFT_SERVER
657 std::cerr << "FFTDataServer(" << this << " [" << (void *)QThread::currentThreadId() << "]): suspend" << std::endl; 662 std::cerr << "FFTDataServer(" << this << " [" << (void *)QThread::currentThreadId() << "]): suspend" << std::endl;
658 #endif 663 #endif
659 Profiler profiler("FFTDataServer::suspend", false); 664 Profiler profiler("FFTDataServer::suspend", false);
660 665
661 QMutexLocker locker(&m_writeMutex); 666 MutexLocker locker(&m_writeMutex,
667 "FFTDataServer::m_writeMutex[suspend]");
662 m_suspended = true; 668 m_suspended = true;
663 for (CacheVector::iterator i = m_caches.begin(); i != m_caches.end(); ++i) { 669 for (CacheVector::iterator i = m_caches.begin(); i != m_caches.end(); ++i) {
664 if (*i) (*i)->suspend(); 670 if (*i) (*i)->suspend();
665 } 671 }
666 } 672 }
702 Profiler profiler("FFTDataServer::getCacheAux", false); 708 Profiler profiler("FFTDataServer::getCacheAux", false);
703 #ifdef DEBUG_FFT_SERVER 709 #ifdef DEBUG_FFT_SERVER
704 std::cerr << "FFTDataServer(" << this << " [" << (void *)QThread::currentThreadId() << "])::getCacheAux" << std::endl; 710 std::cerr << "FFTDataServer(" << this << " [" << (void *)QThread::currentThreadId() << "])::getCacheAux" << std::endl;
705 #endif 711 #endif
706 712
707 QMutexLocker locker(&m_writeMutex); 713 MutexLocker locker(&m_writeMutex,
714 "FFTDataServer::m_writeMutex[getCacheAux]");
708 715
709 if (m_lastUsedCache == -1) { 716 if (m_lastUsedCache == -1) {
710 m_fillThread->start(); 717 m_fillThread->start();
711 } 718 }
712 719
980 std::cout << "FFTDataServer::fillColumn(" << x << ")" << std::endl; 987 std::cout << "FFTDataServer::fillColumn(" << x << ")" << std::endl;
981 #endif 988 #endif
982 FFTCache *cache = getCache(x, col); 989 FFTCache *cache = getCache(x, col);
983 if (!cache) return; 990 if (!cache) return;
984 991
985 QMutexLocker locker(&m_writeMutex); 992 MutexLocker locker(&m_writeMutex,
993 "FFTDataServer::m_writeMutex[fillColumn]");
986 994
987 if (cache->haveSetColumnAt(col)) return; 995 if (cache->haveSetColumnAt(col)) return;
988 996
989 int startFrame = m_windowIncrement * x; 997 int startFrame = m_windowIncrement * x;
990 int endFrame = startFrame + m_windowSize; 998 int endFrame = startFrame + m_windowSize;
1140 1148
1141 while (m_server.m_suspended) { 1149 while (m_server.m_suspended) {
1142 #ifdef DEBUG_FFT_SERVER 1150 #ifdef DEBUG_FFT_SERVER
1143 std::cerr << "FFTDataServer(" << this << " [" << (void *)QThread::currentThreadId() << "]): suspended, waiting..." << std::endl; 1151 std::cerr << "FFTDataServer(" << this << " [" << (void *)QThread::currentThreadId() << "]): suspended, waiting..." << std::endl;
1144 #endif 1152 #endif
1145 m_server.m_writeMutex.lock(); 1153 {
1146 m_server.m_condition.wait(&m_server.m_writeMutex, 10000); 1154 MutexLocker locker(&m_server.m_writeMutex,
1147 m_server.m_writeMutex.unlock(); 1155 "FFTDataServer::m_writeMutex[run/1]");
1156 m_server.m_condition.wait(&m_server.m_writeMutex, 10000);
1157 }
1148 #ifdef DEBUG_FFT_SERVER 1158 #ifdef DEBUG_FFT_SERVER
1149 std::cerr << "FFTDataServer(" << this << " [" << (void *)QThread::currentThreadId() << "]): waited" << std::endl; 1159 std::cerr << "FFTDataServer(" << this << " [" << (void *)QThread::currentThreadId() << "]): waited" << std::endl;
1150 #endif 1160 #endif
1151 if (m_server.m_exiting) return; 1161 if (m_server.m_exiting) return;
1152 } 1162 }
1174 1184
1175 while (m_server.m_suspended) { 1185 while (m_server.m_suspended) {
1176 #ifdef DEBUG_FFT_SERVER 1186 #ifdef DEBUG_FFT_SERVER
1177 std::cerr << "FFTDataServer(" << this << " [" << (void *)QThread::currentThreadId() << "]): suspended, waiting..." << std::endl; 1187 std::cerr << "FFTDataServer(" << this << " [" << (void *)QThread::currentThreadId() << "]): suspended, waiting..." << std::endl;
1178 #endif 1188 #endif
1179 m_server.m_writeMutex.lock(); 1189 {
1180 m_server.m_condition.wait(&m_server.m_writeMutex, 10000); 1190 MutexLocker locker(&m_server.m_writeMutex,
1181 m_server.m_writeMutex.unlock(); 1191 "FFTDataServer::m_writeMutex[run/2]");
1192 m_server.m_condition.wait(&m_server.m_writeMutex, 10000);
1193 }
1182 if (m_server.m_exiting) return; 1194 if (m_server.m_exiting) return;
1183 } 1195 }
1184 1196
1185 if (++counter == updateAt) { 1197 if (++counter == updateAt) {
1186 m_extent = f; 1198 m_extent = f;