From 714ec2fdc8e9c8dc1c2cdf5486afdbc185beef14 Mon Sep 17 00:00:00 2001 From: Aaron Date: Tue, 9 Mar 2010 23:59:10 -0800 Subject: [PATCH] SERVER-695 don't destroy static global mutexes --- client/connpool.cpp | 4 +-- client/connpool.h | 4 +-- db/client.cpp | 6 ++--- db/client.h | 6 ++--- db/clientcursor.cpp | 16 +++++------ db/clientcursor.h | 8 +++--- db/db.cpp | 1 + db/dbcommands_admin.cpp | 6 ++--- db/dbwebserver.cpp | 2 +- db/index.cpp | 2 +- db/instance.cpp | 8 +++--- db/instance.h | 8 +++--- db/lasterror.cpp | 8 +++--- db/lasterror.h | 2 +- db/namespace.cpp | 4 +-- db/namespace.h | 6 ++--- db/nonce.cpp | 4 +-- db/queryoptimizer.cpp | 6 ++--- db/reccache.cpp | 10 +++---- db/reccache.h | 10 +++---- db/security.h | 8 +++--- db/stats/snapshots.cpp | 6 ++--- db/stats/snapshots.h | 2 +- db/stats/top.cpp | 8 +++--- db/stats/top.h | 10 +++---- mongo.xcodeproj/project.pbxproj | 28 +++++++++++++++++--- s/config.cpp | 4 +-- s/config.h | 2 +- s/request.cpp | 6 ++--- s/request.h | 2 +- scripting/engine.cpp | 6 ++--- scripting/engine_spidermonkey.cpp | 2 +- shell/dbshell.cpp | 1 + shell/utils.cpp | 8 +++--- util/assert_util.cpp | 4 +-- util/assert_util.h | 4 +-- util/background.cpp | 4 +-- util/background.h | 2 +- util/file_allocator.h | 16 +++++------ util/goodies.h | 44 +++++++++++++++++++++++++------ util/log.h | 4 +-- util/message.cpp | 11 ++++---- util/message_server_asio.cpp | 6 ++--- util/mmap.cpp | 10 +++---- util/queue.h | 10 +++---- util/sock.cpp | 4 +-- util/sock.h | 8 +++--- util/thread_pool.cpp | 8 +++--- util/thread_pool.h | 2 +- util/util.cpp | 6 +++-- 50 files changed, 204 insertions(+), 153 deletions(-) diff --git a/client/connpool.cpp b/client/connpool.cpp index 51304ecbe2d..eaaf4193d18 100644 --- a/client/connpool.cpp +++ b/client/connpool.cpp @@ -27,7 +27,7 @@ namespace mongo { DBConnectionPool pool; DBClientBase* DBConnectionPool::get(const string& host) { - boostlock L(poolMutex); + scoped_lock L(poolMutex); PoolForHost *&p = pools[host]; if ( p == 0 ) @@ -64,7 +64,7 @@ namespace mongo { } void DBConnectionPool::flush(){ - boostlock L(poolMutex); + scoped_lock L(poolMutex); for ( map::iterator i = pools.begin(); i != pools.end(); i++ ){ PoolForHost* p = i->second; diff --git a/client/connpool.h b/client/connpool.h index 34ed498c880..408799ab69c 100644 --- a/client/connpool.h +++ b/client/connpool.h @@ -51,7 +51,7 @@ namespace mongo { } */ class DBConnectionPool { - boost::mutex poolMutex; + mongo::mutex poolMutex; map pools; // servername -> pool list _hooks; @@ -63,7 +63,7 @@ namespace mongo { void release(const string& host, DBClientBase *c) { if ( c->isFailed() ) return; - boostlock L(poolMutex); + scoped_lock L(poolMutex); pools[host]->pool.push(c); } void addHook( DBConnectionHook * hook ); diff --git a/db/client.cpp b/db/client.cpp index a7d068453a4..8b1de92f768 100644 --- a/db/client.cpp +++ b/db/client.cpp @@ -29,7 +29,7 @@ namespace mongo { - boost::mutex Client::clientsMutex; + mongo::mutex Client::clientsMutex; set Client::clients; // always be in clientsMutex when manipulating this boost::thread_specific_ptr currentClient; @@ -40,7 +40,7 @@ namespace mongo { _god(0) { _curOp = new CurOp( this ); - boostlock bl(clientsMutex); + scoped_lock bl(clientsMutex); clients.insert(this); } @@ -59,7 +59,7 @@ namespace mongo { if ( inShutdown() ) return false; { - boostlock bl(clientsMutex); + scoped_lock bl(clientsMutex); clients.erase(this); } diff --git a/db/client.h b/db/client.h index 05cca1b1501..02bda6c0135 100644 --- a/db/client.h +++ b/db/client.h @@ -1,5 +1,5 @@ -// client.h - +// client.h + /** * Copyright (C) 2008 10gen Inc. * @@ -42,7 +42,7 @@ namespace mongo { class Client : boost::noncopyable { public: - static boost::mutex clientsMutex; + static mongo::mutex clientsMutex; static set clients; // always be in clientsMutex when manipulating this class GodScope { diff --git a/db/clientcursor.cpp b/db/clientcursor.cpp index 603138fec0e..be0bd2f232e 100644 --- a/db/clientcursor.cpp +++ b/db/clientcursor.cpp @@ -36,7 +36,7 @@ namespace mongo { boost::recursive_mutex ClientCursor::ccmutex; unsigned ClientCursor::byLocSize() { - recursive_boostlock lock(ccmutex); + recursive_scoped_lock lock(ccmutex); return byLoc.size(); } @@ -73,7 +73,7 @@ namespace mongo { assert( len > 0 && strchr(nsPrefix, '.') ); { - recursive_boostlock lock(ccmutex); + recursive_scoped_lock lock(ccmutex); for ( CCByLoc::iterator i = byLoc.begin(); i != byLoc.end(); ++i ) { ClientCursor *cc = i->second; @@ -88,7 +88,7 @@ namespace mongo { /* called every 4 seconds. millis is amount of idle time passed since the last call -- could be zero */ void ClientCursor::idleTimeReport(unsigned millis) { - recursive_boostlock lock(ccmutex); + recursive_scoped_lock lock(ccmutex); for ( CCByLoc::iterator i = byLoc.begin(); i != byLoc.end(); ) { CCByLoc::iterator j = i; i++; @@ -104,7 +104,7 @@ namespace mongo { note this is potentially slow */ void ClientCursor::informAboutToDeleteBucket(const DiskLoc& b) { - recursive_boostlock lock(ccmutex); + recursive_scoped_lock lock(ccmutex); RARELY if ( byLoc.size() > 70 ) { log() << "perf warning: byLoc.size=" << byLoc.size() << " in aboutToDeleteBucket\n"; } @@ -117,7 +117,7 @@ namespace mongo { /* must call this on a delete so we clean up the cursors. */ void ClientCursor::aboutToDelete(const DiskLoc& dl) { - recursive_boostlock lock(ccmutex); + recursive_scoped_lock lock(ccmutex); CCByLoc::iterator j = byLoc.lower_bound(dl); CCByLoc::iterator stop = byLoc.upper_bound(dl); @@ -170,7 +170,7 @@ namespace mongo { assert( pos != -2 ); { - recursive_boostlock lock(ccmutex); + recursive_scoped_lock lock(ccmutex); setLastLoc_inlock( DiskLoc() ); // removes us from bylocation multimap clientCursorsById.erase(cursorid); @@ -193,7 +193,7 @@ namespace mongo { return; } { - recursive_boostlock lock(ccmutex); + recursive_scoped_lock lock(ccmutex); setLastLoc_inlock(cl); c->noteLocation(); } @@ -269,7 +269,7 @@ namespace mongo { } virtual LockType locktype(){ return NONE; } bool run(const char *dbname, BSONObj& jsobj, string& errmsg, BSONObjBuilder& result, bool fromRepl ){ - recursive_boostlock lock(ClientCursor::ccmutex); + recursive_scoped_lock lock(ClientCursor::ccmutex); result.append("byLocation_size", unsigned( ClientCursor::byLoc.size() ) ); result.append("clientCursors_size", unsigned( ClientCursor::clientCursorsById.size() ) ); return true; diff --git a/db/clientcursor.h b/db/clientcursor.h index 04296c0236a..42919e3c574 100644 --- a/db/clientcursor.h +++ b/db/clientcursor.h @@ -83,7 +83,7 @@ namespace mongo { _c = 0; } Pointer(long long cursorid) { - recursive_boostlock lock(ccmutex); + recursive_scoped_lock lock(ccmutex); _c = ClientCursor::find_inlock(cursorid, true); if( _c ) { if( _c->_pinValue >= 100 ) { @@ -113,7 +113,7 @@ namespace mongo { { if( !okToTimeout ) noTimeout(); - recursive_boostlock lock(ccmutex); + recursive_scoped_lock lock(ccmutex); cursorid = allocCursorId_inlock(); clientCursorsById.insert( make_pair(cursorid, this) ); } @@ -155,7 +155,7 @@ namespace mongo { } public: static ClientCursor* find(CursorId id, bool warn = true) { - recursive_boostlock lock(ccmutex); + recursive_scoped_lock lock(ccmutex); ClientCursor *c = find_inlock(id, warn); // if this asserts, your code was not thread safe - you either need to set no timeout // for the cursor or keep a ClientCursor::Pointer in scope for it. @@ -164,7 +164,7 @@ namespace mongo { } static bool erase(CursorId id) { - recursive_boostlock lock(ccmutex); + recursive_scoped_lock lock(ccmutex); ClientCursor *cc = find_inlock(id); if ( cc ) { assert( cc->_pinValue < 100 ); // you can't still have an active ClientCursor::Pointer diff --git a/db/db.cpp b/db/db.cpp index 0089bc57e88..3dd1360d824 100644 --- a/db/db.cpp +++ b/db/db.cpp @@ -589,6 +589,7 @@ string arg_error_check(int argc, char* argv[]) { int main(int argc, char* argv[], char *envp[] ) { + static StaticObserver staticObserver; getcurns = ourgetns; po::options_description general_options("General options"); diff --git a/db/dbcommands_admin.cpp b/db/dbcommands_admin.cpp index c9c0dc97874..7811df96c58 100644 --- a/db/dbcommands_admin.cpp +++ b/db/dbcommands_admin.cpp @@ -274,7 +274,7 @@ namespace mongo { extern bool unlockRequested; extern unsigned lockedForWriting; - extern boost::mutex lockedForWritingMutex; + extern mongo::mutex lockedForWritingMutex; /* class UnlockCommand : public Command { @@ -308,7 +308,7 @@ namespace mongo { Client::initThread("fsyncjob"); Client& c = cc(); { - boostlock lk(lockedForWritingMutex); + scoped_lock lk(lockedForWritingMutex); lockedForWriting++; } readlock lk(""); @@ -323,7 +323,7 @@ namespace mongo { sleepmillis(20); } { - boostlock lk(lockedForWritingMutex); + scoped_lock lk(lockedForWritingMutex); lockedForWriting--; } c.shutdown(); diff --git a/db/dbwebserver.cpp b/db/dbwebserver.cpp index ad6ff0949d5..3060482d217 100644 --- a/db/dbwebserver.cpp +++ b/db/dbwebserver.cpp @@ -193,7 +193,7 @@ namespace mongo { << "\n"; { - boostlock bl(Client::clientsMutex); + scoped_lock bl(Client::clientsMutex); for( set::iterator i = Client::clients.begin(); i != Client::clients.end(); i++ ) { Client *c = *i; CurOp& co = *(c->curop()); diff --git a/db/index.cpp b/db/index.cpp index 777a9b0f951..c14cd79b16b 100644 --- a/db/index.cpp +++ b/db/index.cpp @@ -79,7 +79,7 @@ namespace mongo { } const IndexSpec& IndexDetails::getSpec() const { - boostlock lk(NamespaceDetailsTransient::_qcMutex); + scoped_lock lk(NamespaceDetailsTransient::_qcMutex); return NamespaceDetailsTransient::get_inlock( info.obj()["ns"].valuestr() ).getIndexSpec( this ); } diff --git a/db/instance.cpp b/db/instance.cpp index a386cad1c02..c63ef0abe38 100644 --- a/db/instance.cpp +++ b/db/instance.cpp @@ -78,7 +78,7 @@ namespace mongo { // see FSyncCommand: unsigned lockedForWriting; - boost::mutex lockedForWritingMutex; + mongo::mutex lockedForWritingMutex; bool unlockRequested = false; void inProgCmd( Message &m, DbResponse &dbresponse ) { @@ -95,7 +95,7 @@ namespace mongo { vector vals; { Client& me = cc(); - boostlock bl(Client::clientsMutex); + scoped_lock bl(Client::clientsMutex); for( set::iterator i = Client::clients.begin(); i != Client::clients.end(); i++ ) { Client *c = *i; if ( c == &me ) @@ -590,7 +590,7 @@ namespace mongo { void recCacheCloseAll(); - boost::mutex &exitMutex( *( new boost::mutex ) ); + mongo::mutex exitMutex; int numExitCalls = 0; void shutdown(); @@ -618,7 +618,7 @@ namespace mongo { void dbexit( ExitCode rc, const char *why) { Client * c = currentClient.get(); { - boostlock lk( exitMutex ); + scoped_lock lk( exitMutex ); if ( numExitCalls++ > 0 ) { if ( numExitCalls > 5 ){ // this means something horrible has happened diff --git a/db/instance.h b/db/instance.h index 2aa2e86a516..9e53f05723c 100644 --- a/db/instance.h +++ b/db/instance.h @@ -38,7 +38,7 @@ namespace mongo { 7 = log a few reads, and all writes. */ int level; - boost::mutex mutex; + mongo::mutex mutex; DiagLog() : f(0) , level(0) { } void init() { @@ -65,13 +65,13 @@ namespace mongo { } void flush() { if ( level ){ - boostlock lk(mutex); + scoped_lock lk(mutex); f->flush(); } } void write(char *data,int len) { if ( level & 1 ){ - boostlock lk(mutex); + scoped_lock lk(mutex); f->write(data,len); } } @@ -80,7 +80,7 @@ namespace mongo { bool log = (level & 4) == 0; OCCASIONALLY log = true; if ( log ){ - boostlock lk(mutex); + scoped_lock lk(mutex); f->write(data,len); } } diff --git a/db/lasterror.cpp b/db/lasterror.cpp index e8b1fcfe069..9fefcfa984c 100644 --- a/db/lasterror.cpp +++ b/db/lasterror.cpp @@ -28,7 +28,7 @@ namespace mongo { LastError LastError::noError; LastErrorHolder lastError; - boost::mutex LastErrorHolder::_idsmutex; + mongo::mutex LastErrorHolder::_idsmutex; void LastError::appendSelf( BSONObjBuilder &b ) { if ( !valid ) { @@ -75,7 +75,7 @@ namespace mongo { if ( id == 0 ) return _tl.get(); - boostlock lock(_idsmutex); + scoped_lock lock(_idsmutex); map::iterator i = _ids.find( id ); if ( i == _ids.end() ){ if ( ! create ) @@ -95,7 +95,7 @@ namespace mongo { } void LastErrorHolder::remove( int id ){ - boostlock lock(_idsmutex); + scoped_lock lock(_idsmutex); map::iterator i = _ids.find( id ); if ( i == _ids.end() ) return; @@ -121,7 +121,7 @@ namespace mongo { return; } - boostlock lock(_idsmutex); + scoped_lock lock(_idsmutex); Status & status = _ids[id]; status.time = time(0); status.lerr = le; diff --git a/db/lasterror.h b/db/lasterror.h index 510226fc4d3..78160eb5307 100644 --- a/db/lasterror.h +++ b/db/lasterror.h @@ -100,7 +100,7 @@ namespace mongo { time_t time; LastError *lerr; }; - static boost::mutex _idsmutex; + static mongo::mutex _idsmutex; map _ids; } lastError; diff --git a/db/namespace.cpp b/db/namespace.cpp index 10c1c97c01a..2dca516ff6a 100644 --- a/db/namespace.cpp +++ b/db/namespace.cpp @@ -609,8 +609,8 @@ namespace mongo { /* ------------------------------------------------------------------------- */ - boost::mutex NamespaceDetailsTransient::_qcMutex; - boost::mutex NamespaceDetailsTransient::_isMutex; + mongo::mutex NamespaceDetailsTransient::_qcMutex; + mongo::mutex NamespaceDetailsTransient::_isMutex; map< string, shared_ptr< NamespaceDetailsTransient > > NamespaceDetailsTransient::_map; typedef map< string, shared_ptr< NamespaceDetailsTransient > >::iterator ouriter; diff --git a/db/namespace.h b/db/namespace.h index 54030941efd..867f0e9094d 100644 --- a/db/namespace.h +++ b/db/namespace.h @@ -506,12 +506,12 @@ namespace mongo { /* IndexSpec caching */ private: map _indexSpecs; - static boost::mutex _isMutex; + static mongo::mutex _isMutex; public: const IndexSpec& getIndexSpec( const IndexDetails * details ){ IndexSpec& spec = _indexSpecs[details]; if ( ! spec._finishedInit ){ - boostlock lk(_isMutex); + scoped_lock lk(_isMutex); if ( ! spec._finishedInit ){ spec.reset( details ); assert( spec._finishedInit ); @@ -525,7 +525,7 @@ namespace mongo { int _qcWriteCount; map< QueryPattern, pair< BSONObj, long long > > _qcCache; public: - static boost::mutex _qcMutex; + static mongo::mutex _qcMutex; /* you must be in the qcMutex when calling this (and using the returned val): */ static NamespaceDetailsTransient& get_inlock(const char *ns) { return _get(ns); diff --git a/db/nonce.cpp b/db/nonce.cpp index 4c677bef342..d8db58dfa57 100644 --- a/db/nonce.cpp +++ b/db/nonce.cpp @@ -49,8 +49,8 @@ namespace mongo { } nonce Security::getNonce(){ - static boost::mutex m; - boostlock lk(m); + static mongo::mutex m; + scoped_lock lk(m); /* question/todo: /dev/random works on OS X. is it better to use that than random() / srandom()? diff --git a/db/queryoptimizer.cpp b/db/queryoptimizer.cpp index bfa0bcf2a25..2fdf98ec73c 100644 --- a/db/queryoptimizer.cpp +++ b/db/queryoptimizer.cpp @@ -220,7 +220,7 @@ namespace mongo { void QueryPlan::registerSelf( long long nScanned ) const { if ( fbs_.matchPossible() ) { - boostlock lk(NamespaceDetailsTransient::_qcMutex); + scoped_lock lk(NamespaceDetailsTransient::_qcMutex); NamespaceDetailsTransient::get_inlock( ns() ).registerIndexForPattern( fbs_.pattern( order_ ), indexKey(), nScanned ); } } @@ -340,7 +340,7 @@ namespace mongo { } if ( honorRecordedPlan_ ) { - boostlock lk(NamespaceDetailsTransient::_qcMutex); + scoped_lock lk(NamespaceDetailsTransient::_qcMutex); NamespaceDetailsTransient& nsd = NamespaceDetailsTransient::get_inlock( ns ); BSONObj bestIndex = nsd.indexForPattern( fbs_.pattern( order_ ) ); if ( !bestIndex.isEmpty() ) { @@ -419,7 +419,7 @@ namespace mongo { if ( res->complete() || plans_.size() > 1 ) return res; { - boostlock lk(NamespaceDetailsTransient::_qcMutex); + scoped_lock lk(NamespaceDetailsTransient::_qcMutex); NamespaceDetailsTransient::get_inlock( fbs_.ns() ).registerIndexForPattern( fbs_.pattern( order_ ), BSONObj(), 0 ); } init(); diff --git a/db/reccache.cpp b/db/reccache.cpp index da100814cdb..6e1f3de6fec 100644 --- a/db/reccache.cpp +++ b/db/reccache.cpp @@ -238,7 +238,7 @@ inline void RecCache::writeIfDirty(Node *n) { void RecCache::closeFiles(string dbname, string path) { assertInWriteLock(); - boostlock lk(rcmutex); + scoped_lock lk(rcmutex); // first we write all dirty pages. it is not easy to check which Nodes are for a particular // db, so we just write them all. @@ -259,7 +259,7 @@ void RecCache::closeFiles(string dbname, string path) { } void RecCache::closing() { - boostlock lk(rcmutex); + scoped_lock lk(rcmutex); (cout << "TEMP: recCacheCloseAll() writing dirty pages...\n").flush(); writeDirty( dirtyl.begin(), true ); for( unsigned i = 0; i < stores.size(); i++ ) { @@ -296,7 +296,7 @@ void RecCache::writeLazily() { int sleep = 0; int k; { - boostlock lk(rcmutex); + scoped_lock lk(rcmutex); Timer t; set::iterator i = dirtyl.end(); for( k = 0; k < 100; k++ ) { @@ -318,7 +318,7 @@ void RecCache::writeLazily() { } void RecCache::_ejectOld() { - boostlock lk(rcmutex); + scoped_lock lk(rcmutex); if( nnodes <= MAXNODES ) return; Node *n = oldest; @@ -384,7 +384,7 @@ void RecCache::closeStore(BasicRecStore *rs) { void RecCache::drop(const char *_ns) { // todo: test with a non clean shutdown file - boostlock lk(rcmutex); + scoped_lock lk(rcmutex); map::iterator it = storesByNsKey.find(mknskey(_ns)); string fname; diff --git a/db/reccache.h b/db/reccache.h index ec41030512e..d354587ae05 100644 --- a/db/reccache.h +++ b/db/reccache.h @@ -49,7 +49,7 @@ class RecCache { bool dirty; Node *older, *newer; // lru }; - boost::mutex &rcmutex; // mainly to coordinate with the lazy writer thread + mongo::mutex rcmutex; // mainly to coordinate with the lazy writer thread unsigned recsize; map m; // the cache Node *newest, *oldest; @@ -134,7 +134,7 @@ private: public: /* all public functions (except constructor) should use the mutex */ - RecCache(unsigned recsz) : rcmutex( *( new boost::mutex() ) ), recsize(recsz) { + RecCache(unsigned recsz) : recsize(recsz) { nnodes = 0; newest = oldest = 0; } @@ -156,7 +156,7 @@ public: */ void dirty(DiskLoc d) { assert( d.a() >= Base ); - boostlock lk(rcmutex); + scoped_lock lk(rcmutex); map::iterator i = m.find(d); if( i != m.end() ) { Node *n = i->second; @@ -171,7 +171,7 @@ public: assert( d.a() >= Base ); assert( len == recsize ); - boostlock lk(rcmutex); + scoped_lock lk(rcmutex); map::iterator i = m.find(d); if( i != m.end() ) { touch(i->second); @@ -188,7 +188,7 @@ public: void drop(const char *ns); DiskLoc insert(const char *ns, const void *obuf, int len, bool god) { - boostlock lk(rcmutex); + scoped_lock lk(rcmutex); BasicRecStore& rs = store(ns); fileofs o = rs.insert((const char *) obuf, len); assert( o % recsize == 0 ); diff --git a/db/security.h b/db/security.h index ca7489dd5af..261b1238b60 100644 --- a/db/security.h +++ b/db/security.h @@ -37,7 +37,7 @@ namespace mongo { }; class AuthenticationInfo : boost::noncopyable { - boost::mutex _lock; + mongo::mutex _lock; map m; // dbname -> auth static int warned; public: @@ -46,15 +46,15 @@ namespace mongo { ~AuthenticationInfo() { } void logout(const string& dbname ) { - boostlock lk(_lock); + scoped_lock lk(_lock); m.erase(dbname); } void authorize(const string& dbname ) { - boostlock lk(_lock); + scoped_lock lk(_lock); m[dbname].level = 2; } void authorizeReadOnly(const string& dbname) { - boostlock lk(_lock); + scoped_lock lk(_lock); m[dbname].level = 1; } bool isAuthorized(const string& dbname) { return _isAuthorized( dbname, 2 ); } diff --git a/db/stats/snapshots.cpp b/db/stats/snapshots.cpp index a5babcdfabd..7fc6bbdc0da 100644 --- a/db/stats/snapshots.cpp +++ b/db/stats/snapshots.cpp @@ -64,7 +64,7 @@ namespace mongo { } void Snapshots::add( SnapshotData * s ){ - boostlock lk(_lock); + scoped_lock lk(_lock); _loc = ( _loc + 1 ) % _n; _snapshots[_loc] = s; if ( _stored < _n ) @@ -72,7 +72,7 @@ namespace mongo { } auto_ptr Snapshots::computeDelta( int numBack ){ - boostlock lk(_lock); + scoped_lock lk(_lock); auto_ptr p; if ( numBack < numDeltas() ) p.reset( new SnapshotDelta( getPrev(numBack+1) , getPrev(numBack) ) ); @@ -87,7 +87,7 @@ namespace mongo { } void Snapshots::outputLockInfoHTML( stringstream& ss ){ - boostlock lk(_lock); + scoped_lock lk(_lock); ss << "\n"; ss << "\n"; diff --git a/db/stats/snapshots.h b/db/stats/snapshots.h index b87db8a161e..9fde41ac1ee 100644 --- a/db/stats/snapshots.h +++ b/db/stats/snapshots.h @@ -93,7 +93,7 @@ namespace mongo { void outputLockInfoHTML( stringstream& ss ); private: - boost::mutex _lock; + mongo::mutex _lock; int _n; SnapshotData** _snapshots; int _loc; diff --git a/db/stats/top.cpp b/db/stats/top.cpp index 50ec7a4a5b8..93d29ed3baf 100644 --- a/db/stats/top.cpp +++ b/db/stats/top.cpp @@ -46,7 +46,7 @@ namespace mongo { void Top::record( const string& ns , int op , int lockType , long long micros , bool command ){ - boostlock lk(_lock); + scoped_lock lk(_lock); CollectionData& coll = _usage[ns]; _record( coll , op , lockType , micros , command ); @@ -95,13 +95,13 @@ namespace mongo { } Top::UsageMap Top::cloneMap(){ - boostlock lk(_lock); + scoped_lock lk(_lock); UsageMap x = _usage; return x; } void Top::append( BSONObjBuilder& b ){ - boostlock lk( _lock ); + scoped_lock lk( _lock ); append( b , _usage ); } @@ -163,7 +163,7 @@ namespace mongo { TopOld::UsageMap TopOld::_snapshotB; TopOld::UsageMap &TopOld::_snapshot = TopOld::_snapshotA; TopOld::UsageMap &TopOld::_nextSnapshot = TopOld::_snapshotB; - boost::mutex TopOld::topMutex; + mongo::mutex TopOld::topMutex; } diff --git a/db/stats/top.h b/db/stats/top.h index f1927f4c8e0..eaf8a12cad5 100644 --- a/db/stats/top.h +++ b/db/stats/top.h @@ -81,7 +81,7 @@ namespace mongo { void _record( CollectionData& c , int op , int lockType , long long micros , bool command ); - boost::mutex _lock; + mongo::mutex _lock; CollectionData _global; UsageMap _usage; }; @@ -115,7 +115,7 @@ namespace mongo { D d = currentTime() - _currentStart; { - boostlock L(topMutex); + scoped_lock L(topMutex); recordUsage( _current, d ); } @@ -134,7 +134,7 @@ namespace mongo { }; static void usage( vector< Usage > &res ) { - boostlock L(topMutex); + scoped_lock L(topMutex); // Populate parent namespaces UsageMap snapshot; @@ -172,7 +172,7 @@ namespace mongo { } static void completeSnapshot() { - boostlock L(topMutex); + scoped_lock L(topMutex); if ( &_snapshot == &_snapshotA ) { _snapshot = _snapshotB; @@ -187,7 +187,7 @@ namespace mongo { } private: - static boost::mutex topMutex; + static mongo::mutex topMutex; static bool trivialNs( const char *ns ) { const char *ret = strrchr( ns, '.' ); return ret && ret[ 1 ] == '\0'; diff --git a/mongo.xcodeproj/project.pbxproj b/mongo.xcodeproj/project.pbxproj index db5a3c91cf7..bfb77c70b91 100644 --- a/mongo.xcodeproj/project.pbxproj +++ b/mongo.xcodeproj/project.pbxproj @@ -401,10 +401,8 @@ 936B895A0F4C899400934AF2 /* md5.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = md5.c; sourceTree = ""; }; 936B895B0F4C899400934AF2 /* md5.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = md5.h; sourceTree = ""; }; 936B895C0F4C899400934AF2 /* md5.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = md5.hpp; sourceTree = ""; }; - 936B895D0F4C899400934AF2 /* md5main.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = md5main.c; sourceTree = ""; }; 936B895E0F4C899400934AF2 /* message.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = message.cpp; sourceTree = ""; }; 936B895F0F4C899400934AF2 /* message.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = message.h; sourceTree = ""; }; - 936B89600F4C899400934AF2 /* top.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = top.h; sourceTree = ""; }; 937CACE90F27BF4900C57AA6 /* socktests.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = socktests.cpp; sourceTree = ""; }; 937D0E340F28CB070071FFA9 /* repltests.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = repltests.cpp; sourceTree = ""; }; 937D14AB0F2A225F0071FFA9 /* nonce.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = nonce.h; sourceTree = ""; }; @@ -500,6 +498,14 @@ 93C8E81C1145BCCA00F28017 /* regex7.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript; path = regex7.js; sourceTree = ""; }; 93C8E9DF1146D39700F28017 /* arrayfind2.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript; path = arrayfind2.js; sourceTree = ""; }; 93C8EB4D114721D000F28017 /* copydb2.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript; path = copydb2.js; sourceTree = ""; }; + 93C8ECE61147820C00F28017 /* counters.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = counters.cpp; sourceTree = ""; }; + 93C8ECE71147820C00F28017 /* counters.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = counters.h; sourceTree = ""; }; + 93C8ECE91147820C00F28017 /* snapshots.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = snapshots.cpp; sourceTree = ""; }; + 93C8ECEA1147820C00F28017 /* snapshots.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = snapshots.h; sourceTree = ""; }; + 93C8ECEC1147820C00F28017 /* top.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = top.cpp; sourceTree = ""; }; + 93C8ECED1147820C00F28017 /* top.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = top.h; sourceTree = ""; }; + 93C8ED001147824B00F28017 /* thread_pool.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = thread_pool.cpp; sourceTree = ""; }; + 93C8ED041147828F00F28017 /* index.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = index.cpp; sourceTree = ""; }; 93CC40C2113C407A00734218 /* insert1.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript; path = insert1.js; sourceTree = ""; }; 93CC441A113DE6BA00734218 /* indexg.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript; path = indexg.js; sourceTree = ""; }; 93CC4484113E602400734218 /* in3.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript; path = in3.js; sourceTree = ""; }; @@ -662,6 +668,8 @@ 9342238F0EF16DB400608550 /* db */ = { isa = PBXGroup; children = ( + 93C8ED041147828F00F28017 /* index.cpp */, + 93C8ECE51147820C00F28017 /* stats */, 9303D1AB10E1415C00294FAC /* client.cpp */, 9303D1AC10E1415C00294FAC /* client.h */, 9303D1AD10E1415C00294FAC /* cmdline.h */, @@ -1098,6 +1106,7 @@ 934DD87B0EFAD23B00459CC1 /* util */ = { isa = PBXGroup; children = ( + 93C8ED001147824B00F28017 /* thread_pool.cpp */, 934BEE8C10E050A500178102 /* allocator.h */, 934BEE8D10E050A500178102 /* assert_util.cpp */, 934BEE8E10E050A500178102 /* assert_util.h */, @@ -1126,10 +1135,8 @@ 936B895A0F4C899400934AF2 /* md5.c */, 936B895B0F4C899400934AF2 /* md5.h */, 936B895C0F4C899400934AF2 /* md5.hpp */, - 936B895D0F4C899400934AF2 /* md5main.c */, 936B895E0F4C899400934AF2 /* message.cpp */, 936B895F0F4C899400934AF2 /* message.h */, - 936B89600F4C899400934AF2 /* top.h */, 934DD87C0EFAD23B00459CC1 /* background.cpp */, 934DD87D0EFAD23B00459CC1 /* background.h */, 934DD87F0EFAD23B00459CC1 /* builder.h */, @@ -1222,6 +1229,19 @@ path = scripting; sourceTree = ""; }; + 93C8ECE51147820C00F28017 /* stats */ = { + isa = PBXGroup; + children = ( + 93C8ECE61147820C00F28017 /* counters.cpp */, + 93C8ECE71147820C00F28017 /* counters.h */, + 93C8ECE91147820C00F28017 /* snapshots.cpp */, + 93C8ECEA1147820C00F28017 /* snapshots.h */, + 93C8ECEC1147820C00F28017 /* top.cpp */, + 93C8ECED1147820C00F28017 /* top.h */, + ); + path = stats; + sourceTree = ""; + }; 93F0956F10E165E50053380C /* parallel */ = { isa = PBXGroup; children = ( diff --git a/s/config.cpp b/s/config.cpp index 0a4d74d5514..5b1405f3f84 100644 --- a/s/config.cpp +++ b/s/config.cpp @@ -297,7 +297,7 @@ namespace mongo { if ( database == "config" ) return &configServer; - boostlock l( _lock ); + scoped_lock l( _lock ); DBConfig*& cc = _databases[database]; if ( cc == 0 ){ @@ -333,7 +333,7 @@ namespace mongo { void Grid::removeDB( string database ){ uassert( 10186 , "removeDB expects db name" , database.find( '.' ) == string::npos ); - boostlock l( _lock ); + scoped_lock l( _lock ); _databases.erase( database ); } diff --git a/s/config.h b/s/config.h index 7c4b03d2f26..3b0dc4c1b50 100644 --- a/s/config.h +++ b/s/config.h @@ -151,7 +151,7 @@ namespace mongo { unsigned long long getNextOpTime() const; private: map _databases; - boost::mutex _lock; // TODO: change to r/w lock + mongo::mutex _lock; // TODO: change to r/w lock }; class ConfigServer : public DBConfig { diff --git a/s/request.cpp b/s/request.cpp index 8bebd64c044..a111680c020 100644 --- a/s/request.cpp +++ b/s/request.cpp @@ -118,7 +118,7 @@ namespace mongo { } ClientInfo::~ClientInfo(){ - boostlock lk( _clientsLock ); + scoped_lock lk( _clientsLock ); ClientCache::iterator i = _clients.find( _id ); if ( i != _clients.end() ){ _clients.erase( i ); @@ -157,7 +157,7 @@ namespace mongo { return info; } - boostlock lk( _clientsLock ); + scoped_lock lk( _clientsLock ); ClientCache::iterator i = _clients.find( clientId ); if ( i != _clients.end() ) return i->second; @@ -169,7 +169,7 @@ namespace mongo { } map ClientInfo::_clients; - boost::mutex ClientInfo::_clientsLock; + mongo::mutex ClientInfo::_clientsLock; boost::thread_specific_ptr ClientInfo::_tlInfo; } // namespace mongo diff --git a/s/request.h b/s/request.h index f87a70ec9b4..2c02724dea2 100644 --- a/s/request.h +++ b/s/request.h @@ -127,7 +127,7 @@ namespace mongo { set * _prev; int _lastAccess; - static boost::mutex _clientsLock; + static mongo::mutex _clientsLock; static ClientCache _clients; static boost::thread_specific_ptr _tlInfo; }; diff --git a/scripting/engine.cpp b/scripting/engine.cpp index 0dff413dbde..cc245b66a47 100644 --- a/scripting/engine.cpp +++ b/scripting/engine.cpp @@ -243,7 +243,7 @@ namespace mongo { } void done( const string& pool , Scope * s ){ - boostlock lk( _mutex ); + scoped_lock lk( _mutex ); list & l = _pools[pool]; if ( l.size() > 10 ){ delete s; @@ -255,7 +255,7 @@ namespace mongo { } Scope * get( const string& pool ){ - boostlock lk( _mutex ); + scoped_lock lk( _mutex ); list & l = _pools[pool]; if ( l.size() == 0 ) return 0; @@ -283,7 +283,7 @@ namespace mongo { private: PoolToScopes _pools; - boost::mutex _mutex; + mongo::mutex _mutex; int _magic; }; diff --git a/scripting/engine_spidermonkey.cpp b/scripting/engine_spidermonkey.cpp index 959ed856a0d..19e3e852817 100644 --- a/scripting/engine_spidermonkey.cpp +++ b/scripting/engine_spidermonkey.cpp @@ -46,7 +46,7 @@ namespace mongo { boost::thread_specific_ptr currentScope( dontDeleteScope ); boost::recursive_mutex &smmutex = *( new boost::recursive_mutex ); -#define smlock recursive_boostlock ___lk( smmutex ); +#define smlock recursive_scoped_lock ___lk( smmutex ); #define GETHOLDER(x,o) ((BSONHolder*)JS_GetPrivate( x , o )) diff --git a/shell/dbshell.cpp b/shell/dbshell.cpp index 47109f7a37c..5f1a82c0959 100644 --- a/shell/dbshell.cpp +++ b/shell/dbshell.cpp @@ -525,6 +525,7 @@ int _main(int argc, char* argv[]) { } int main(int argc, char* argv[]) { + static mongo::StaticObserver staticObserver; try { return _main( argc , argv ); } diff --git a/shell/utils.cpp b/shell/utils.cpp index 6ba70f12b70..b10c93d41c0 100644 --- a/shell/utils.cpp +++ b/shell/utils.cpp @@ -195,11 +195,11 @@ namespace mongo { map< pid_t, HANDLE > handles; #endif - boost::mutex &mongoProgramOutputMutex( *( new boost::mutex ) ); + mongo::mutex mongoProgramOutputMutex; stringstream mongoProgramOutput_; void writeMongoProgramOutputLine( int port, int pid, const char *line ) { - boost::mutex::scoped_lock lk( mongoProgramOutputMutex ); + mongo::mutex::scoped_lock lk( mongoProgramOutputMutex ); stringstream buf; if ( port > 0 ) buf << "m" << port << "| " << line; @@ -211,7 +211,7 @@ namespace mongo { // only returns last 100000 characters BSONObj RawMongoProgramOutput( const BSONObj &args ) { - boost::mutex::scoped_lock lk( mongoProgramOutputMutex ); + mongo::mutex::scoped_lock lk( mongoProgramOutputMutex ); string out = mongoProgramOutput_.str(); size_t len = out.length(); if ( len > 100000 ) @@ -220,7 +220,7 @@ namespace mongo { } BSONObj ClearRawMongoProgramOutput( const BSONObj &args ) { - boost::mutex::scoped_lock lk( mongoProgramOutputMutex ); + mongo::mutex::scoped_lock lk( mongoProgramOutputMutex ); mongoProgramOutput_.str( "" ); return undefined_; } diff --git a/util/assert_util.cpp b/util/assert_util.cpp index 6bc902e7635..8c8477a0976 100644 --- a/util/assert_util.cpp +++ b/util/assert_util.cpp @@ -105,13 +105,13 @@ namespace mongo { } - boost::mutex *Assertion::_mutex = new boost::mutex(); + mongo::mutex *Assertion::_mutex = new mongo::mutex(); string Assertion::toString() { if( _mutex == 0 ) return ""; - boostlock lk(*_mutex); + scoped_lock lk(*_mutex); if ( !isSet() ) return ""; diff --git a/util/assert_util.h b/util/assert_util.h index 81a6b0df20a..bae3a55cbf1 100644 --- a/util/assert_util.h +++ b/util/assert_util.h @@ -32,7 +32,7 @@ namespace mongo { when = 0; } private: - static boost::mutex *_mutex; + static mongo::mutex *_mutex; char msg[128]; char context[128]; const char *file; @@ -44,7 +44,7 @@ namespace mongo { /* asserted during global variable initialization */ return; } - boostlock lk(*_mutex); + scoped_lock lk(*_mutex); strncpy(msg, m, 127); strncpy(context, ctxt, 127); file = f; diff --git a/util/background.cpp b/util/background.cpp index ac3a48c8380..41253153247 100644 --- a/util/background.cpp +++ b/util/background.cpp @@ -22,7 +22,7 @@ namespace mongo { BackgroundJob *BackgroundJob::grab = 0; - boost::mutex &BackgroundJob::mutex = *( new boost::mutex ); + mongo::mutex BackgroundJob::mutex; /* static */ void BackgroundJob::thr() { @@ -38,7 +38,7 @@ namespace mongo { } BackgroundJob& BackgroundJob::go() { - boostlock bl(mutex); + scoped_lock bl(mutex); assert( grab == 0 ); grab = this; boost::thread t(thr); diff --git a/util/background.h b/util/background.h index 53c04887250..c95a5bd2c45 100644 --- a/util/background.h +++ b/util/background.h @@ -64,7 +64,7 @@ namespace mongo { private: static BackgroundJob *grab; - static boost::mutex &mutex; + static mongo::mutex mutex; static void thr(); volatile State state; }; diff --git a/util/file_allocator.h b/util/file_allocator.h index fa48d22c412..e819ba2321c 100644 --- a/util/file_allocator.h +++ b/util/file_allocator.h @@ -54,7 +54,7 @@ namespace mongo { on windows anyway as we don't have to pre-zero the file there. */ #if !defined(_WIN32) - boostlock lk( pendingMutex_ ); + scoped_lock lk( pendingMutex_ ); if ( failed_ ) return; long oldSize = prevSize( name ); @@ -71,7 +71,7 @@ namespace mongo { // updated to match existing file size. void allocateAsap( const string &name, long &size ) { #if !defined(_WIN32) - boostlock lk( pendingMutex_ ); + scoped_lock lk( pendingMutex_ ); long oldSize = prevSize( name ); if ( oldSize != -1 ) { size = oldSize; @@ -100,7 +100,7 @@ namespace mongo { #if !defined(_WIN32) if ( failed_ ) return; - boostlock lk( pendingMutex_ ); + scoped_lock lk( pendingMutex_ ); while( pending_.size() != 0 ) pendingUpdated_.wait( lk ); #endif @@ -130,7 +130,7 @@ namespace mongo { return false; } - mutable boost::mutex pendingMutex_; + mutable mongo::mutex pendingMutex_; mutable boost::condition pendingUpdated_; list< string > pending_; mutable map< string, long > pendingSize_; @@ -142,7 +142,7 @@ namespace mongo { void operator()() { while( 1 ) { { - boostlock lk( a_.pendingMutex_ ); + scoped_lock lk( a_.pendingMutex_ ); if ( a_.pending_.size() == 0 ) a_.pendingUpdated_.wait( lk ); } @@ -150,7 +150,7 @@ namespace mongo { string name; long size; { - boostlock lk( a_.pendingMutex_ ); + scoped_lock lk( a_.pendingMutex_ ); if ( a_.pending_.size() == 0 ) break; name = a_.pending_.front(); @@ -206,7 +206,7 @@ namespace mongo { BOOST_CHECK_EXCEPTION( boost::filesystem::remove( name ) ); } catch ( ... ) { } - boostlock lk( a_.pendingMutex_ ); + scoped_lock lk( a_.pendingMutex_ ); a_.failed_ = true; // not erasing from pending a_.pendingUpdated_.notify_all(); @@ -214,7 +214,7 @@ namespace mongo { } { - boostlock lk( a_.pendingMutex_ ); + scoped_lock lk( a_.pendingMutex_ ); a_.pendingSize_.erase( name ); a_.pending_.pop_front(); a_.pendingUpdated_.notify_all(); diff --git a/util/goodies.h b/util/goodies.h index 62ae2a64f1e..8bfe7a2b2f6 100644 --- a/util/goodies.h +++ b/util/goodies.h @@ -253,8 +253,36 @@ namespace mongo { return secs*1000000 + t; } using namespace boost; - typedef boost::mutex::scoped_lock boostlock; - typedef boost::recursive_mutex::scoped_lock recursive_boostlock; + + extern bool __destroyingStatics; + + // If you create a local static instance of this class, that instance will be destroyed + // before all global static objects are destroyed, so __destroyingStatics will be set + // to true before the global static variables are destroyed. + class StaticObserver : boost::noncopyable { + public: + ~StaticObserver() { __destroyingStatics = true; } + }; + + class mutex : boost::noncopyable { + public: + mutex() { new (_buf) boost::mutex(); } + ~mutex() { + if( !__destroyingStatics ) { + me().boost::mutex::~mutex(); + } + } + void lock() { me().lock(); } + void unlock() { me().unlock(); } + bool try_lock() { return me().try_lock(); } + typedef boost::unique_lock scoped_lock; + private: + boost::mutex &me() { return *( boost::mutex * )( _buf ); } + char _buf[ sizeof( boost::mutex ) ]; + }; + + typedef mongo::mutex::scoped_lock scoped_lock; + typedef boost::recursive_mutex::scoped_lock recursive_scoped_lock; // simple scoped timer class Timer { @@ -293,7 +321,7 @@ namespace mongo { class DebugMutex : boost::noncopyable { friend class lock; - boost::mutex m; + mongo::mutex m; int locked; public: DebugMutex() : locked(0); { } @@ -302,7 +330,7 @@ namespace mongo { */ -//typedef boostlock lock; +//typedef scoped_lock lock; inline bool startsWith(const char *str, const char *prefix) { size_t l = strlen(prefix); @@ -443,7 +471,7 @@ namespace mongo { } bool tryAcquire(){ - boostlock lk( _mutex ); + scoped_lock lk( _mutex ); if ( _num <= 0 ){ if ( _num < 0 ){ cerr << "DISASTER! in TicketHolder" << endl; @@ -455,12 +483,12 @@ namespace mongo { } void release(){ - boostlock lk( _mutex ); + scoped_lock lk( _mutex ); _num++; } void resize( int newSize ){ - boostlock lk( _mutex ); + scoped_lock lk( _mutex ); int used = _outof - _num; if ( used > newSize ){ cout << "ERROR: can't resize since we're using (" << used << ") more than newSize(" << newSize << ")" << endl; @@ -482,7 +510,7 @@ namespace mongo { private: int _outof; int _num; - boost::mutex _mutex; + mongo::mutex _mutex; }; class TicketHolderReleaser { diff --git a/util/log.h b/util/log.h index bac1156d0f4..668557a3e5b 100644 --- a/util/log.h +++ b/util/log.h @@ -118,7 +118,7 @@ namespace mongo { #define LOGIT { ss << x; return *this; } class Logstream : public Nullstream { - static boost::mutex &mutex; + static mongo::mutex mutex; static int doneSetup; stringstream ss; public: @@ -128,7 +128,7 @@ namespace mongo { void flush() { // this ensures things are sane if ( doneSetup == 1717 ){ - boostlock lk(mutex); + scoped_lock lk(mutex); cout << ss.str(); cout.flush(); } diff --git a/util/message.cpp b/util/message.cpp index b61e8944af1..2c3d0063f34 100644 --- a/util/message.cpp +++ b/util/message.cpp @@ -138,23 +138,22 @@ namespace mongo { class Ports { set& ports; - boost::mutex& m; + mongo::mutex m; public: // we "new" this so it is still be around when other automatic global vars // are being destructed during termination. - Ports() : ports( *(new set()) ), - m( *(new boost::mutex()) ) { } + Ports() : ports( *(new set()) ) {} void closeAll() { \ - boostlock bl(m); + scoped_lock bl(m); for ( set::iterator i = ports.begin(); i != ports.end(); i++ ) (*i)->shutdown(); } void insert(MessagingPort* p) { - boostlock bl(m); + scoped_lock bl(m); ports.insert(p); } void erase(MessagingPort* p) { - boostlock bl(m); + scoped_lock bl(m); ports.erase(p); } } ports; diff --git a/util/message_server_asio.cpp b/util/message_server_asio.cpp index f652a340147..7fca29abd98 100644 --- a/util/message_server_asio.cpp +++ b/util/message_server_asio.cpp @@ -68,7 +68,7 @@ namespace mongo { }; vector > thread_pool; - boost::mutex tp_mutex; // this is only needed if io_service::run() is called from multiple threads + mongo::mutex tp_mutex; // this is only needed if io_service::run() is called from multiple threads } class MessageServerSession : public boost::enable_shared_from_this , public AbstractMessagingPort { @@ -117,7 +117,7 @@ namespace mongo { void handleReadBody( const boost::system::error_code& error ){ if (!_myThread){ - boost::mutex::scoped_lock(tp_mutex); + mongo::mutex::scoped_lock(tp_mutex); if (!thread_pool.empty()){ _myThread = thread_pool.back(); thread_pool.pop_back(); @@ -148,7 +148,7 @@ namespace mongo { void handleWriteDone( const boost::system::error_code& error ){ { // return thread to pool after we have sent data to the client - boost::mutex::scoped_lock(tp_mutex); + mongo::mutex::scoped_lock(tp_mutex); assert(_myThread); thread_pool.push_back(_myThread); _myThread.reset(); diff --git a/util/mmap.cpp b/util/mmap.cpp index 536cf85e145..f6bbc735ec6 100644 --- a/util/mmap.cpp +++ b/util/mmap.cpp @@ -22,16 +22,16 @@ namespace mongo { set mmfiles; - boost::mutex mmmutex; + mongo::mutex mmmutex; MemoryMappedFile::~MemoryMappedFile() { close(); - boostlock lk( mmmutex ); + scoped_lock lk( mmmutex ); mmfiles.erase(this); } void MemoryMappedFile::created(){ - boostlock lk( mmmutex ); + scoped_lock lk( mmmutex ); mmfiles.insert(this); } @@ -55,7 +55,7 @@ namespace mongo { long long MemoryMappedFile::totalMappedLength(){ unsigned long long total = 0; - boostlock lk( mmmutex ); + scoped_lock lk( mmmutex ); for ( set::iterator i = mmfiles.begin(); i != mmfiles.end(); i++ ) total += (*i)->length(); @@ -65,7 +65,7 @@ namespace mongo { int MemoryMappedFile::flushAll( bool sync ){ int num = 0; - boostlock lk( mmmutex ); + scoped_lock lk( mmmutex ); for ( set::iterator i = mmfiles.begin(); i != mmfiles.end(); i++ ){ num++; MemoryMappedFile * mmf = *i; diff --git a/util/queue.h b/util/queue.h index 8f4fbaf7ac8..d291cb80c90 100644 --- a/util/queue.h +++ b/util/queue.h @@ -30,18 +30,18 @@ namespace mongo { template class BlockingQueue : boost::noncopyable { public: void push(T const& t){ - boostlock l( _lock ); + scoped_lock l( _lock ); _queue.push( t ); _condition.notify_one(); } bool empty() const { - boostlock l( _lock ); + scoped_lock l( _lock ); return _queue.empty(); } bool tryPop( T & t ){ - boostlock l( _lock ); + scoped_lock l( _lock ); if ( _queue.empty() ) return false; @@ -53,7 +53,7 @@ namespace mongo { T blockingPop(){ - boostlock l( _lock ); + scoped_lock l( _lock ); while( _queue.empty() ) _condition.wait( l ); @@ -65,7 +65,7 @@ namespace mongo { private: std::queue _queue; - mutable boost::mutex _lock; + mutable mongo::mutex _lock; boost::condition _condition; }; diff --git a/util/sock.cpp b/util/sock.cpp index 5172692a529..5beac683568 100644 --- a/util/sock.cpp +++ b/util/sock.cpp @@ -20,14 +20,14 @@ namespace mongo { - static boost::mutex sock_mutex; + static mongo::mutex sock_mutex; string hostbyname(const char *hostname) { static string unknown = "0.0.0.0"; if ( unknown == hostname ) return unknown; - boostlock lk(sock_mutex); + scoped_lock lk(sock_mutex); #if defined(_WIN32) if( inet_addr(hostname) != INADDR_NONE ) return hostname; diff --git a/util/sock.h b/util/sock.h index d1a941692cd..ee7a7aef48f 100644 --- a/util/sock.h +++ b/util/sock.h @@ -245,18 +245,18 @@ namespace mongo { } void add( int sock ){ - boostlock lk( _mutex ); + scoped_lock lk( _mutex ); _sockets->insert( sock ); } void remove( int sock ){ - boostlock lk( _mutex ); + scoped_lock lk( _mutex ); _sockets->erase( sock ); } void closeAll(){ set* s; { - boostlock lk( _mutex ); + scoped_lock lk( _mutex ); s = _sockets; _sockets = new set(); } @@ -272,7 +272,7 @@ namespace mongo { static ListeningSockets* get(); private: - boost::mutex _mutex; + mongo::mutex _mutex; set* _sockets; static ListeningSockets* _instance; }; diff --git a/util/thread_pool.cpp b/util/thread_pool.cpp index b95bc1d50cb..7c12b87bb65 100644 --- a/util/thread_pool.cpp +++ b/util/thread_pool.cpp @@ -77,7 +77,7 @@ ThreadPool::ThreadPool(int nThreads) : _tasksRemaining(0) , _nThreads(nThreads) { - boostlock lock(_mutex); + scoped_lock lock(_mutex); while (nThreads-- > 0){ Worker* worker = new Worker(*this); _freeWorkers.push_front(worker); @@ -99,14 +99,14 @@ ThreadPool::~ThreadPool(){ } void ThreadPool::join(){ - boostlock lock(_mutex); + scoped_lock lock(_mutex); while(_tasksRemaining){ _condition.wait(lock); } } void ThreadPool::schedule(Task task){ - boostlock lock(_mutex); + scoped_lock lock(_mutex); _tasksRemaining++; @@ -120,7 +120,7 @@ void ThreadPool::schedule(Task task){ // should only be called by a worker from the worker thread void ThreadPool::task_done(Worker* worker){ - boostlock lock(_mutex); + scoped_lock lock(_mutex); if (!_tasks.empty()){ worker->set_task(_tasks.front()); diff --git a/util/thread_pool.h b/util/thread_pool.h index 91c2969d559..d891d7daac2 100644 --- a/util/thread_pool.h +++ b/util/thread_pool.h @@ -62,7 +62,7 @@ namespace threadpool { int tasks_remaining() { return _tasksRemaining; } private: - boost::mutex _mutex; + mongo::mutex _mutex; boost::condition _condition; list _freeWorkers; //used as LIFO stack (always front) diff --git a/util/util.cpp b/util/util.cpp index c96bef62445..8ae00f3e961 100644 --- a/util/util.cpp +++ b/util/util.cpp @@ -34,7 +34,7 @@ namespace mongo { const char * (*getcurns)() = default_getcurns; int logLevel = 0; - boost::mutex &Logstream::mutex = *( new boost::mutex ); + mongo::mutex Logstream::mutex; int Logstream::doneSetup = Logstream::magicNumber(); bool goingAway = false; @@ -137,5 +137,7 @@ namespace mongo { s << (string)o; return s; } - + + bool __destroyingStatics = false; + } // namespace mongo
elapsed(ms)% write locked