diff options
author | Aaron <aaron@10gen.com> | 2010-03-10 00:39:26 -0800 |
---|---|---|
committer | Aaron <aaron@10gen.com> | 2010-03-10 00:39:26 -0800 |
commit | eb7cde3e751b02eae055a922af8985fe52c807fa (patch) | |
tree | 2e233ffffb850b8cf7d3e6f01bf977fa24146457 | |
parent | 26b6ffe30a81e80cafd427ca0c78e072ff918f23 (diff) | |
download | mongo-eb7cde3e751b02eae055a922af8985fe52c807fa.tar.gz |
Revert "SERVER-695 don't destroy static global mutexes"
This reverts commit 714ec2fdc8e9c8dc1c2cdf5486afdbc185beef14.
50 files changed, 153 insertions, 204 deletions
diff --git a/client/connpool.cpp b/client/connpool.cpp index eaaf4193d18..51304ecbe2d 100644 --- a/client/connpool.cpp +++ b/client/connpool.cpp @@ -27,7 +27,7 @@ namespace mongo { DBConnectionPool pool; DBClientBase* DBConnectionPool::get(const string& host) { - scoped_lock L(poolMutex); + boostlock L(poolMutex); PoolForHost *&p = pools[host]; if ( p == 0 ) @@ -64,7 +64,7 @@ namespace mongo { } void DBConnectionPool::flush(){ - scoped_lock L(poolMutex); + boostlock L(poolMutex); for ( map<string,PoolForHost*>::iterator i = pools.begin(); i != pools.end(); i++ ){ PoolForHost* p = i->second; diff --git a/client/connpool.h b/client/connpool.h index 408799ab69c..34ed498c880 100644 --- a/client/connpool.h +++ b/client/connpool.h @@ -51,7 +51,7 @@ namespace mongo { } */ class DBConnectionPool { - mongo::mutex poolMutex; + boost::mutex poolMutex; map<string,PoolForHost*> pools; // servername -> pool list<DBConnectionHook*> _hooks; @@ -63,7 +63,7 @@ namespace mongo { void release(const string& host, DBClientBase *c) { if ( c->isFailed() ) return; - scoped_lock L(poolMutex); + boostlock L(poolMutex); pools[host]->pool.push(c); } void addHook( DBConnectionHook * hook ); diff --git a/db/client.cpp b/db/client.cpp index 8b1de92f768..a7d068453a4 100644 --- a/db/client.cpp +++ b/db/client.cpp @@ -29,7 +29,7 @@ namespace mongo { - mongo::mutex Client::clientsMutex; + boost::mutex Client::clientsMutex; set<Client*> Client::clients; // always be in clientsMutex when manipulating this boost::thread_specific_ptr<Client> currentClient; @@ -40,7 +40,7 @@ namespace mongo { _god(0) { _curOp = new CurOp( this ); - scoped_lock bl(clientsMutex); + boostlock bl(clientsMutex); clients.insert(this); } @@ -59,7 +59,7 @@ namespace mongo { if ( inShutdown() ) return false; { - scoped_lock bl(clientsMutex); + boostlock bl(clientsMutex); clients.erase(this); } diff --git a/db/client.h b/db/client.h index 02bda6c0135..05cca1b1501 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 mongo::mutex clientsMutex; + static boost::mutex clientsMutex; static set<Client*> clients; // always be in clientsMutex when manipulating this class GodScope { diff --git a/db/clientcursor.cpp b/db/clientcursor.cpp index be0bd2f232e..603138fec0e 100644 --- a/db/clientcursor.cpp +++ b/db/clientcursor.cpp @@ -36,7 +36,7 @@ namespace mongo { boost::recursive_mutex ClientCursor::ccmutex; unsigned ClientCursor::byLocSize() { - recursive_scoped_lock lock(ccmutex); + recursive_boostlock lock(ccmutex); return byLoc.size(); } @@ -73,7 +73,7 @@ namespace mongo { assert( len > 0 && strchr(nsPrefix, '.') ); { - recursive_scoped_lock lock(ccmutex); + recursive_boostlock 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_scoped_lock lock(ccmutex); + recursive_boostlock 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_scoped_lock lock(ccmutex); + recursive_boostlock 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_scoped_lock lock(ccmutex); + recursive_boostlock 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_scoped_lock lock(ccmutex); + recursive_boostlock lock(ccmutex); setLastLoc_inlock( DiskLoc() ); // removes us from bylocation multimap clientCursorsById.erase(cursorid); @@ -193,7 +193,7 @@ namespace mongo { return; } { - recursive_scoped_lock lock(ccmutex); + recursive_boostlock 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_scoped_lock lock(ClientCursor::ccmutex); + recursive_boostlock 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 42919e3c574..04296c0236a 100644 --- a/db/clientcursor.h +++ b/db/clientcursor.h @@ -83,7 +83,7 @@ namespace mongo { _c = 0; } Pointer(long long cursorid) { - recursive_scoped_lock lock(ccmutex); + recursive_boostlock lock(ccmutex); _c = ClientCursor::find_inlock(cursorid, true); if( _c ) { if( _c->_pinValue >= 100 ) { @@ -113,7 +113,7 @@ namespace mongo { { if( !okToTimeout ) noTimeout(); - recursive_scoped_lock lock(ccmutex); + recursive_boostlock 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_scoped_lock lock(ccmutex); + recursive_boostlock 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_scoped_lock lock(ccmutex); + recursive_boostlock 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 b0b4b44c94b..bc9372c33bb 100644 --- a/db/db.cpp +++ b/db/db.cpp @@ -589,7 +589,6 @@ 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 7811df96c58..c9c0dc97874 100644 --- a/db/dbcommands_admin.cpp +++ b/db/dbcommands_admin.cpp @@ -274,7 +274,7 @@ namespace mongo { extern bool unlockRequested; extern unsigned lockedForWriting; - extern mongo::mutex lockedForWritingMutex; + extern boost::mutex lockedForWritingMutex; /* class UnlockCommand : public Command { @@ -308,7 +308,7 @@ namespace mongo { Client::initThread("fsyncjob"); Client& c = cc(); { - scoped_lock lk(lockedForWritingMutex); + boostlock lk(lockedForWritingMutex); lockedForWriting++; } readlock lk(""); @@ -323,7 +323,7 @@ namespace mongo { sleepmillis(20); } { - scoped_lock lk(lockedForWritingMutex); + boostlock lk(lockedForWritingMutex); lockedForWriting--; } c.shutdown(); diff --git a/db/dbwebserver.cpp b/db/dbwebserver.cpp index 3060482d217..ad6ff0949d5 100644 --- a/db/dbwebserver.cpp +++ b/db/dbwebserver.cpp @@ -193,7 +193,7 @@ namespace mongo { << "</tr>\n"; { - scoped_lock bl(Client::clientsMutex); + boostlock bl(Client::clientsMutex); for( set<Client*>::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 c14cd79b16b..777a9b0f951 100644 --- a/db/index.cpp +++ b/db/index.cpp @@ -79,7 +79,7 @@ namespace mongo { } const IndexSpec& IndexDetails::getSpec() const { - scoped_lock lk(NamespaceDetailsTransient::_qcMutex); + boostlock lk(NamespaceDetailsTransient::_qcMutex); return NamespaceDetailsTransient::get_inlock( info.obj()["ns"].valuestr() ).getIndexSpec( this ); } diff --git a/db/instance.cpp b/db/instance.cpp index c63ef0abe38..a386cad1c02 100644 --- a/db/instance.cpp +++ b/db/instance.cpp @@ -78,7 +78,7 @@ namespace mongo { // see FSyncCommand: unsigned lockedForWriting; - mongo::mutex lockedForWritingMutex; + boost::mutex lockedForWritingMutex; bool unlockRequested = false; void inProgCmd( Message &m, DbResponse &dbresponse ) { @@ -95,7 +95,7 @@ namespace mongo { vector<BSONObj> vals; { Client& me = cc(); - scoped_lock bl(Client::clientsMutex); + boostlock bl(Client::clientsMutex); for( set<Client*>::iterator i = Client::clients.begin(); i != Client::clients.end(); i++ ) { Client *c = *i; if ( c == &me ) @@ -590,7 +590,7 @@ namespace mongo { void recCacheCloseAll(); - mongo::mutex exitMutex; + boost::mutex &exitMutex( *( new boost::mutex ) ); int numExitCalls = 0; void shutdown(); @@ -618,7 +618,7 @@ namespace mongo { void dbexit( ExitCode rc, const char *why) { Client * c = currentClient.get(); { - scoped_lock lk( exitMutex ); + boostlock 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 9e53f05723c..2aa2e86a516 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; - mongo::mutex mutex; + boost::mutex mutex; DiagLog() : f(0) , level(0) { } void init() { @@ -65,13 +65,13 @@ namespace mongo { } void flush() { if ( level ){ - scoped_lock lk(mutex); + boostlock lk(mutex); f->flush(); } } void write(char *data,int len) { if ( level & 1 ){ - scoped_lock lk(mutex); + boostlock lk(mutex); f->write(data,len); } } @@ -80,7 +80,7 @@ namespace mongo { bool log = (level & 4) == 0; OCCASIONALLY log = true; if ( log ){ - scoped_lock lk(mutex); + boostlock lk(mutex); f->write(data,len); } } diff --git a/db/lasterror.cpp b/db/lasterror.cpp index 9fefcfa984c..e8b1fcfe069 100644 --- a/db/lasterror.cpp +++ b/db/lasterror.cpp @@ -28,7 +28,7 @@ namespace mongo { LastError LastError::noError; LastErrorHolder lastError; - mongo::mutex LastErrorHolder::_idsmutex; + boost::mutex LastErrorHolder::_idsmutex; void LastError::appendSelf( BSONObjBuilder &b ) { if ( !valid ) { @@ -75,7 +75,7 @@ namespace mongo { if ( id == 0 ) return _tl.get(); - scoped_lock lock(_idsmutex); + boostlock lock(_idsmutex); map<int,Status>::iterator i = _ids.find( id ); if ( i == _ids.end() ){ if ( ! create ) @@ -95,7 +95,7 @@ namespace mongo { } void LastErrorHolder::remove( int id ){ - scoped_lock lock(_idsmutex); + boostlock lock(_idsmutex); map<int,Status>::iterator i = _ids.find( id ); if ( i == _ids.end() ) return; @@ -121,7 +121,7 @@ namespace mongo { return; } - scoped_lock lock(_idsmutex); + boostlock lock(_idsmutex); Status & status = _ids[id]; status.time = time(0); status.lerr = le; diff --git a/db/lasterror.h b/db/lasterror.h index 78160eb5307..510226fc4d3 100644 --- a/db/lasterror.h +++ b/db/lasterror.h @@ -100,7 +100,7 @@ namespace mongo { time_t time; LastError *lerr; }; - static mongo::mutex _idsmutex; + static boost::mutex _idsmutex; map<int,Status> _ids; } lastError; diff --git a/db/namespace.cpp b/db/namespace.cpp index 2dca516ff6a..10c1c97c01a 100644 --- a/db/namespace.cpp +++ b/db/namespace.cpp @@ -609,8 +609,8 @@ namespace mongo { /* ------------------------------------------------------------------------- */ - mongo::mutex NamespaceDetailsTransient::_qcMutex; - mongo::mutex NamespaceDetailsTransient::_isMutex; + boost::mutex NamespaceDetailsTransient::_qcMutex; + boost::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 867f0e9094d..54030941efd 100644 --- a/db/namespace.h +++ b/db/namespace.h @@ -506,12 +506,12 @@ namespace mongo { /* IndexSpec caching */ private: map<const IndexDetails*,IndexSpec> _indexSpecs; - static mongo::mutex _isMutex; + static boost::mutex _isMutex; public: const IndexSpec& getIndexSpec( const IndexDetails * details ){ IndexSpec& spec = _indexSpecs[details]; if ( ! spec._finishedInit ){ - scoped_lock lk(_isMutex); + boostlock 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 mongo::mutex _qcMutex; + static boost::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 d8db58dfa57..4c677bef342 100644 --- a/db/nonce.cpp +++ b/db/nonce.cpp @@ -49,8 +49,8 @@ namespace mongo { } nonce Security::getNonce(){ - static mongo::mutex m; - scoped_lock lk(m); + static boost::mutex m; + boostlock 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 2fdf98ec73c..bfa0bcf2a25 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() ) { - scoped_lock lk(NamespaceDetailsTransient::_qcMutex); + boostlock lk(NamespaceDetailsTransient::_qcMutex); NamespaceDetailsTransient::get_inlock( ns() ).registerIndexForPattern( fbs_.pattern( order_ ), indexKey(), nScanned ); } } @@ -340,7 +340,7 @@ namespace mongo { } if ( honorRecordedPlan_ ) { - scoped_lock lk(NamespaceDetailsTransient::_qcMutex); + boostlock 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; { - scoped_lock lk(NamespaceDetailsTransient::_qcMutex); + boostlock 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 6e1f3de6fec..da100814cdb 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(); - scoped_lock lk(rcmutex); + boostlock 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() { - scoped_lock lk(rcmutex); + boostlock 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; { - scoped_lock lk(rcmutex); + boostlock lk(rcmutex); Timer t; set<DiskLoc>::iterator i = dirtyl.end(); for( k = 0; k < 100; k++ ) { @@ -318,7 +318,7 @@ void RecCache::writeLazily() { } void RecCache::_ejectOld() { - scoped_lock lk(rcmutex); + boostlock 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 - scoped_lock lk(rcmutex); + boostlock lk(rcmutex); map<string, BasicRecStore*>::iterator it = storesByNsKey.find(mknskey(_ns)); string fname; diff --git a/db/reccache.h b/db/reccache.h index d354587ae05..ec41030512e 100644 --- a/db/reccache.h +++ b/db/reccache.h @@ -49,7 +49,7 @@ class RecCache { bool dirty; Node *older, *newer; // lru }; - mongo::mutex rcmutex; // mainly to coordinate with the lazy writer thread + boost::mutex &rcmutex; // mainly to coordinate with the lazy writer thread unsigned recsize; map<DiskLoc, Node*> m; // the cache Node *newest, *oldest; @@ -134,7 +134,7 @@ private: public: /* all public functions (except constructor) should use the mutex */ - RecCache(unsigned recsz) : recsize(recsz) { + RecCache(unsigned recsz) : rcmutex( *( new boost::mutex() ) ), recsize(recsz) { nnodes = 0; newest = oldest = 0; } @@ -156,7 +156,7 @@ public: */ void dirty(DiskLoc d) { assert( d.a() >= Base ); - scoped_lock lk(rcmutex); + boostlock lk(rcmutex); map<DiskLoc, Node*>::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 ); - scoped_lock lk(rcmutex); + boostlock lk(rcmutex); map<DiskLoc, Node*>::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) { - scoped_lock lk(rcmutex); + boostlock 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 261b1238b60..ca7489dd5af 100644 --- a/db/security.h +++ b/db/security.h @@ -37,7 +37,7 @@ namespace mongo { }; class AuthenticationInfo : boost::noncopyable { - mongo::mutex _lock; + boost::mutex _lock; map<string, Auth> m; // dbname -> auth static int warned; public: @@ -46,15 +46,15 @@ namespace mongo { ~AuthenticationInfo() { } void logout(const string& dbname ) { - scoped_lock lk(_lock); + boostlock lk(_lock); m.erase(dbname); } void authorize(const string& dbname ) { - scoped_lock lk(_lock); + boostlock lk(_lock); m[dbname].level = 2; } void authorizeReadOnly(const string& dbname) { - scoped_lock lk(_lock); + boostlock 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 7fc6bbdc0da..a5babcdfabd 100644 --- a/db/stats/snapshots.cpp +++ b/db/stats/snapshots.cpp @@ -64,7 +64,7 @@ namespace mongo { } void Snapshots::add( SnapshotData * s ){ - scoped_lock lk(_lock); + boostlock lk(_lock); _loc = ( _loc + 1 ) % _n; _snapshots[_loc] = s; if ( _stored < _n ) @@ -72,7 +72,7 @@ namespace mongo { } auto_ptr<SnapshotDelta> Snapshots::computeDelta( int numBack ){ - scoped_lock lk(_lock); + boostlock lk(_lock); auto_ptr<SnapshotDelta> p; if ( numBack < numDeltas() ) p.reset( new SnapshotDelta( getPrev(numBack+1) , getPrev(numBack) ) ); @@ -87,7 +87,7 @@ namespace mongo { } void Snapshots::outputLockInfoHTML( stringstream& ss ){ - scoped_lock lk(_lock); + boostlock lk(_lock); ss << "\n<table>"; ss << "<tr><th>elapsed(ms)</th><th>% write locked</th></tr>\n"; diff --git a/db/stats/snapshots.h b/db/stats/snapshots.h index 9fde41ac1ee..b87db8a161e 100644 --- a/db/stats/snapshots.h +++ b/db/stats/snapshots.h @@ -93,7 +93,7 @@ namespace mongo { void outputLockInfoHTML( stringstream& ss ); private: - mongo::mutex _lock; + boost::mutex _lock; int _n; SnapshotData** _snapshots; int _loc; diff --git a/db/stats/top.cpp b/db/stats/top.cpp index 93d29ed3baf..50ec7a4a5b8 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 ){ - scoped_lock lk(_lock); + boostlock lk(_lock); CollectionData& coll = _usage[ns]; _record( coll , op , lockType , micros , command ); @@ -95,13 +95,13 @@ namespace mongo { } Top::UsageMap Top::cloneMap(){ - scoped_lock lk(_lock); + boostlock lk(_lock); UsageMap x = _usage; return x; } void Top::append( BSONObjBuilder& b ){ - scoped_lock lk( _lock ); + boostlock 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; - mongo::mutex TopOld::topMutex; + boost::mutex TopOld::topMutex; } diff --git a/db/stats/top.h b/db/stats/top.h index eaf8a12cad5..f1927f4c8e0 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 ); - mongo::mutex _lock; + boost::mutex _lock; CollectionData _global; UsageMap _usage; }; @@ -115,7 +115,7 @@ namespace mongo { D d = currentTime() - _currentStart; { - scoped_lock L(topMutex); + boostlock L(topMutex); recordUsage( _current, d ); } @@ -134,7 +134,7 @@ namespace mongo { }; static void usage( vector< Usage > &res ) { - scoped_lock L(topMutex); + boostlock L(topMutex); // Populate parent namespaces UsageMap snapshot; @@ -172,7 +172,7 @@ namespace mongo { } static void completeSnapshot() { - scoped_lock L(topMutex); + boostlock L(topMutex); if ( &_snapshot == &_snapshotA ) { _snapshot = _snapshotB; @@ -187,7 +187,7 @@ namespace mongo { } private: - static mongo::mutex topMutex; + static boost::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 bfb77c70b91..db5a3c91cf7 100644 --- a/mongo.xcodeproj/project.pbxproj +++ b/mongo.xcodeproj/project.pbxproj @@ -401,8 +401,10 @@ 936B895A0F4C899400934AF2 /* md5.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = md5.c; sourceTree = "<group>"; }; 936B895B0F4C899400934AF2 /* md5.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = md5.h; sourceTree = "<group>"; }; 936B895C0F4C899400934AF2 /* md5.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = md5.hpp; sourceTree = "<group>"; }; + 936B895D0F4C899400934AF2 /* md5main.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = md5main.c; sourceTree = "<group>"; }; 936B895E0F4C899400934AF2 /* message.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = message.cpp; sourceTree = "<group>"; }; 936B895F0F4C899400934AF2 /* message.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = message.h; sourceTree = "<group>"; }; + 936B89600F4C899400934AF2 /* top.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = top.h; sourceTree = "<group>"; }; 937CACE90F27BF4900C57AA6 /* socktests.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = socktests.cpp; sourceTree = "<group>"; }; 937D0E340F28CB070071FFA9 /* repltests.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = repltests.cpp; sourceTree = "<group>"; }; 937D14AB0F2A225F0071FFA9 /* nonce.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = nonce.h; sourceTree = "<group>"; }; @@ -498,14 +500,6 @@ 93C8E81C1145BCCA00F28017 /* regex7.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript; path = regex7.js; sourceTree = "<group>"; }; 93C8E9DF1146D39700F28017 /* arrayfind2.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript; path = arrayfind2.js; sourceTree = "<group>"; }; 93C8EB4D114721D000F28017 /* copydb2.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript; path = copydb2.js; sourceTree = "<group>"; }; - 93C8ECE61147820C00F28017 /* counters.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = counters.cpp; sourceTree = "<group>"; }; - 93C8ECE71147820C00F28017 /* counters.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = counters.h; sourceTree = "<group>"; }; - 93C8ECE91147820C00F28017 /* snapshots.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = snapshots.cpp; sourceTree = "<group>"; }; - 93C8ECEA1147820C00F28017 /* snapshots.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = snapshots.h; sourceTree = "<group>"; }; - 93C8ECEC1147820C00F28017 /* top.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = top.cpp; sourceTree = "<group>"; }; - 93C8ECED1147820C00F28017 /* top.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = top.h; sourceTree = "<group>"; }; - 93C8ED001147824B00F28017 /* thread_pool.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = thread_pool.cpp; sourceTree = "<group>"; }; - 93C8ED041147828F00F28017 /* index.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = index.cpp; sourceTree = "<group>"; }; 93CC40C2113C407A00734218 /* insert1.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript; path = insert1.js; sourceTree = "<group>"; }; 93CC441A113DE6BA00734218 /* indexg.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript; path = indexg.js; sourceTree = "<group>"; }; 93CC4484113E602400734218 /* in3.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript; path = in3.js; sourceTree = "<group>"; }; @@ -668,8 +662,6 @@ 9342238F0EF16DB400608550 /* db */ = { isa = PBXGroup; children = ( - 93C8ED041147828F00F28017 /* index.cpp */, - 93C8ECE51147820C00F28017 /* stats */, 9303D1AB10E1415C00294FAC /* client.cpp */, 9303D1AC10E1415C00294FAC /* client.h */, 9303D1AD10E1415C00294FAC /* cmdline.h */, @@ -1106,7 +1098,6 @@ 934DD87B0EFAD23B00459CC1 /* util */ = { isa = PBXGroup; children = ( - 93C8ED001147824B00F28017 /* thread_pool.cpp */, 934BEE8C10E050A500178102 /* allocator.h */, 934BEE8D10E050A500178102 /* assert_util.cpp */, 934BEE8E10E050A500178102 /* assert_util.h */, @@ -1135,8 +1126,10 @@ 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 */, @@ -1229,19 +1222,6 @@ path = scripting; sourceTree = "<group>"; }; - 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 = "<group>"; - }; 93F0956F10E165E50053380C /* parallel */ = { isa = PBXGroup; children = ( diff --git a/s/config.cpp b/s/config.cpp index 5b1405f3f84..0a4d74d5514 100644 --- a/s/config.cpp +++ b/s/config.cpp @@ -297,7 +297,7 @@ namespace mongo { if ( database == "config" ) return &configServer; - scoped_lock l( _lock ); + boostlock 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 ); - scoped_lock l( _lock ); + boostlock l( _lock ); _databases.erase( database ); } diff --git a/s/config.h b/s/config.h index 3b0dc4c1b50..7c4b03d2f26 100644 --- a/s/config.h +++ b/s/config.h @@ -151,7 +151,7 @@ namespace mongo { unsigned long long getNextOpTime() const; private: map<string,DBConfig*> _databases; - mongo::mutex _lock; // TODO: change to r/w lock + boost::mutex _lock; // TODO: change to r/w lock }; class ConfigServer : public DBConfig { diff --git a/s/request.cpp b/s/request.cpp index a111680c020..8bebd64c044 100644 --- a/s/request.cpp +++ b/s/request.cpp @@ -118,7 +118,7 @@ namespace mongo { } ClientInfo::~ClientInfo(){ - scoped_lock lk( _clientsLock ); + boostlock lk( _clientsLock ); ClientCache::iterator i = _clients.find( _id ); if ( i != _clients.end() ){ _clients.erase( i ); @@ -157,7 +157,7 @@ namespace mongo { return info; } - scoped_lock lk( _clientsLock ); + boostlock lk( _clientsLock ); ClientCache::iterator i = _clients.find( clientId ); if ( i != _clients.end() ) return i->second; @@ -169,7 +169,7 @@ namespace mongo { } map<int,ClientInfo*> ClientInfo::_clients; - mongo::mutex ClientInfo::_clientsLock; + boost::mutex ClientInfo::_clientsLock; boost::thread_specific_ptr<ClientInfo> ClientInfo::_tlInfo; } // namespace mongo diff --git a/s/request.h b/s/request.h index 2c02724dea2..f87a70ec9b4 100644 --- a/s/request.h +++ b/s/request.h @@ -127,7 +127,7 @@ namespace mongo { set<string> * _prev; int _lastAccess; - static mongo::mutex _clientsLock; + static boost::mutex _clientsLock; static ClientCache _clients; static boost::thread_specific_ptr<ClientInfo> _tlInfo; }; diff --git a/scripting/engine.cpp b/scripting/engine.cpp index cc245b66a47..0dff413dbde 100644 --- a/scripting/engine.cpp +++ b/scripting/engine.cpp @@ -243,7 +243,7 @@ namespace mongo { } void done( const string& pool , Scope * s ){ - scoped_lock lk( _mutex ); + boostlock lk( _mutex ); list<Scope*> & l = _pools[pool]; if ( l.size() > 10 ){ delete s; @@ -255,7 +255,7 @@ namespace mongo { } Scope * get( const string& pool ){ - scoped_lock lk( _mutex ); + boostlock lk( _mutex ); list<Scope*> & l = _pools[pool]; if ( l.size() == 0 ) return 0; @@ -283,7 +283,7 @@ namespace mongo { private: PoolToScopes _pools; - mongo::mutex _mutex; + boost::mutex _mutex; int _magic; }; diff --git a/scripting/engine_spidermonkey.cpp b/scripting/engine_spidermonkey.cpp index 19e3e852817..959ed856a0d 100644 --- a/scripting/engine_spidermonkey.cpp +++ b/scripting/engine_spidermonkey.cpp @@ -46,7 +46,7 @@ namespace mongo { boost::thread_specific_ptr<SMScope> currentScope( dontDeleteScope ); boost::recursive_mutex &smmutex = *( new boost::recursive_mutex ); -#define smlock recursive_scoped_lock ___lk( smmutex ); +#define smlock recursive_boostlock ___lk( smmutex ); #define GETHOLDER(x,o) ((BSONHolder*)JS_GetPrivate( x , o )) diff --git a/shell/dbshell.cpp b/shell/dbshell.cpp index 5f1a82c0959..47109f7a37c 100644 --- a/shell/dbshell.cpp +++ b/shell/dbshell.cpp @@ -525,7 +525,6 @@ 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 b10c93d41c0..6ba70f12b70 100644 --- a/shell/utils.cpp +++ b/shell/utils.cpp @@ -195,11 +195,11 @@ namespace mongo { map< pid_t, HANDLE > handles; #endif - mongo::mutex mongoProgramOutputMutex; + boost::mutex &mongoProgramOutputMutex( *( new boost::mutex ) ); stringstream mongoProgramOutput_; void writeMongoProgramOutputLine( int port, int pid, const char *line ) { - mongo::mutex::scoped_lock lk( mongoProgramOutputMutex ); + boost::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 ) { - mongo::mutex::scoped_lock lk( mongoProgramOutputMutex ); + boost::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 ) { - mongo::mutex::scoped_lock lk( mongoProgramOutputMutex ); + boost::mutex::scoped_lock lk( mongoProgramOutputMutex ); mongoProgramOutput_.str( "" ); return undefined_; } diff --git a/util/assert_util.cpp b/util/assert_util.cpp index 8c8477a0976..6bc902e7635 100644 --- a/util/assert_util.cpp +++ b/util/assert_util.cpp @@ -105,13 +105,13 @@ namespace mongo { } - mongo::mutex *Assertion::_mutex = new mongo::mutex(); + boost::mutex *Assertion::_mutex = new boost::mutex(); string Assertion::toString() { if( _mutex == 0 ) return ""; - scoped_lock lk(*_mutex); + boostlock lk(*_mutex); if ( !isSet() ) return ""; diff --git a/util/assert_util.h b/util/assert_util.h index bae3a55cbf1..81a6b0df20a 100644 --- a/util/assert_util.h +++ b/util/assert_util.h @@ -32,7 +32,7 @@ namespace mongo { when = 0; } private: - static mongo::mutex *_mutex; + static boost::mutex *_mutex; char msg[128]; char context[128]; const char *file; @@ -44,7 +44,7 @@ namespace mongo { /* asserted during global variable initialization */ return; } - scoped_lock lk(*_mutex); + boostlock lk(*_mutex); strncpy(msg, m, 127); strncpy(context, ctxt, 127); file = f; diff --git a/util/background.cpp b/util/background.cpp index 41253153247..ac3a48c8380 100644 --- a/util/background.cpp +++ b/util/background.cpp @@ -22,7 +22,7 @@ namespace mongo { BackgroundJob *BackgroundJob::grab = 0; - mongo::mutex BackgroundJob::mutex; + boost::mutex &BackgroundJob::mutex = *( new boost::mutex ); /* static */ void BackgroundJob::thr() { @@ -38,7 +38,7 @@ namespace mongo { } BackgroundJob& BackgroundJob::go() { - scoped_lock bl(mutex); + boostlock bl(mutex); assert( grab == 0 ); grab = this; boost::thread t(thr); diff --git a/util/background.h b/util/background.h index c95a5bd2c45..53c04887250 100644 --- a/util/background.h +++ b/util/background.h @@ -64,7 +64,7 @@ namespace mongo { private: static BackgroundJob *grab; - static mongo::mutex mutex; + static boost::mutex &mutex; static void thr(); volatile State state; }; diff --git a/util/file_allocator.h b/util/file_allocator.h index e819ba2321c..fa48d22c412 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) - scoped_lock lk( pendingMutex_ ); + boostlock 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) - scoped_lock lk( pendingMutex_ ); + boostlock lk( pendingMutex_ ); long oldSize = prevSize( name ); if ( oldSize != -1 ) { size = oldSize; @@ -100,7 +100,7 @@ namespace mongo { #if !defined(_WIN32) if ( failed_ ) return; - scoped_lock lk( pendingMutex_ ); + boostlock lk( pendingMutex_ ); while( pending_.size() != 0 ) pendingUpdated_.wait( lk ); #endif @@ -130,7 +130,7 @@ namespace mongo { return false; } - mutable mongo::mutex pendingMutex_; + mutable boost::mutex pendingMutex_; mutable boost::condition pendingUpdated_; list< string > pending_; mutable map< string, long > pendingSize_; @@ -142,7 +142,7 @@ namespace mongo { void operator()() { while( 1 ) { { - scoped_lock lk( a_.pendingMutex_ ); + boostlock lk( a_.pendingMutex_ ); if ( a_.pending_.size() == 0 ) a_.pendingUpdated_.wait( lk ); } @@ -150,7 +150,7 @@ namespace mongo { string name; long size; { - scoped_lock lk( a_.pendingMutex_ ); + boostlock 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 ( ... ) { } - scoped_lock lk( a_.pendingMutex_ ); + boostlock lk( a_.pendingMutex_ ); a_.failed_ = true; // not erasing from pending a_.pendingUpdated_.notify_all(); @@ -214,7 +214,7 @@ namespace mongo { } { - scoped_lock lk( a_.pendingMutex_ ); + boostlock 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 8bfe7a2b2f6..62ae2a64f1e 100644 --- a/util/goodies.h +++ b/util/goodies.h @@ -253,36 +253,8 @@ namespace mongo { return secs*1000000 + t; } using namespace boost; - - 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<mongo::mutex> 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; + typedef boost::mutex::scoped_lock boostlock; + typedef boost::recursive_mutex::scoped_lock recursive_boostlock; // simple scoped timer class Timer { @@ -321,7 +293,7 @@ namespace mongo { class DebugMutex : boost::noncopyable { friend class lock; - mongo::mutex m; + boost::mutex m; int locked; public: DebugMutex() : locked(0); { } @@ -330,7 +302,7 @@ namespace mongo { */ -//typedef scoped_lock lock; +//typedef boostlock lock; inline bool startsWith(const char *str, const char *prefix) { size_t l = strlen(prefix); @@ -471,7 +443,7 @@ namespace mongo { } bool tryAcquire(){ - scoped_lock lk( _mutex ); + boostlock lk( _mutex ); if ( _num <= 0 ){ if ( _num < 0 ){ cerr << "DISASTER! in TicketHolder" << endl; @@ -483,12 +455,12 @@ namespace mongo { } void release(){ - scoped_lock lk( _mutex ); + boostlock lk( _mutex ); _num++; } void resize( int newSize ){ - scoped_lock lk( _mutex ); + boostlock lk( _mutex ); int used = _outof - _num; if ( used > newSize ){ cout << "ERROR: can't resize since we're using (" << used << ") more than newSize(" << newSize << ")" << endl; @@ -510,7 +482,7 @@ namespace mongo { private: int _outof; int _num; - mongo::mutex _mutex; + boost::mutex _mutex; }; class TicketHolderReleaser { diff --git a/util/log.h b/util/log.h index 668557a3e5b..bac1156d0f4 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 mongo::mutex mutex; + static boost::mutex &mutex; static int doneSetup; stringstream ss; public: @@ -128,7 +128,7 @@ namespace mongo { void flush() { // this ensures things are sane if ( doneSetup == 1717 ){ - scoped_lock lk(mutex); + boostlock lk(mutex); cout << ss.str(); cout.flush(); } diff --git a/util/message.cpp b/util/message.cpp index 2c3d0063f34..b61e8944af1 100644 --- a/util/message.cpp +++ b/util/message.cpp @@ -138,22 +138,23 @@ namespace mongo { class Ports { set<MessagingPort*>& ports; - mongo::mutex m; + boost::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<MessagingPort*>()) ) {} + Ports() : ports( *(new set<MessagingPort*>()) ), + m( *(new boost::mutex()) ) { } void closeAll() { \ - scoped_lock bl(m); + boostlock bl(m); for ( set<MessagingPort*>::iterator i = ports.begin(); i != ports.end(); i++ ) (*i)->shutdown(); } void insert(MessagingPort* p) { - scoped_lock bl(m); + boostlock bl(m); ports.insert(p); } void erase(MessagingPort* p) { - scoped_lock bl(m); + boostlock bl(m); ports.erase(p); } } ports; diff --git a/util/message_server_asio.cpp b/util/message_server_asio.cpp index 7fca29abd98..f652a340147 100644 --- a/util/message_server_asio.cpp +++ b/util/message_server_asio.cpp @@ -68,7 +68,7 @@ namespace mongo { }; vector<boost::shared_ptr<StickyThread> > thread_pool; - mongo::mutex tp_mutex; // this is only needed if io_service::run() is called from multiple threads + boost::mutex tp_mutex; // this is only needed if io_service::run() is called from multiple threads } class MessageServerSession : public boost::enable_shared_from_this<MessageServerSession> , public AbstractMessagingPort { @@ -117,7 +117,7 @@ namespace mongo { void handleReadBody( const boost::system::error_code& error ){ if (!_myThread){ - mongo::mutex::scoped_lock(tp_mutex); + boost::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 - mongo::mutex::scoped_lock(tp_mutex); + boost::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 f6bbc735ec6..536cf85e145 100644 --- a/util/mmap.cpp +++ b/util/mmap.cpp @@ -22,16 +22,16 @@ namespace mongo { set<MemoryMappedFile*> mmfiles; - mongo::mutex mmmutex; + boost::mutex mmmutex; MemoryMappedFile::~MemoryMappedFile() { close(); - scoped_lock lk( mmmutex ); + boostlock lk( mmmutex ); mmfiles.erase(this); } void MemoryMappedFile::created(){ - scoped_lock lk( mmmutex ); + boostlock lk( mmmutex ); mmfiles.insert(this); } @@ -55,7 +55,7 @@ namespace mongo { long long MemoryMappedFile::totalMappedLength(){ unsigned long long total = 0; - scoped_lock lk( mmmutex ); + boostlock lk( mmmutex ); for ( set<MemoryMappedFile*>::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; - scoped_lock lk( mmmutex ); + boostlock lk( mmmutex ); for ( set<MemoryMappedFile*>::iterator i = mmfiles.begin(); i != mmfiles.end(); i++ ){ num++; MemoryMappedFile * mmf = *i; diff --git a/util/queue.h b/util/queue.h index d291cb80c90..8f4fbaf7ac8 100644 --- a/util/queue.h +++ b/util/queue.h @@ -30,18 +30,18 @@ namespace mongo { template<typename T> class BlockingQueue : boost::noncopyable { public: void push(T const& t){ - scoped_lock l( _lock ); + boostlock l( _lock ); _queue.push( t ); _condition.notify_one(); } bool empty() const { - scoped_lock l( _lock ); + boostlock l( _lock ); return _queue.empty(); } bool tryPop( T & t ){ - scoped_lock l( _lock ); + boostlock l( _lock ); if ( _queue.empty() ) return false; @@ -53,7 +53,7 @@ namespace mongo { T blockingPop(){ - scoped_lock l( _lock ); + boostlock l( _lock ); while( _queue.empty() ) _condition.wait( l ); @@ -65,7 +65,7 @@ namespace mongo { private: std::queue<T> _queue; - mutable mongo::mutex _lock; + mutable boost::mutex _lock; boost::condition _condition; }; diff --git a/util/sock.cpp b/util/sock.cpp index 5beac683568..5172692a529 100644 --- a/util/sock.cpp +++ b/util/sock.cpp @@ -20,14 +20,14 @@ namespace mongo { - static mongo::mutex sock_mutex; + static boost::mutex sock_mutex; string hostbyname(const char *hostname) { static string unknown = "0.0.0.0"; if ( unknown == hostname ) return unknown; - scoped_lock lk(sock_mutex); + boostlock 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 ee7a7aef48f..d1a941692cd 100644 --- a/util/sock.h +++ b/util/sock.h @@ -245,18 +245,18 @@ namespace mongo { } void add( int sock ){ - scoped_lock lk( _mutex ); + boostlock lk( _mutex ); _sockets->insert( sock ); } void remove( int sock ){ - scoped_lock lk( _mutex ); + boostlock lk( _mutex ); _sockets->erase( sock ); } void closeAll(){ set<int>* s; { - scoped_lock lk( _mutex ); + boostlock lk( _mutex ); s = _sockets; _sockets = new set<int>(); } @@ -272,7 +272,7 @@ namespace mongo { static ListeningSockets* get(); private: - mongo::mutex _mutex; + boost::mutex _mutex; set<int>* _sockets; static ListeningSockets* _instance; }; diff --git a/util/thread_pool.cpp b/util/thread_pool.cpp index 7c12b87bb65..b95bc1d50cb 100644 --- a/util/thread_pool.cpp +++ b/util/thread_pool.cpp @@ -77,7 +77,7 @@ ThreadPool::ThreadPool(int nThreads) : _tasksRemaining(0) , _nThreads(nThreads) { - scoped_lock lock(_mutex); + boostlock lock(_mutex); while (nThreads-- > 0){ Worker* worker = new Worker(*this); _freeWorkers.push_front(worker); @@ -99,14 +99,14 @@ ThreadPool::~ThreadPool(){ } void ThreadPool::join(){ - scoped_lock lock(_mutex); + boostlock lock(_mutex); while(_tasksRemaining){ _condition.wait(lock); } } void ThreadPool::schedule(Task task){ - scoped_lock lock(_mutex); + boostlock 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){ - scoped_lock lock(_mutex); + boostlock lock(_mutex); if (!_tasks.empty()){ worker->set_task(_tasks.front()); diff --git a/util/thread_pool.h b/util/thread_pool.h index d891d7daac2..91c2969d559 100644 --- a/util/thread_pool.h +++ b/util/thread_pool.h @@ -62,7 +62,7 @@ namespace threadpool { int tasks_remaining() { return _tasksRemaining; } private: - mongo::mutex _mutex; + boost::mutex _mutex; boost::condition _condition; list<Worker*> _freeWorkers; //used as LIFO stack (always front) diff --git a/util/util.cpp b/util/util.cpp index 8ae00f3e961..c96bef62445 100644 --- a/util/util.cpp +++ b/util/util.cpp @@ -34,7 +34,7 @@ namespace mongo { const char * (*getcurns)() = default_getcurns; int logLevel = 0; - mongo::mutex Logstream::mutex; + boost::mutex &Logstream::mutex = *( new boost::mutex ); int Logstream::doneSetup = Logstream::magicNumber(); bool goingAway = false; @@ -137,7 +137,5 @@ namespace mongo { s << (string)o; return s; } - - bool __destroyingStatics = false; - + } // namespace mongo |