diff options
author | Eliot Horowitz <eliot@10gen.com> | 2009-11-30 10:52:02 -0500 |
---|---|---|
committer | Eliot Horowitz <eliot@10gen.com> | 2009-11-30 10:52:02 -0500 |
commit | d7280381dfbc77488186c063012b55e6f809ce8f (patch) | |
tree | 72bf7168371d92f0bd3f402c94b8f586adf5cdfa /util/mmap.cpp | |
parent | 57b0c56f527e6e4fd5d6c946d486a804d64cf3c9 (diff) | |
download | mongo-d7280381dfbc77488186c063012b55e6f809ce8f.tar.gz |
some threadsafety on memory mapped file static methods
Diffstat (limited to 'util/mmap.cpp')
-rw-r--r-- | util/mmap.cpp | 11 |
1 files changed, 10 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; } |