# HG changeset patch # User Chris Cannam # Date 1146674824 0 # Node ID 27d726916ab33d203419f2f6a1c6b27c8b3fd50f # Parent 4988de098b258e2aec4533769af5581445c8655a * Remove mmap-based code again. We can be more efficient with read(). diff -r 4988de098b25 -r 27d726916ab3 base/MatrixFileCache.cpp --- a/base/MatrixFileCache.cpp Wed May 03 16:09:16 2006 +0000 +++ b/base/MatrixFileCache.cpp Wed May 03 16:47:04 2006 +0000 @@ -30,12 +30,6 @@ #include #include -//#define HAVE_MMAP 1 - -#ifdef HAVE_MMAP -#include -#endif - std::map MatrixFileCache::m_refcount; QMutex MatrixFileCache::m_refcountMutex; @@ -54,11 +48,7 @@ m_rx(0), m_rw(0), m_userRegion(false), - m_region(0), - m_mmapped(false), - m_mmapSize(0), - m_mmapOff(0), - m_preferMmap(false) + m_region(0) { // Ensure header size is a multiple of the size of our data (for // alignment purposes) @@ -121,13 +111,7 @@ MatrixFileCache::~MatrixFileCache() { if (m_rw > 0) { - if (m_mmapped) { -#ifdef HAVE_MMAP - ::munmap(m_region, m_mmapSize); -#endif - } else { - delete[] m_region; - } + delete[] m_region; } if (m_fd >= 0) { @@ -173,7 +157,7 @@ if (w * h > m_width * m_height) { -#ifdef HAVE_MMAP +/*!!! // If we're going to mmap the file, we need to ensure it's long // enough beforehand @@ -193,8 +177,7 @@ ::perror("WARNING: MatrixFileCache::resize: write failed"); } } -#endif - +*/ } else { if (::ftruncate(m_fd, off) < 0) { @@ -358,12 +341,6 @@ float *region = m_region; - if (m_mmapOff > 0) { - char *cr = (char *)m_region; - cr += m_mmapOff; - region = (float *)cr; - } - float *ptr = &(region[(x - m_rx) * m_height + y]); // std::cerr << "getRegionPtr(" << x << "," << y << "): region is " << m_region << ", returning " << ptr << std::endl; @@ -390,18 +367,8 @@ if (m_rw > 0 && x >= m_rx && x + width <= m_rx + m_rw) return true; if (m_rw > 0) { - if (m_mmapped) { -#ifdef HAVE_MMAP - ::munmap(m_region, m_mmapSize); - std::cerr << "unmapped " << m_mmapSize << " at " << m_region << std::endl; -#endif - } else { - delete[] m_region; - } + delete[] m_region; m_region = 0; - m_mmapped = false; - m_mmapSize = 0; - m_mmapOff = 0; m_rw = 0; } @@ -409,46 +376,6 @@ return true; } -#ifdef HAVE_MMAP - - if (m_preferMmap) { - - size_t mmapSize = m_height * width * sizeof(float); - off_t offset = m_headerSize + (x * m_height) * sizeof(float); - int pagesize = getpagesize(); - off_t aligned = (offset / pagesize) * pagesize; - size_t mmapOff = offset - aligned; - mmapSize += mmapOff; - - m_region = (float *) - ::mmap(0, mmapSize, PROT_READ, MAP_PRIVATE, m_fd, aligned); - - if (m_region == MAP_FAILED) { - - ::perror("Mmap failed"); - std::cerr << "ERROR: MatrixFileCache::setRegion(" << x << ", " - << width << "): Mmap(0, " << mmapSize - << ", " << PROT_READ << ", " << MAP_SHARED << ", " << m_fd - << ", " << aligned << ") failed, falling back to " - << "non-mmapping code for this cache" << std::endl; - m_preferMmap = false; - - } else { - - std::cerr << "mmap succeeded (offset " << aligned << ", size " << mmapSize << ", m_mmapOff " << mmapOff << ") = " << m_region << std::endl; - - m_mmapped = true; - m_mmapSize = mmapSize; - m_mmapOff = mmapOff; - m_rx = x; - m_rw = width; - if (user) m_userRegion = true; - MUNLOCK(m_region, m_mmapSize); - return true; - } - } -#endif - if (!seekTo(x, 0)) return false; m_region = new float[width * m_height]; diff -r 4988de098b25 -r 27d726916ab3 base/MatrixFileCache.h --- a/base/MatrixFileCache.h Wed May 03 16:09:16 2006 +0000 +++ b/base/MatrixFileCache.h Wed May 03 16:47:04 2006 +0000 @@ -62,10 +62,6 @@ mutable size_t m_rw; mutable bool m_userRegion; mutable float *m_region; - mutable bool m_mmapped; - mutable size_t m_mmapSize; - mutable size_t m_mmapOff; - mutable bool m_preferMmap; float *getRegionPtr(size_t x, size_t y) const; bool autoSetRegion(size_t x) const;