diff options
author | Eliot Horowitz <eliot@10gen.com> | 2011-02-21 11:19:58 -0500 |
---|---|---|
committer | Eliot Horowitz <eliot@10gen.com> | 2011-02-21 11:19:58 -0500 |
commit | badd41ef11213d3e1b27bcad262ccc69d89bd155 (patch) | |
tree | 5482390bf81bc71146871a61ad4a7f7bb9569e02 | |
parent | 62b843a58874f2e77253dc8c4a1fe674b7258360 (diff) | |
download | mongo-badd41ef11213d3e1b27bcad262ccc69d89bd155.tar.gz |
line endings
-rw-r--r-- | db/mongommf.cpp | 124 |
1 files changed, 62 insertions, 62 deletions
diff --git a/db/mongommf.cpp b/db/mongommf.cpp index 46724c0ff1f..3349aead6ed 100644 --- a/db/mongommf.cpp +++ b/db/mongommf.cpp @@ -31,22 +31,22 @@ using namespace mongoutils; namespace mongo { -#if defined(_WIN32)
+#if defined(_WIN32) extern mutex mapViewMutex; - __declspec(noinline) void makeChunkWritable(size_t chunkno) {
+ __declspec(noinline) void makeChunkWritable(size_t chunkno) { scoped_lock lk(mapViewMutex); -
- if( writable.get(chunkno) ) // double check lock
- return;
-
- // remap all maps in this chunk. common case is a single map, but could have more than one with smallfiles or .ns files
- size_t chunkStart = chunkno * MemoryMappedFile::ChunkSize;
- size_t chunkNext = chunkStart + MemoryMappedFile::ChunkSize;
-
- scoped_lock lk2(privateViews._mutex());
- map<void*,MongoMMF*>::iterator i = privateViews.finditer_inlock((void*) (chunkNext-1));
- while( 1 ) {
+ + if( writable.get(chunkno) ) // double check lock + return; + + // remap all maps in this chunk. common case is a single map, but could have more than one with smallfiles or .ns files + size_t chunkStart = chunkno * MemoryMappedFile::ChunkSize; + size_t chunkNext = chunkStart + MemoryMappedFile::ChunkSize; + + scoped_lock lk2(privateViews._mutex()); + map<void*,MongoMMF*>::iterator i = privateViews.finditer_inlock((void*) (chunkNext-1)); + while( 1 ) { const pair<void*,MongoMMF*> x = *(--i); MongoMMF *mmf = x.second; if( mmf == 0 ) @@ -61,56 +61,56 @@ namespace mongo { dassert(protectStart<chunkNext); size_t protectEnd = min(viewEnd, chunkNext); - size_t protectSize = protectEnd - protectStart;
- dassert(protectSize>0&&protectSize<=MemoryMappedFile::ChunkSize);
-
- DWORD old;
- bool ok = VirtualProtect((void*)protectStart, protectSize, PAGE_WRITECOPY, &old);
- if( !ok ) {
- DWORD e = GetLastError();
- log() << "VirtualProtect failed " << chunkno << hex << protectStart << ' ' << protectSize << ' ' << errnoWithDescription(e) << endl;
- assert(false);
- }
- }
-
- writable.set(chunkno);
- }
-
- __declspec(noinline) void makeChunkWritableOld(size_t chunkno) {
+ size_t protectSize = protectEnd - protectStart; + dassert(protectSize>0&&protectSize<=MemoryMappedFile::ChunkSize); + + DWORD old; + bool ok = VirtualProtect((void*)protectStart, protectSize, PAGE_WRITECOPY, &old); + if( !ok ) { + DWORD e = GetLastError(); + log() << "VirtualProtect failed " << chunkno << hex << protectStart << ' ' << protectSize << ' ' << errnoWithDescription(e) << endl; + assert(false); + } + } + + writable.set(chunkno); + } + + __declspec(noinline) void makeChunkWritableOld(size_t chunkno) { scoped_lock lk(mapViewMutex); -
- if( writable.get(chunkno) )
- return;
-
- size_t loc = chunkno * MemoryMappedFile::ChunkSize;
- void *Loc = (void*) loc;
- size_t ofs;
- MongoMMF *mmf = privateViews.find( (void *) (loc), ofs );
- MemoryMappedFile *f = (MemoryMappedFile*) mmf;
- assert(f);
-
- size_t len = MemoryMappedFile::ChunkSize;
- assert( mmf->getView() <= Loc );
- if( ofs + len > f->length() ) {
- // at the very end of the map
- len = f->length() - ofs;
- }
- else {
- ;
- }
-
- // todo: check this goes away on remap
- DWORD old;
- bool ok = VirtualProtect(Loc, len, PAGE_WRITECOPY, &old);
- if( !ok ) {
- DWORD e = GetLastError();
- log() << "VirtualProtect failed " << Loc << ' ' << len << ' ' << errnoWithDescription(e) << endl;
- assert(false);
- }
-
- writable.set(chunkno);
- }
-
+ + if( writable.get(chunkno) ) + return; + + size_t loc = chunkno * MemoryMappedFile::ChunkSize; + void *Loc = (void*) loc; + size_t ofs; + MongoMMF *mmf = privateViews.find( (void *) (loc), ofs ); + MemoryMappedFile *f = (MemoryMappedFile*) mmf; + assert(f); + + size_t len = MemoryMappedFile::ChunkSize; + assert( mmf->getView() <= Loc ); + if( ofs + len > f->length() ) { + // at the very end of the map + len = f->length() - ofs; + } + else { + ; + } + + // todo: check this goes away on remap + DWORD old; + bool ok = VirtualProtect(Loc, len, PAGE_WRITECOPY, &old); + if( !ok ) { + DWORD e = GetLastError(); + log() << "VirtualProtect failed " << Loc << ' ' << len << ' ' << errnoWithDescription(e) << endl; + assert(false); + } + + writable.set(chunkno); + } + // align so that there is only one map per chunksize so our bitset works right void* mapaligned(HANDLE h, unsigned long long _len) { void *loc = 0; |