diff options
author | Aaron <aaron@10gen.com> | 2009-01-15 10:17:11 -0500 |
---|---|---|
committer | Aaron <aaron@10gen.com> | 2009-01-15 10:17:11 -0500 |
commit | 90d45238aa5fccb6dbdf0b40dfcf5823695d4643 (patch) | |
tree | 7a95e901512b890eb06309af2edd0da9c88b7279 /util/mmap.cpp | |
parent | 938c2c07a8032259527b8e9cbb6d0d12c7e8867a (diff) | |
download | mongo-90d45238aa5fccb6dbdf0b40dfcf5823695d4643.tar.gz |
Indent all lines within namespaces one level
Diffstat (limited to 'util/mmap.cpp')
-rw-r--r-- | util/mmap.cpp | 288 |
1 files changed, 144 insertions, 144 deletions
diff --git a/util/mmap.cpp b/util/mmap.cpp index 2d0df61f3d9..402690e4ce9 100644 --- a/util/mmap.cpp +++ b/util/mmap.cpp @@ -21,33 +21,33 @@ namespace mongo { -set<MemoryMappedFile*> mmfiles; - -MemoryMappedFile::~MemoryMappedFile() { - close(); - mmfiles.erase(this); -} - -/*static*/ -int closingAllFiles = 0; -void MemoryMappedFile::closeAllFiles() { - if ( closingAllFiles ) { - cout << "warning closingAllFiles=" << closingAllFiles << endl; - return; + set<MemoryMappedFile*> mmfiles; + + MemoryMappedFile::~MemoryMappedFile() { + close(); + mmfiles.erase(this); + } + + /*static*/ + int closingAllFiles = 0; + void MemoryMappedFile::closeAllFiles() { + if ( closingAllFiles ) { + cout << "warning closingAllFiles=" << closingAllFiles << endl; + return; + } + ++closingAllFiles; + for ( set<MemoryMappedFile*>::iterator i = mmfiles.begin(); i != mmfiles.end(); i++ ) + (*i)->close(); + log() << " closeAllFiles() finished" << endl; + --closingAllFiles; + } + + void MemoryMappedFile::updateLength( const char *filename, int &length ) const { + if ( !boost::filesystem::exists( filename ) ) + return; + // make sure we map full length if preexisting file. + length = boost::filesystem::file_size( filename ); } - ++closingAllFiles; - for ( set<MemoryMappedFile*>::iterator i = mmfiles.begin(); i != mmfiles.end(); i++ ) - (*i)->close(); - log() << " closeAllFiles() finished" << endl; - --closingAllFiles; -} - -void MemoryMappedFile::updateLength( const char *filename, int &length ) const { - if ( !boost::filesystem::exists( filename ) ) - return; - // make sure we map full length if preexisting file. - length = boost::filesystem::file_size( filename ); -} #if defined(_WIN32) @@ -57,72 +57,72 @@ void MemoryMappedFile::updateLength( const char *filename, int &length ) const { namespace mongo { -MemoryMappedFile::MemoryMappedFile() { - fd = 0; - maphandle = 0; - view = 0; - mmfiles.insert(this); -} - -void MemoryMappedFile::close() { - if ( view ) - UnmapViewOfFile(view); - view = 0; - if ( maphandle ) - CloseHandle(maphandle); - maphandle = 0; - if ( fd ) - CloseHandle(fd); - fd = 0; -} - -std::wstring toWideString(const char *s) { - std::basic_ostringstream<TCHAR> buf; - buf << s; - return buf.str(); -} - -unsigned mapped = 0; - -void* MemoryMappedFile::map(const char *filename, int length) { - updateLength( filename, length ); - std::wstring filenamew = toWideString(filename); - - fd = CreateFile( - filenamew.c_str(), GENERIC_WRITE | GENERIC_READ, FILE_SHARE_READ, - NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); - if ( fd == INVALID_HANDLE_VALUE ) { - cout << "CreateFile failed " << filename << endl; - return 0; + MemoryMappedFile::MemoryMappedFile() { + fd = 0; + maphandle = 0; + view = 0; + mmfiles.insert(this); + } + + void MemoryMappedFile::close() { + if ( view ) + UnmapViewOfFile(view); + view = 0; + if ( maphandle ) + CloseHandle(maphandle); + maphandle = 0; + if ( fd ) + CloseHandle(fd); + fd = 0; + } + + std::wstring toWideString(const char *s) { + std::basic_ostringstream<TCHAR> buf; + buf << s; + return buf.str(); } + unsigned mapped = 0; + + void* MemoryMappedFile::map(const char *filename, int length) { + updateLength( filename, length ); + std::wstring filenamew = toWideString(filename); + + fd = CreateFile( + filenamew.c_str(), GENERIC_WRITE | GENERIC_READ, FILE_SHARE_READ, + NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); + if ( fd == INVALID_HANDLE_VALUE ) { + cout << "CreateFile failed " << filename << endl; + return 0; + } + #if defined(_WIN32) - if ( mapped > 500000000 ) { - cout << "WARNING: too much mem mapped for win32" << endl; + if ( mapped > 500000000 ) { + cout << "WARNING: too much mem mapped for win32" << endl; // if( length > 50000000 ) // length = 50000000; - } - mapped += length; + } + mapped += length; #endif - maphandle = CreateFileMapping(fd, NULL, PAGE_READWRITE, 0, length, NULL); - if ( maphandle == NULL ) { - cout << "CreateFileMapping failed " << filename << endl; - return 0; - } + maphandle = CreateFileMapping(fd, NULL, PAGE_READWRITE, 0, length, NULL); + if ( maphandle == NULL ) { + cout << "CreateFileMapping failed " << filename << endl; + return 0; + } - view = MapViewOfFile(maphandle, FILE_MAP_ALL_ACCESS, 0, 0, 0); - if ( view == 0 ) { - cout << "MapViewOfFile failed " << filename << " errno:"; - cout << GetLastError(); - cout << endl; - } + view = MapViewOfFile(maphandle, FILE_MAP_ALL_ACCESS, 0, 0, 0); + if ( view == 0 ) { + cout << "MapViewOfFile failed " << filename << " errno:"; + cout << GetLastError(); + cout << endl; + } - return view; -} + return view; + } -void MemoryMappedFile::flush(bool) { -} + void MemoryMappedFile::flush(bool) { + } #else @@ -136,88 +136,88 @@ void MemoryMappedFile::flush(bool) { namespace mongo { -MemoryMappedFile::MemoryMappedFile() { - fd = 0; - maphandle = 0; - view = 0; - len = 0; - mmfiles.insert(this); -} + MemoryMappedFile::MemoryMappedFile() { + fd = 0; + maphandle = 0; + view = 0; + len = 0; + mmfiles.insert(this); + } -void MemoryMappedFile::close() { - if ( view ) - munmap(view, len); - view = 0; + void MemoryMappedFile::close() { + if ( view ) + munmap(view, len); + view = 0; - if ( fd ) - ::close(fd); - fd = 0; -} + if ( fd ) + ::close(fd); + fd = 0; + } #ifndef O_NOATIME #warning NO O_NOATIME #define O_NOATIME 0 #endif -void* MemoryMappedFile::map(const char *filename, int length) { - updateLength( filename, length ); - len = length; + void* MemoryMappedFile::map(const char *filename, int length) { + updateLength( filename, length ); + len = length; - fd = open(filename, O_CREAT | O_RDWR | O_NOATIME, S_IRUSR | S_IWUSR); - if ( !fd ) { - cout << "couldn't open " << filename << ' ' << errno << endl; - return 0; - } + fd = open(filename, O_CREAT | O_RDWR | O_NOATIME, S_IRUSR | S_IWUSR); + if ( !fd ) { + cout << "couldn't open " << filename << ' ' << errno << endl; + return 0; + } - /* make sure the file is the full desired length */ - off_t filelen = lseek(fd, 0, SEEK_END); - if ( filelen < length ) { + /* make sure the file is the full desired length */ + off_t filelen = lseek(fd, 0, SEEK_END); + if ( filelen < length ) { // log() << "map: file length=" << (unsigned) filelen << " want:" // << length // << endl; - if ( filelen != 0 ) { - problem() << "failure mapping new file " << filename << " length:" << length << endl; - return 0; - } - // Check for end of disk. - lseek(fd, length - 1, SEEK_SET); - write(fd, "", 1); - Logstream &l = log(); - l << "new datafile " << filename << " filling with zeroes..."; - l.flush(); - Timer t; - int z = 8192; - char buf[z]; - memset(buf, 0, z); - int left = length; - while ( 1 ) { - if ( left <= z ) { - write(fd, buf, left); - break; + if ( filelen != 0 ) { + problem() << "failure mapping new file " << filename << " length:" << length << endl; + return 0; } - write(fd, buf, z); - left -= z; + // Check for end of disk. + lseek(fd, length - 1, SEEK_SET); + write(fd, "", 1); + Logstream &l = log(); + l << "new datafile " << filename << " filling with zeroes..."; + l.flush(); + Timer t; + int z = 8192; + char buf[z]; + memset(buf, 0, z); + int left = length; + while ( 1 ) { + if ( left <= z ) { + write(fd, buf, left); + break; + } + write(fd, buf, z); + left -= z; + } + l << "done " << ((double)t.millis())/1000.0 << " secs" << endl; } - l << "done " << ((double)t.millis())/1000.0 << " secs" << endl; - } - view = mmap(NULL, length, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0); - if ( view == MAP_FAILED ) { - cout << " mmap() failed for " << filename << " len:" << length << " errno:" << errno << endl; - return 0; + view = mmap(NULL, length, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0); + if ( view == MAP_FAILED ) { + cout << " mmap() failed for " << filename << " len:" << length << " errno:" << errno << endl; + return 0; + } + return view; } - return view; -} -void MemoryMappedFile::flush(bool sync) { - if ( msync(view, len, sync ? MS_SYNC : MS_ASYNC) ) - problem() << "msync error " << errno << endl; -} + void MemoryMappedFile::flush(bool sync) { + if ( msync(view, len, sync ? MS_SYNC : MS_ASYNC) ) + problem() << "msync error " << errno << endl; + } #endif -void* MemoryMappedFile::map(const char *filename) { - return map( filename , file_size( filename ) ); // file_size is from boost -} + void* MemoryMappedFile::map(const char *filename) { + return map( filename , file_size( filename ) ); // file_size is from boost + } } // namespace mongo |