From 0ca01a91ae0a3562e54c226e7b9512feb2ea83d0 Mon Sep 17 00:00:00 2001 From: Antonin Kral Date: Thu, 25 Mar 2010 19:21:32 +0100 Subject: Imported Upstream version 1.4.0 --- util/mmap_win.cpp | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) (limited to 'util/mmap_win.cpp') diff --git a/util/mmap_win.cpp b/util/mmap_win.cpp index 8a0d306..d831d66 100644 --- a/util/mmap_win.cpp +++ b/util/mmap_win.cpp @@ -49,7 +49,7 @@ namespace mongo { unsigned mapped = 0; - void* MemoryMappedFile::map(const char *_filename, long &length) { + void* MemoryMappedFile::map(const char *_filename, long &length, int options) { /* big hack here: Babble uses db names with colons. doesn't seem to work on windows. temporary perhaps. */ char filename[256]; strncpy(filename, _filename, 255); @@ -69,9 +69,13 @@ namespace mongo { updateLength( filename, length ); std::wstring filenamew = toWideString(filename); + DWORD createOptions = FILE_ATTRIBUTE_NORMAL; + if ( options & SEQUENTIAL ) + createOptions |= FILE_FLAG_SEQUENTIAL_SCAN; + fd = CreateFile( filenamew.c_str(), GENERIC_WRITE | GENERIC_READ, FILE_SHARE_READ, - NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); + NULL, OPEN_ALWAYS, createOptions , NULL); if ( fd == INVALID_HANDLE_VALUE ) { out() << "Create/OpenFile failed " << filename << ' ' << GetLastError() << endl; return 0; @@ -95,7 +99,21 @@ namespace mongo { return view; } - void MemoryMappedFile::flush(bool) { - } + void MemoryMappedFile::flush(bool sync) { + uassert(13056, "Async flushing not supported on windows", sync); + if (!view || !fd) return; + + bool success = FlushViewOfFile(view, 0); // 0 means whole mapping + if (!success){ + int err = GetLastError(); + out() << "FlushViewOfFile failed " << err << endl; + } + + success = FlushFileBuffers(fd); + if (!success){ + int err = GetLastError(); + out() << "FlushFileBuffers failed " << err << endl; + } + } } -- cgit v1.2.3