comparison data/fft/FFTFileCache.cpp @ 455:3e0f1f7bec85

* Fix a nasty and long-standing race condition in MatrixFile's use of FileReadThread that was causing crashes sometimes
author Chris Cannam
date Thu, 09 Oct 2008 20:10:28 +0000
parents 115f60df1e4d
children f60360209e5c
comparison
equal deleted inserted replaced
454:ba7aaacb7211 455:3e0f1f7bec85
17 17
18 #include "fileio/MatrixFile.h" 18 #include "fileio/MatrixFile.h"
19 19
20 #include "base/Profiler.h" 20 #include "base/Profiler.h"
21 #include "base/Thread.h" 21 #include "base/Thread.h"
22 #include "base/Exceptions.h"
22 23
23 #include <iostream> 24 #include <iostream>
24 25
25 26
26 // The underlying matrix has height (m_height * 2 + 1). In each 27 // The underlying matrix has height (m_height * 2 + 1). In each
306 Profiler profiler("FFTFileCache::populateReadBuf", false); 307 Profiler profiler("FFTFileCache::populateReadBuf", false);
307 308
308 if (!m_readbuf) { 309 if (!m_readbuf) {
309 m_readbuf = new char[m_mfc->getHeight() * 2 * m_mfc->getCellSize()]; 310 m_readbuf = new char[m_mfc->getHeight() * 2 * m_mfc->getCellSize()];
310 } 311 }
311 m_mfc->getColumnAt(x, m_readbuf); 312 try {
312 if (m_mfc->haveSetColumnAt(x + 1)) { 313 m_mfc->getColumnAt(x, m_readbuf);
313 m_mfc->getColumnAt 314 if (m_mfc->haveSetColumnAt(x + 1)) {
314 (x + 1, m_readbuf + m_mfc->getCellSize() * m_mfc->getHeight()); 315 m_mfc->getColumnAt
315 m_readbufWidth = 2; 316 (x + 1, m_readbuf + m_mfc->getCellSize() * m_mfc->getHeight());
316 } else { 317 m_readbufWidth = 2;
317 m_readbufWidth = 1; 318 } else {
319 m_readbufWidth = 1;
320 }
321 } catch (FileReadFailed f) {
322 std::cerr << "ERROR: FFTFileCache::populateReadBuf: File read failed: "
323 << f.what() << std::endl;
324 memset(m_readbuf, 0, m_mfc->getHeight() * 2 * m_mfc->getCellSize());
318 } 325 }
319 m_readbufCol = x; 326 m_readbufCol = x;
320 } 327 }
321 328