Mercurial > hg > svcore
diff data/fft/FFTDataServer.cpp @ 548:1469caaa8e67
* Finer locking in fft caches; fix displayed bin ranges in spectrogram
author | Chris Cannam |
---|---|
date | Thu, 05 Feb 2009 12:05:28 +0000 |
parents | 87aef350f1dc |
children | 388afa99d537 |
line wrap: on
line diff
--- a/data/fft/FFTDataServer.cpp Wed Feb 04 20:39:11 2009 +0000 +++ b/data/fft/FFTDataServer.cpp Thu Feb 05 12:05:28 2009 +0000 @@ -738,13 +738,25 @@ bool FFTDataServer::makeCache(int c) { - QWriteLocker locker(&m_cacheVectorLock); + // Creating the cache could take a significant amount of time. We + // don't want to block readers on m_cacheVectorLock while this is + // happening, but we do want to block any further calls to + // makeCache. So we use this lock solely to serialise this + // particular function -- it isn't used anywhere else. + QMutexLocker locker(&m_cacheCreationMutex); + + m_cacheVectorLock.lockForRead(); if (m_caches[c]) { // someone else must have created the cache between our - // testing for it and taking the write lock + // testing for it and taking the mutex + m_cacheVectorLock.unlock(); return true; } + m_cacheVectorLock.unlock(); + + // Now m_cacheCreationMutex is held, but m_cacheVectorLock is not + // -- readers can proceed, but callers to this function will block CacheBlock *cb = new CacheBlock; @@ -811,8 +823,12 @@ } } + m_cacheVectorLock.lockForWrite(); + m_caches[c] = cb; + m_cacheVectorLock.unlock(); + return success; }