0
0
mirror of https://github.com/mongodb/mongo.git synced 2024-11-30 00:56:44 +01:00
mongodb/util/mmap.cpp

69 lines
2.1 KiB
C++
Raw Normal View History

2008-06-06 15:43:15 +02:00
// mmap.cpp
/**
* Copyright (C) 2008 10gen Inc.
2008-12-29 02:28:49 +01:00
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License, version 3,
* as published by the Free Software Foundation.
2008-12-29 02:28:49 +01:00
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
2008-12-29 02:28:49 +01:00
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
2008-06-06 15:43:15 +02:00
#include "stdafx.h"
#include "mmap.h"
2009-01-14 23:09:51 +01:00
namespace mongo {
set<MemoryMappedFile*> mmfiles;
MemoryMappedFile::~MemoryMappedFile() {
close();
mmfiles.erase(this);
}
void MemoryMappedFile::created(){
mmfiles.insert(this);
}
/*static*/
int closingAllFiles = 0;
void MemoryMappedFile::closeAllFiles( stringstream &message ) {
if ( closingAllFiles ) {
message << "warning closingAllFiles=" << closingAllFiles << endl;
return;
}
++closingAllFiles;
ProgressMeter pm( mmfiles.size() , 2 , 1 );
for ( set<MemoryMappedFile*>::iterator i = mmfiles.begin(); i != mmfiles.end(); i++ ){
(*i)->close();
pm.hit();
}
message << " closeAllFiles() finished" << endl;
--closingAllFiles;
}
2009-07-09 22:56:34 +02:00
void MemoryMappedFile::updateLength( const char *filename, long &length ) {
if ( !boost::filesystem::exists( filename ) )
return;
// make sure we map full length if preexisting file.
2009-01-19 01:13:12 +01:00
boost::uintmax_t l = boost::filesystem::file_size( filename );
assert( l <= 0x7fffffff );
2009-08-13 18:28:30 +02:00
length = (long) l;
2008-12-29 02:28:49 +01:00
}
void* MemoryMappedFile::map(const char *filename) {
2009-01-19 01:13:12 +01:00
boost::uintmax_t l = boost::filesystem::file_size( filename );
assert( l <= 0x7fffffff );
2009-07-09 22:56:34 +02:00
long i = (long)l;
return map( filename , i );
}
2009-01-14 23:09:51 +01:00
} // namespace mongo