diff --git a/db/mongommf.h b/db/mongommf.h index 5da46fc7c87..b347e4ff259 100644 --- a/db/mongommf.h +++ b/db/mongommf.h @@ -27,6 +27,9 @@ namespace mongo { not this. */ class MongoMMF : private MemoryMappedFile { + protected: + virtual void* viewForFlushing() { return _view_write; } + public: MongoMMF(); virtual ~MongoMMF(); diff --git a/util/mmap.h b/util/mmap.h index 74ef8649c44..c09dfce281c 100644 --- a/util/mmap.h +++ b/util/mmap.h @@ -135,6 +135,13 @@ namespace mongo { }; class MemoryMappedFile : public MongoFile { + protected: + virtual void* viewForFlushing() { + if( views.size() == 0 ) + return 0; + assert( views.size() == 1 ); + return views[0]; + } public: MemoryMappedFile(); @@ -187,7 +194,7 @@ namespace mongo { HANDLE maphandle; vector views; unsigned long long len; - + #ifdef _WIN32 boost::shared_ptr _flushMutex; void clearWritableBits(void *privateView); diff --git a/util/mmap_posix.cpp b/util/mmap_posix.cpp index 309d0420928..5b213134f24 100644 --- a/util/mmap_posix.cpp +++ b/util/mmap_posix.cpp @@ -155,7 +155,7 @@ namespace mongo { void MemoryMappedFile::flush(bool sync) { if ( views.empty() || fd == 0 ) return; - if ( msync(views[0], len, sync ? MS_SYNC : MS_ASYNC) ) + if ( msync(viewForFlushing(), len, sync ? MS_SYNC : MS_ASYNC) ) problem() << "msync " << errnoWithDescription() << endl; } @@ -178,7 +178,7 @@ namespace mongo { }; MemoryMappedFile::Flushable * MemoryMappedFile::prepareFlush() { - return new PosixFlushable( views.empty() ? 0 : views[0] , fd , len ); + return new PosixFlushable( viewForFlushing() , fd , len ); } void MemoryMappedFile::_lock() { diff --git a/util/mmap_win.cpp b/util/mmap_win.cpp index 0b0b834becd..13369bad30b 100644 --- a/util/mmap_win.cpp +++ b/util/mmap_win.cpp @@ -183,13 +183,13 @@ namespace mongo { void MemoryMappedFile::flush(bool sync) { uassert(13056, "Async flushing not supported on windows", sync); if( !views.empty() ) { - WindowsFlushable f( views[0] , fd , filename() , _flushMutex); + WindowsFlushable f( viewForFlushing() , fd , filename() , _flushMutex); f.flush(); } } MemoryMappedFile::Flushable * MemoryMappedFile::prepareFlush() { - return new WindowsFlushable( views.empty() ? 0 : views[0] , fd , filename() , _flushMutex ); + return new WindowsFlushable( viewForFlushing() , fd , filename() , _flushMutex ); } void MemoryMappedFile::_lock() {} void MemoryMappedFile::_unlock() {}