summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEliot Horowitz <eliot@10gen.com>2009-11-30 10:52:02 -0500
committerEliot Horowitz <eliot@10gen.com>2009-11-30 10:52:02 -0500
commitd7280381dfbc77488186c063012b55e6f809ce8f (patch)
tree72bf7168371d92f0bd3f402c94b8f586adf5cdfa
parent57b0c56f527e6e4fd5d6c946d486a804d64cf3c9 (diff)
downloadmongo-d7280381dfbc77488186c063012b55e6f809ce8f.tar.gz
some threadsafety on memory mapped file static methods
-rw-r--r--util/mmap.cpp11
-rw-r--r--util/mmap_posix.cpp2
2 files changed, 12 insertions, 1 deletions
diff --git a/util/mmap.cpp b/util/mmap.cpp
index 11237a74c2f..f3103d0c684 100644
--- a/util/mmap.cpp
+++ b/util/mmap.cpp
@@ -21,13 +21,16 @@
namespace mongo {
set<MemoryMappedFile*> mmfiles;
+ boost::mutex mmmutex;
MemoryMappedFile::~MemoryMappedFile() {
close();
+ boostlock lk( mmmutex );
mmfiles.erase(this);
}
void MemoryMappedFile::created(){
+ boostlock lk( mmmutex );
mmfiles.insert(this);
}
@@ -51,6 +54,7 @@ namespace mongo {
long long MemoryMappedFile::totalMappedLength(){
unsigned long long total = 0;
+ boostlock lk( mmmutex );
for ( set<MemoryMappedFile*>::iterator i = mmfiles.begin(); i != mmfiles.end(); i++ )
total += (*i)->length();
@@ -59,9 +63,14 @@ namespace mongo {
int MemoryMappedFile::flushAll( bool sync ){
int num = 0;
+
+ boostlock lk( mmmutex );
for ( set<MemoryMappedFile*>::iterator i = mmfiles.begin(); i != mmfiles.end(); i++ ){
num++;
- (*i)->flush( sync );
+ MemoryMappedFile * mmf = *i;
+ if ( ! mmf )
+ continue;
+ mmf->flush( sync );
}
return num;
}
diff --git a/util/mmap_posix.cpp b/util/mmap_posix.cpp
index e4487cd1403..4b6d0f5c3f9 100644
--- a/util/mmap_posix.cpp
+++ b/util/mmap_posix.cpp
@@ -77,6 +77,8 @@ namespace mongo {
}
void MemoryMappedFile::flush(bool sync) {
+ if ( view == 0 || fd == 0 )
+ return;
if ( msync(view, len, sync ? MS_SYNC : MS_ASYNC) )
problem() << "msync error " << errno << endl;
}