Mercurial > hg > svcore
comparison 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 |
comparison
equal
deleted
inserted
replaced
547:806e3c72b5df | 548:1469caaa8e67 |
---|---|
736 } | 736 } |
737 | 737 |
738 bool | 738 bool |
739 FFTDataServer::makeCache(int c) | 739 FFTDataServer::makeCache(int c) |
740 { | 740 { |
741 QWriteLocker locker(&m_cacheVectorLock); | 741 // Creating the cache could take a significant amount of time. We |
742 | 742 // don't want to block readers on m_cacheVectorLock while this is |
743 // happening, but we do want to block any further calls to | |
744 // makeCache. So we use this lock solely to serialise this | |
745 // particular function -- it isn't used anywhere else. | |
746 | |
747 QMutexLocker locker(&m_cacheCreationMutex); | |
748 | |
749 m_cacheVectorLock.lockForRead(); | |
743 if (m_caches[c]) { | 750 if (m_caches[c]) { |
744 // someone else must have created the cache between our | 751 // someone else must have created the cache between our |
745 // testing for it and taking the write lock | 752 // testing for it and taking the mutex |
753 m_cacheVectorLock.unlock(); | |
746 return true; | 754 return true; |
747 } | 755 } |
756 m_cacheVectorLock.unlock(); | |
757 | |
758 // Now m_cacheCreationMutex is held, but m_cacheVectorLock is not | |
759 // -- readers can proceed, but callers to this function will block | |
748 | 760 |
749 CacheBlock *cb = new CacheBlock; | 761 CacheBlock *cb = new CacheBlock; |
750 | 762 |
751 QString name = QString("%1-%2").arg(m_fileBaseName).arg(c); | 763 QString name = QString("%1-%2").arg(m_fileBaseName).arg(c); |
752 | 764 |
809 std::cerr << "ERROR: Failed to construct disc cache for FFT data: " | 821 std::cerr << "ERROR: Failed to construct disc cache for FFT data: " |
810 << e.what() << std::endl; | 822 << e.what() << std::endl; |
811 } | 823 } |
812 } | 824 } |
813 | 825 |
826 m_cacheVectorLock.lockForWrite(); | |
827 | |
814 m_caches[c] = cb; | 828 m_caches[c] = cb; |
829 | |
830 m_cacheVectorLock.unlock(); | |
815 | 831 |
816 return success; | 832 return success; |
817 } | 833 } |
818 | 834 |
819 bool | 835 bool |