comparison data/fft/FFTFileCache.cpp @ 458:f60360209e5c

* Fix race condition in FFTFileCache when reading from the same FFT model from multiple threads (e.g. when applying more than one plugin at once)
author Chris Cannam
date Wed, 15 Oct 2008 12:08:02 +0000
parents 3e0f1f7bec85
children 6066bde1c126
comparison
equal deleted inserted replaced
457:ef14acd6d102 458:f60360209e5c
70 FFTFileCache::resize(size_t width, size_t height) 70 FFTFileCache::resize(size_t width, size_t height)
71 { 71 {
72 MutexLocker locker(&m_writeMutex, "FFTFileCache::resize::m_writeMutex"); 72 MutexLocker locker(&m_writeMutex, "FFTFileCache::resize::m_writeMutex");
73 73
74 m_mfc->resize(width, height * 2 + m_factorSize); 74 m_mfc->resize(width, height * 2 + m_factorSize);
75 if (m_readbuf) { 75
76 delete[] m_readbuf; 76 {
77 m_readbuf = 0; 77 MutexLocker locker(&m_readbufMutex, "FFTFileCache::resize::m_readMutex");
78 } 78 if (m_readbuf) {
79 delete[] m_readbuf;
80 m_readbuf = 0;
81 }
82 }
83
79 if (m_writebuf) { 84 if (m_writebuf) {
80 delete[] m_writebuf; 85 delete[] m_writebuf;
81 } 86 }
82 m_writebuf = new char[(height * 2 + m_factorSize) * m_mfc->getCellSize()]; 87 m_writebuf = new char[(height * 2 + m_factorSize) * m_mfc->getCellSize()];
83 } 88 }
84 89
85 void 90 void
86 FFTFileCache::reset() 91 FFTFileCache::reset()
87 { 92 {
88 m_mfc->reset(); 93 m_mfc->reset();
89 } 94 }
300 (type == Compact ? sizeof(uint16_t) : sizeof(float)) + 305 (type == Compact ? sizeof(uint16_t) : sizeof(float)) +
301 2 * sizeof(size_t); // matrix file header size 306 2 * sizeof(size_t); // matrix file header size
302 } 307 }
303 308
304 void 309 void
305 FFTFileCache::populateReadBuf(size_t x) const 310 FFTFileCache::populateReadBuf(size_t x) const // m_readbufMutex already held
306 { 311 {
307 Profiler profiler("FFTFileCache::populateReadBuf", false); 312 Profiler profiler("FFTFileCache::populateReadBuf", false);
308 313
309 if (!m_readbuf) { 314 if (!m_readbuf) {
310 m_readbuf = new char[m_mfc->getHeight() * 2 * m_mfc->getCellSize()]; 315 m_readbuf = new char[m_mfc->getHeight() * 2 * m_mfc->getCellSize()];