diff options
author | Andrew Morrow <acm@mongodb.com> | 2015-06-18 15:02:54 -0400 |
---|---|---|
committer | Andrew Morrow <acm@mongodb.com> | 2015-06-19 22:51:28 -0400 |
commit | 1178eff1ddf60a7dac3a8cd71e2fdd278aa01b52 (patch) | |
tree | ee3096045eb4d2e4f69d57ef85c66b3be69e4302 | |
parent | 4b5fa5fc711e4cf94291665575fd1c742ad3e7c3 (diff) | |
download | mongo-1178eff1ddf60a7dac3a8cd71e2fdd278aa01b52.tar.gz |
SERVER-19041 Simplify SimpleMutex
78 files changed, 247 insertions, 234 deletions
diff --git a/src/mongo/client/connpool.h b/src/mongo/client/connpool.h index fd0204dd46a..0324a5be080 100644 --- a/src/mongo/client/connpool.h +++ b/src/mongo/client/connpool.h @@ -249,7 +249,7 @@ namespace mongo { typedef std::map<PoolKey,PoolForHost,poolKeyCompare> PoolMap; // servername -> pool - mongo::mutex _mutex; + stdx::mutex _mutex; std::string _name; // The maximum number of connections we'll save in the pool per-host diff --git a/src/mongo/client/cyrus_sasl_client_session.cpp b/src/mongo/client/cyrus_sasl_client_session.cpp index d947bb3fa36..46db14f49c4 100644 --- a/src/mongo/client/cyrus_sasl_client_session.cpp +++ b/src/mongo/client/cyrus_sasl_client_session.cpp @@ -83,7 +83,7 @@ namespace { */ void* saslMutexAlloc(void) { - return new SimpleMutex("sasl"); + return new SimpleMutex; } int saslMutexLock(void* mutex) { diff --git a/src/mongo/client/dbclient.cpp b/src/mongo/client/dbclient.cpp index fc38fdb224e..4b455a75ac4 100644 --- a/src/mongo/client/dbclient.cpp +++ b/src/mongo/client/dbclient.cpp @@ -53,6 +53,7 @@ #include "mongo/s/stale_exception.h" // for RecvStaleConfigException #include "mongo/stdx/functional.h" #include "mongo/stdx/memory.h" +#include "mongo/stdx/mutex.h" #include "mongo/util/assert_util.h" #include "mongo/util/concurrency/mutex.h" #include "mongo/util/debug_util.h" @@ -76,11 +77,11 @@ namespace { const char* const saslCommandUserSourceFieldName = "userSource"; #ifdef MONGO_CONFIG_SSL - static SimpleMutex s_mtx("SSLManager"); + static SimpleMutex s_mtx; static SSLManagerInterface* s_sslMgr(NULL); SSLManagerInterface* sslManager() { - SimpleMutex::scoped_lock lk(s_mtx); + stdx::lock_guard<SimpleMutex> lk(s_mtx); if (s_sslMgr) { return s_sslMgr; } diff --git a/src/mongo/client/examples/mongoperf.cpp b/src/mongo/client/examples/mongoperf.cpp index f74ec14acad..88d3d03e422 100644 --- a/src/mongo/client/examples/mongoperf.cpp +++ b/src/mongo/client/examples/mongoperf.cpp @@ -72,7 +72,7 @@ unsigned nThreadsRunning = 0; // as this is incremented A LOT, at some point this becomes a bottleneck if very high ops/second (in cache) things are happening. AtomicUInt32 iops; -SimpleMutex m("mperf"); +SimpleMutex m; int syncDelaySecs = 0; diff --git a/src/mongo/client/replica_set_monitor.cpp b/src/mongo/client/replica_set_monitor.cpp index cad15d3899a..9a953ce3a0e 100644 --- a/src/mongo/client/replica_set_monitor.cpp +++ b/src/mongo/client/replica_set_monitor.cpp @@ -39,6 +39,7 @@ #include "mongo/client/replica_set_monitor_internal.h" #include "mongo/db/server_options.h" #include "mongo/stdx/condition_variable.h" +#include "mongo/stdx/mutex.h" #include "mongo/stdx/thread.h" #include "mongo/util/background.h" #include "mongo/util/concurrency/mutex.h" // for StaticObserver @@ -46,6 +47,7 @@ #include "mongo/util/exit.h" #include "mongo/util/log.h" #include "mongo/util/string_map.h" +#include "mongo/util/static_observer.h" #include "mongo/util/timer.h" namespace mongo { @@ -181,7 +183,7 @@ namespace { } // protects _started, _stopRequested - mongo::mutex _monitorMutex; + stdx::mutex _monitorMutex; bool _started; stdx::condition_variable _stopRequestedCV; diff --git a/src/mongo/client/syncclusterconnection.h b/src/mongo/client/syncclusterconnection.h index 0147cec1711..fe8c93be8da 100644 --- a/src/mongo/client/syncclusterconnection.h +++ b/src/mongo/client/syncclusterconnection.h @@ -34,6 +34,7 @@ #include "mongo/bson/bsonelement.h" #include "mongo/bson/bsonobj.h" #include "mongo/client/dbclientinterface.h" +#include "mongo/stdx/mutex.h" #include "mongo/util/concurrency/mutex.h" namespace mongo { @@ -163,7 +164,7 @@ namespace mongo { // Optionally attached by user std::unique_ptr<QueryHandler> _customQueryHandler; - mongo::mutex _mutex; + stdx::mutex _mutex; std::map<std::string,int> _lockTypes; // End mutex diff --git a/src/mongo/db/catalog/cursor_manager.cpp b/src/mongo/db/catalog/cursor_manager.cpp index 3143c3382cf..b5bf0f49f73 100644 --- a/src/mongo/db/catalog/cursor_manager.cpp +++ b/src/mongo/db/catalog/cursor_manager.cpp @@ -141,8 +141,7 @@ namespace mongo { } GlobalCursorIdCache::GlobalCursorIdCache() - : _mutex( "GlobalCursorIdCache" ), - _nextId( 0 ), + : _nextId( 0 ), _secureRandom() { } @@ -150,7 +149,7 @@ namespace mongo { } int64_t GlobalCursorIdCache::nextSeed() { - SimpleMutex::scoped_lock lk( _mutex ); + stdx::lock_guard<SimpleMutex> lk( _mutex ); if ( !_secureRandom ) _secureRandom.reset(SecureRandom::create()); return _secureRandom->nextInt64(); @@ -159,7 +158,7 @@ namespace mongo { unsigned GlobalCursorIdCache::created( const std::string& ns ) { static const unsigned MAX_IDS = 1000 * 1000 * 1000; - SimpleMutex::scoped_lock lk( _mutex ); + stdx::lock_guard<SimpleMutex> lk( _mutex ); fassert( 17359, _idToNS.size() < MAX_IDS ); @@ -177,7 +176,7 @@ namespace mongo { } void GlobalCursorIdCache::destroyed( unsigned id, const std::string& ns ) { - SimpleMutex::scoped_lock lk( _mutex ); + stdx::lock_guard<SimpleMutex> lk( _mutex ); invariant( ns == _idToNS[id] ); _idToNS.erase( id ); } @@ -195,7 +194,7 @@ namespace mongo { ns = pin.c()->ns(); } else { - SimpleMutex::scoped_lock lk(_mutex); + stdx::lock_guard<SimpleMutex> lk(_mutex); unsigned nsid = idFromCursorId(id); Map::const_iterator it = _idToNS.find(nsid); if (it == _idToNS.end()) { @@ -250,7 +249,7 @@ namespace mongo { // Compute the set of collection names that we have to time out cursors for. vector<string> todo; { - SimpleMutex::scoped_lock lk( _mutex ); + stdx::lock_guard<SimpleMutex> lk( _mutex ); for ( Map::const_iterator i = _idToNS.begin(); i != _idToNS.end(); ++i ) { if (globalCursorManager->ownsCursorId(cursorIdFromParts(i->first, 0))) { // Skip the global cursor manager, since we handle it above (and it's not @@ -317,8 +316,7 @@ namespace mongo { CursorManager::CursorManager( StringData ns ) - : _nss( ns ), - _mutex( "CursorManager" ) { + : _nss( ns ) { _collectionCacheRuntimeId = globalCursorIdCache->created( _nss.ns() ); _random.reset( new PseudoRandom( globalCursorIdCache->nextSeed() ) ); } @@ -330,7 +328,7 @@ namespace mongo { void CursorManager::invalidateAll(bool collectionGoingAway, const std::string& reason) { - SimpleMutex::scoped_lock lk( _mutex ); + stdx::lock_guard<SimpleMutex> lk( _mutex ); for ( ExecSet::iterator it = _nonCachedExecutors.begin(); it != _nonCachedExecutors.end(); @@ -407,7 +405,7 @@ namespace mongo { return; } - SimpleMutex::scoped_lock lk( _mutex ); + stdx::lock_guard<SimpleMutex> lk( _mutex ); for ( ExecSet::iterator it = _nonCachedExecutors.begin(); it != _nonCachedExecutors.end(); @@ -426,7 +424,7 @@ namespace mongo { } std::size_t CursorManager::timeoutCursors( int millisSinceLastCall ) { - SimpleMutex::scoped_lock lk( _mutex ); + stdx::lock_guard<SimpleMutex> lk( _mutex ); vector<ClientCursor*> toDelete; @@ -448,18 +446,18 @@ namespace mongo { } void CursorManager::registerExecutor( PlanExecutor* exec ) { - SimpleMutex::scoped_lock lk(_mutex); + stdx::lock_guard<SimpleMutex> lk(_mutex); const std::pair<ExecSet::iterator, bool> result = _nonCachedExecutors.insert(exec); invariant(result.second); // make sure this was inserted } void CursorManager::deregisterExecutor( PlanExecutor* exec ) { - SimpleMutex::scoped_lock lk(_mutex); + stdx::lock_guard<SimpleMutex> lk(_mutex); _nonCachedExecutors.erase(exec); } ClientCursor* CursorManager::find( CursorId id, bool pin ) { - SimpleMutex::scoped_lock lk( _mutex ); + stdx::lock_guard<SimpleMutex> lk( _mutex ); CursorMap::const_iterator it = _cursors.find( id ); if ( it == _cursors.end() ) return NULL; @@ -476,7 +474,7 @@ namespace mongo { } void CursorManager::unpin( ClientCursor* cursor ) { - SimpleMutex::scoped_lock lk( _mutex ); + stdx::lock_guard<SimpleMutex> lk( _mutex ); invariant( cursor->isPinned() ); cursor->unsetPinned(); @@ -487,7 +485,7 @@ namespace mongo { } void CursorManager::getCursorIds( std::set<CursorId>* openCursors ) const { - SimpleMutex::scoped_lock lk( _mutex ); + stdx::lock_guard<SimpleMutex> lk( _mutex ); for ( CursorMap::const_iterator i = _cursors.begin(); i != _cursors.end(); ++i ) { ClientCursor* cc = i->second; @@ -496,7 +494,7 @@ namespace mongo { } size_t CursorManager::numCursors() const { - SimpleMutex::scoped_lock lk( _mutex ); + stdx::lock_guard<SimpleMutex> lk( _mutex ); return _cursors.size(); } @@ -512,19 +510,19 @@ namespace mongo { CursorId CursorManager::registerCursor( ClientCursor* cc ) { invariant( cc ); - SimpleMutex::scoped_lock lk( _mutex ); + stdx::lock_guard<SimpleMutex> lk( _mutex ); CursorId id = _allocateCursorId_inlock(); _cursors[id] = cc; return id; } void CursorManager::deregisterCursor( ClientCursor* cc ) { - SimpleMutex::scoped_lock lk( _mutex ); + stdx::lock_guard<SimpleMutex> lk( _mutex ); _deregisterCursor_inlock( cc ); } bool CursorManager::eraseCursor(OperationContext* txn, CursorId id, bool checkAuth) { - SimpleMutex::scoped_lock lk( _mutex ); + stdx::lock_guard<SimpleMutex> lk( _mutex ); CursorMap::iterator it = _cursors.find( id ); if ( it == _cursors.end() ) { diff --git a/src/mongo/db/catalog/database_holder.cpp b/src/mongo/db/catalog/database_holder.cpp index 7ff6ea6d81b..bf1238db95f 100644 --- a/src/mongo/db/catalog/database_holder.cpp +++ b/src/mongo/db/catalog/database_holder.cpp @@ -84,7 +84,7 @@ namespace { const StringData db = _todb(ns); invariant(txn->lockState()->isDbLockedForMode(db, MODE_IS)); - SimpleMutex::scoped_lock lk(_m); + stdx::lock_guard<SimpleMutex> lk(_m); DBs::const_iterator it = _dbs.find(db); if (it != _dbs.end()) { return it->second; @@ -141,7 +141,7 @@ namespace { // no way we can insert two different databases for the same name. db = new Database(txn, dbname, entry); - SimpleMutex::scoped_lock lk(_m); + stdx::lock_guard<SimpleMutex> lk(_m); _dbs[dbname] = db; return db; @@ -154,7 +154,7 @@ namespace { const StringData dbName = _todb(ns); - SimpleMutex::scoped_lock lk(_m); + stdx::lock_guard<SimpleMutex> lk(_m); DBs::const_iterator it = _dbs.find(dbName); if (it == _dbs.end()) { @@ -171,7 +171,7 @@ namespace { bool DatabaseHolder::closeAll(OperationContext* txn, BSONObjBuilder& result, bool force) { invariant(txn->lockState()->isW()); - SimpleMutex::scoped_lock lk(_m); + stdx::lock_guard<SimpleMutex> lk(_m); set< string > dbs; for ( DBs::const_iterator i = _dbs.begin(); i != _dbs.end(); ++i ) { diff --git a/src/mongo/db/catalog/database_holder.h b/src/mongo/db/catalog/database_holder.h index 264a03b36b3..3238b886f01 100644 --- a/src/mongo/db/catalog/database_holder.h +++ b/src/mongo/db/catalog/database_holder.h @@ -45,7 +45,7 @@ namespace mongo { */ class DatabaseHolder { public: - DatabaseHolder() : _m("dbholder") { } + DatabaseHolder() = default; /** * Retrieves an already opened database or returns NULL. Must be called with the database @@ -81,7 +81,7 @@ namespace mongo { * lock is held, which would prevent database from disappearing or being created. */ void getAllShortNames( std::set<std::string>& all ) const { - SimpleMutex::scoped_lock lk(_m); + stdx::lock_guard<SimpleMutex> lk(_m); for( DBs::const_iterator j=_dbs.begin(); j!=_dbs.end(); ++j ) { all.insert( j->first ); } diff --git a/src/mongo/db/commands/authentication_commands.cpp b/src/mongo/db/commands/authentication_commands.cpp index 1e2dc0a2439..698eb2fd406 100644 --- a/src/mongo/db/commands/authentication_commands.cpp +++ b/src/mongo/db/commands/authentication_commands.cpp @@ -100,7 +100,6 @@ namespace mongo { public: CmdGetNonce() : Command("getnonce"), - _randMutex("getnonce"), _random(SecureRandom::create()) { } @@ -130,7 +129,7 @@ namespace mongo { private: nonce64 getNextNonce() { - SimpleMutex::scoped_lock lk(_randMutex); + stdx::lock_guard<SimpleMutex> lk(_randMutex); return _random->nextInt64(); } diff --git a/src/mongo/db/commands/dbhash.h b/src/mongo/db/commands/dbhash.h index 35e5c9302fb..aa9a396b080 100644 --- a/src/mongo/db/commands/dbhash.h +++ b/src/mongo/db/commands/dbhash.h @@ -31,6 +31,7 @@ #pragma once #include "mongo/db/commands.h" +#include "mongo/stdx/mutex.h" namespace mongo { @@ -67,7 +68,7 @@ namespace mongo { std::string hashCollection( OperationContext* opCtx, Database* db, const std::string& fullCollectionName, bool* fromCache ); std::map<std::string,std::string> _cachedHashed; - mutex _cachedHashedMutex; + stdx::mutex _cachedHashedMutex; }; diff --git a/src/mongo/db/commands/fsync.cpp b/src/mongo/db/commands/fsync.cpp index a8b19391d3c..aa3b8c9855a 100644 --- a/src/mongo/db/commands/fsync.cpp +++ b/src/mongo/db/commands/fsync.cpp @@ -92,7 +92,7 @@ namespace mongo { stdx::condition_variable_any _threadSync; stdx::condition_variable_any _unlockSync; - FSyncCommand() : Command( "fsync" ), m("lockfsync") { locked=false; pendingUnlock=false; } + FSyncCommand() : Command( "fsync" ) { locked=false; pendingUnlock=false; } virtual bool isWriteCommandForConfigServer() const { return false; } virtual bool slaveOk() const { return true; } virtual bool adminOnly() const { return true; } @@ -125,7 +125,7 @@ namespace mongo { return false; } - SimpleMutex::scoped_lock lk(m); + stdx::lock_guard<SimpleMutex> lk(m); err = ""; (new FSyncLockThread())->go(); @@ -211,16 +211,16 @@ namespace mongo { } unlockFsyncCmd; - SimpleMutex filesLockedFsync("filesLockedFsync"); + SimpleMutex filesLockedFsync; void FSyncLockThread::doRealWork() { - SimpleMutex::scoped_lock lkf(filesLockedFsync); + stdx::lock_guard<SimpleMutex> lkf(filesLockedFsync); OperationContextImpl txn; ScopedTransaction transaction(&txn, MODE_X); Lock::GlobalWrite global(txn.lockState()); // No WriteUnitOfWork needed - SimpleMutex::scoped_lock lk(fsyncCmd.m); + stdx::lock_guard<SimpleMutex> lk(fsyncCmd.m); invariant(!fsyncCmd.locked); // impossible to get here if locked is true try { @@ -271,7 +271,7 @@ namespace mongo { namespace { // @return true if unlocked bool unlockFsync() { - SimpleMutex::scoped_lock lk( fsyncCmd.m ); + stdx::lock_guard<SimpleMutex> lk( fsyncCmd.m ); if( !fsyncCmd.locked ) { return false; } diff --git a/src/mongo/db/concurrency/lock_manager.cpp b/src/mongo/db/concurrency/lock_manager.cpp index d082cc981ac..7a0e094ea30 100644 --- a/src/mongo/db/concurrency/lock_manager.cpp +++ b/src/mongo/db/concurrency/lock_manager.cpp @@ -399,7 +399,7 @@ namespace { // Migration time: lock each partition in turn and transfer its requests, if any while(partitioned()) { LockManager::Partition* partition = partitions.back(); - SimpleMutex::scoped_lock scopedLock(partition->mutex); + stdx::lock_guard<SimpleMutex> scopedLock(partition->mutex); LockManager::Partition::Map::iterator it = partition->data.find(resourceId); if (it != partition->data.end()) { @@ -459,7 +459,7 @@ namespace { // For intent modes, try the PartitionedLockHead if (request->partitioned) { Partition* partition = _getPartition(request); - SimpleMutex::scoped_lock scopedLock(partition->mutex); + stdx::lock_guard<SimpleMutex> scopedLock(partition->mutex); // Fast path for intent locks PartitionedLockHead* partitionedLock = partition->find(resId); @@ -475,7 +475,7 @@ namespace { // Use regular LockHead, maybe start partitioning LockBucket* bucket = _getBucket(resId); - SimpleMutex::scoped_lock scopedLock(bucket->mutex); + stdx::lock_guard<SimpleMutex> scopedLock(bucket->mutex); LockHead* lock = bucket->findOrInsert(resId); @@ -483,7 +483,7 @@ namespace { if (request->partitioned && !(lock->grantedModes & (~intentModes)) && !lock->conflictModes) { Partition* partition = _getPartition(request); - SimpleMutex::scoped_lock scopedLock(partition->mutex); + stdx::lock_guard<SimpleMutex> scopedLock(partition->mutex); PartitionedLockHead* partitionedLock = partition->findOrInsert(resId); invariant(partitionedLock); lock->partitions.push_back(partition); @@ -524,7 +524,7 @@ namespace { LockConflictsTable[newMode]); LockBucket* bucket = _getBucket(resId); - SimpleMutex::scoped_lock scopedLock(bucket->mutex); + stdx::lock_guard<SimpleMutex> scopedLock(bucket->mutex); LockBucket::Map::iterator it = bucket->data.find(resId); invariant(it != bucket->data.end()); @@ -595,7 +595,7 @@ namespace { invariant(request->status == LockRequest::STATUS_GRANTED || request->status == LockRequest::STATUS_CONVERTING); Partition* partition = _getPartition(request); - SimpleMutex::scoped_lock scopedLock(partition->mutex); + stdx::lock_guard<SimpleMutex> scopedLock(partition->mutex); // Fast path: still partitioned. if (request->partitionedLock) { request->partitionedLock->grantedList.remove(request); @@ -608,7 +608,7 @@ namespace { LockHead* lock = request->lock; LockBucket* bucket = _getBucket(lock->resourceId); - SimpleMutex::scoped_lock scopedLock(bucket->mutex); + stdx::lock_guard<SimpleMutex> scopedLock(bucket->mutex); if (request->status == LockRequest::STATUS_GRANTED) { // This releases a currently held lock and is the most common path, so it should be @@ -668,7 +668,7 @@ namespace { LockHead* lock = request->lock; LockBucket* bucket = _getBucket(lock->resourceId); - SimpleMutex::scoped_lock scopedLock(bucket->mutex); + stdx::lock_guard<SimpleMutex> scopedLock(bucket->mutex); lock->incGrantedModeCount(newMode); lock->decGrantedModeCount(request->mode); @@ -681,7 +681,7 @@ namespace { size_t deletedLockHeads = 0; for (unsigned i = 0; i < _numLockBuckets; i++) { LockBucket* bucket = &_lockBuckets[i]; - SimpleMutex::scoped_lock scopedLock(bucket->mutex); + stdx::lock_guard<SimpleMutex> scopedLock(bucket->mutex); LockBucket::Map::iterator it = bucket->data.begin(); while (it != bucket->data.end()) { @@ -821,7 +821,7 @@ namespace { for (unsigned i = 0; i < _numLockBuckets; i++) { LockBucket* bucket = &_lockBuckets[i]; - SimpleMutex::scoped_lock scopedLock(bucket->mutex); + stdx::lock_guard<SimpleMutex> scopedLock(bucket->mutex); if (!bucket->data.empty()) { _dumpBucket(bucket); @@ -971,7 +971,7 @@ namespace { void DeadlockDetector::_processNextNode(const UnprocessedNode& node) { // Locate the request LockManager::LockBucket* bucket = _lockMgr._getBucket(node.resId); - SimpleMutex::scoped_lock scopedLock(bucket->mutex); + stdx::lock_guard<SimpleMutex> scopedLock(bucket->mutex); LockManager::LockBucket::Map::const_iterator iter = bucket->data.find(node.resId); if (iter == bucket->data.end()) { diff --git a/src/mongo/db/concurrency/lock_manager.h b/src/mongo/db/concurrency/lock_manager.h index 1d8c054152b..badad082214 100644 --- a/src/mongo/db/concurrency/lock_manager.h +++ b/src/mongo/db/concurrency/lock_manager.h @@ -130,7 +130,6 @@ namespace mongo { // These types describe the locks hash table struct LockBucket { - LockBucket() : mutex("LockManager") { } SimpleMutex mutex; typedef unordered_map<ResourceId, LockHead*> Map; Map data; @@ -141,7 +140,6 @@ namespace mongo { // modes and potentially other modes that don't conflict with themselves. This avoids // contention on the regular LockHead in the lock manager. struct Partition { - Partition() : mutex("LockManager") { } PartitionedLockHead* find(ResourceId resId); PartitionedLockHead* findOrInsert(ResourceId resId); typedef unordered_map<ResourceId, PartitionedLockHead*> Map; diff --git a/src/mongo/db/db.cpp b/src/mongo/db/db.cpp index 4969640bea7..b16c9c8ba8b 100644 --- a/src/mongo/db/db.cpp +++ b/src/mongo/db/db.cpp @@ -113,6 +113,7 @@ #include "mongo/util/signal_handlers.h" #include "mongo/util/stacktrace.h" #include "mongo/util/startup_test.h" +#include "mongo/util/static_observer.h" #include "mongo/util/text.h" #include "mongo/util/time_support.h" #include "mongo/util/version.h" diff --git a/src/mongo/db/global_timestamp.cpp b/src/mongo/db/global_timestamp.cpp index 6fd17da2d28..536d9d17b98 100644 --- a/src/mongo/db/global_timestamp.cpp +++ b/src/mongo/db/global_timestamp.cpp @@ -29,12 +29,12 @@ #define MONGO_LOG_DEFAULT_COMPONENT ::mongo::logger::LogComponent::kDefault #include "mongo/db/global_timestamp.h" +#include "mongo/stdx/mutex.h" #include "mongo/stdx/thread.h" -#include "mongo/util/concurrency/mutex.h" #include "mongo/util/log.h" namespace { - mongo::mutex globalTimestampMutex; + mongo::stdx::mutex globalTimestampMutex; mongo::Timestamp globalTimestamp(0, 0); bool skewed(const mongo::Timestamp& val) { diff --git a/src/mongo/db/instance.h b/src/mongo/db/instance.h index e7aa31b9f86..097b62d743b 100644 --- a/src/mongo/db/instance.h +++ b/src/mongo/db/instance.h @@ -50,7 +50,7 @@ namespace mongo { 7 = log a few reads, and all writes. */ int level; - mongo::mutex mutex; + stdx::mutex mutex; void openFile(); public: diff --git a/src/mongo/db/range_deleter.h b/src/mongo/db/range_deleter.h index db56a86576b..eaf8fa35e1d 100644 --- a/src/mongo/db/range_deleter.h +++ b/src/mongo/db/range_deleter.h @@ -39,6 +39,7 @@ #include "mongo/db/jsobj.h" #include "mongo/db/operation_context.h" #include "mongo/db/write_concern_options.h" +#include "mongo/stdx/mutex.h" #include "mongo/stdx/thread.h" #include "mongo/util/concurrency/mutex.h" #include "mongo/util/concurrency/synchronization.h" @@ -203,7 +204,7 @@ namespace mongo { std::unique_ptr<stdx::thread> _worker; // Protects _stopRequested. - mutable mutex _stopMutex; + mutable stdx::mutex _stopMutex; // If set, no other delete taks should be accepted. bool _stopRequested; @@ -214,7 +215,7 @@ namespace mongo { stdx::condition_variable _nothingInProgressCV; // Protects all the data structure below this. - mutable mutex _queueMutex; + mutable stdx::mutex _queueMutex; // _taskQueue has a task ready to work on. stdx::condition_variable _taskQueueNotEmptyCV; @@ -240,7 +241,7 @@ namespace mongo { size_t _deletesInProgress; // Protects _statsHistory - mutable mutex _statsHistoryMutex; + mutable stdx::mutex _statsHistoryMutex; std::deque<DeleteJobStats*> _statsHistory; }; diff --git a/src/mongo/db/range_deleter_mock_env.h b/src/mongo/db/range_deleter_mock_env.h index b4892b99f70..bba49a360e4 100644 --- a/src/mongo/db/range_deleter_mock_env.h +++ b/src/mongo/db/range_deleter_mock_env.h @@ -33,6 +33,7 @@ #include <string> #include "mongo/db/range_deleter.h" +#include "mongo/stdx/mutex.h" namespace mongo { @@ -139,14 +140,14 @@ namespace mongo { // mutex acquisition ordering: // _envStatMutex -> _pauseDeleteMutex -> _deleteListMutex -> _cursorMapMutex - mutable mutex _deleteListMutex; + mutable stdx::mutex _deleteListMutex; std::vector<DeletedRange> _deleteList; - mutex _cursorMapMutex; + stdx::mutex _cursorMapMutex; std::map<std::string, std::set<CursorId> > _cursorMap; // Protects _pauseDelete & _pausedCount - mutex _pauseDeleteMutex; + stdx::mutex _pauseDeleteMutex; stdx::condition_variable _pausedCV; bool _pauseDelete; @@ -156,7 +157,7 @@ namespace mongo { stdx::condition_variable _pausedDeleteChangeCV; // Protects all variables below this line. - mutex _envStatMutex; + stdx::mutex _envStatMutex; // Keeps track of the number of times getCursorIds was called. uint64_t _getCursorsCallCount; diff --git a/src/mongo/db/repl/oplog.cpp b/src/mongo/db/repl/oplog.cpp index 5b3d48fbc21..26708ee8de7 100644 --- a/src/mongo/db/repl/oplog.cpp +++ b/src/mongo/db/repl/oplog.cpp @@ -103,7 +103,7 @@ namespace { // Synchronizes the section where a new Timestamp is generated and when it actually // appears in the oplog. - mongo::mutex newOpMutex; + stdx::mutex newOpMutex; stdx::condition_variable newTimestampNotifier; static std::string _oplogCollectionName; diff --git a/src/mongo/db/repl/sync_tail.cpp b/src/mongo/db/repl/sync_tail.cpp index 545dea83f9d..2bfe05728fe 100644 --- a/src/mongo/db/repl/sync_tail.cpp +++ b/src/mongo/db/repl/sync_tail.cpp @@ -365,7 +365,7 @@ namespace { // We must grab this because we're going to grab write locks later. // We hold this mutex the entire time we're writing; it doesn't matter // because all readers are blocked anyway. - SimpleMutex::scoped_lock fsynclk(filesLockedFsync); + stdx::lock_guard<SimpleMutex> fsynclk(filesLockedFsync); // stop all readers until we're done Lock::ParallelBatchWriterMode pbwm(txn->lockState()); diff --git a/src/mongo/db/stats/snapshots.h b/src/mongo/db/stats/snapshots.h index 9c29e7d5eb6..6f3b90e0cb9 100644 --- a/src/mongo/db/stats/snapshots.h +++ b/src/mongo/db/stats/snapshots.h @@ -96,7 +96,7 @@ namespace mongo { StatusWith<SnapshotDiff> computeDelta(); private: - mongo::mutex _lock; + stdx::mutex _lock; static const int kNumSnapshots = 2; SnapshotData _snapshots[kNumSnapshots]; int _loc; diff --git a/src/mongo/db/stats/top.cpp b/src/mongo/db/stats/top.cpp index af793f9401a..903378e1834 100644 --- a/src/mongo/db/stats/top.cpp +++ b/src/mongo/db/stats/top.cpp @@ -80,7 +80,7 @@ namespace { return; //cout << "record: " << ns << "\t" << op << "\t" << command << endl; - SimpleMutex::scoped_lock lk(_lock); + stdx::lock_guard<SimpleMutex> lk(_lock); if ( ( command || op == dbQuery ) && ns == _lastDropped ) { _lastDropped = ""; @@ -138,18 +138,18 @@ namespace { } void Top::collectionDropped( StringData ns ) { - SimpleMutex::scoped_lock lk(_lock); + stdx::lock_guard<SimpleMutex> lk(_lock); _usage.erase(ns); _lastDropped = ns.toString(); } void Top::cloneMap(Top::UsageMap& out) const { - SimpleMutex::scoped_lock lk(_lock); + stdx::lock_guard<SimpleMutex> lk(_lock); out = _usage; } void Top::append( BSONObjBuilder& b ) { - SimpleMutex::scoped_lock lk( _lock ); + stdx::lock_guard<SimpleMutex> lk( _lock ); _appendToUsageMap( b, _usage ); } diff --git a/src/mongo/db/stats/top.h b/src/mongo/db/stats/top.h index 8d5c4919f03..d71605e8ef4 100644 --- a/src/mongo/db/stats/top.h +++ b/src/mongo/db/stats/top.h @@ -46,7 +46,7 @@ namespace mongo { public: static Top& get(ServiceContext* service); - Top() : _lock("Top") { } + Top() = default; struct UsageData { UsageData() : time(0), count(0) {} diff --git a/src/mongo/db/storage/mmap_v1/dur.cpp b/src/mongo/db/storage/mmap_v1/dur.cpp index ec76e172bc5..a596bba061f 100644 --- a/src/mongo/db/storage/mmap_v1/dur.cpp +++ b/src/mongo/db/storage/mmap_v1/dur.cpp @@ -534,7 +534,7 @@ namespace { void DurableImpl::declareWriteIntents( const std::vector<std::pair<void*, unsigned> >& intents) { typedef std::vector<std::pair<void*, unsigned> > Intents; - SimpleMutex::scoped_lock lk(commitJob.groupCommitMutex); + stdx::lock_guard<SimpleMutex> lk(commitJob.groupCommitMutex); for (Intents::const_iterator it(intents.begin()), end(intents.end()); it != end; ++it) { commitJob.note(it->first, it->second); } diff --git a/src/mongo/db/storage/mmap_v1/dur_commitjob.cpp b/src/mongo/db/storage/mmap_v1/dur_commitjob.cpp index 666a6c4a2eb..27e7681b17c 100644 --- a/src/mongo/db/storage/mmap_v1/dur_commitjob.cpp +++ b/src/mongo/db/storage/mmap_v1/dur_commitjob.cpp @@ -63,7 +63,6 @@ namespace dur { CommitJob::CommitJob() : - groupCommitMutex("groupCommit"), _hasWritten(false), _lastNotedPos(0), _bytes(0) { @@ -75,7 +74,7 @@ namespace dur { } void CommitJob::noteOp(shared_ptr<DurOp> p) { - SimpleMutex::scoped_lock lk(groupCommitMutex); + stdx::lock_guard<SimpleMutex> lk(groupCommitMutex); _hasWritten = true; _durOps.push_back(p); } diff --git a/src/mongo/db/storage/mmap_v1/dur_journal.cpp b/src/mongo/db/storage/mmap_v1/dur_journal.cpp index 8eeb229d5bc..a76ade46128 100644 --- a/src/mongo/db/storage/mmap_v1/dur_journal.cpp +++ b/src/mongo/db/storage/mmap_v1/dur_journal.cpp @@ -160,7 +160,7 @@ namespace mongo { namespace { SecureRandom* mySecureRandom = NULL; - mongo::mutex mySecureRandomMutex; + stdx::mutex mySecureRandomMutex; int64_t getMySecureRandomNumber() { stdx::lock_guard<stdx::mutex> lk( mySecureRandomMutex ); if ( ! mySecureRandom ) @@ -190,8 +190,7 @@ namespace mongo { const unsigned long long LsnShutdownSentinel = ~((unsigned long long)0); - Journal::Journal() : - _curLogFileMutex("JournalLfMutex") { + Journal::Journal() { _written = 0; _nextFileNumber = 0; _curLogFile = 0; @@ -280,7 +279,7 @@ namespace mongo { if( _log ) log() << "journalCleanup..." << endl; try { - SimpleMutex::scoped_lock lk(_curLogFileMutex); + stdx::lock_guard<SimpleMutex> lk(_curLogFileMutex); closeCurrentJournalFile(); removeJournalFiles(); } @@ -561,7 +560,7 @@ namespace mongo { void Journal::open() { verify( MongoFile::notifyPreFlush == preFlush ); - SimpleMutex::scoped_lock lk(_curLogFileMutex); + stdx::lock_guard<SimpleMutex> lk(_curLogFileMutex); _open(); } @@ -694,8 +693,6 @@ namespace mongo { void Journal::_rotate() { - _curLogFileMutex.dassertLocked(); - if ( inShutdown() || !_curLogFile ) return; @@ -777,7 +774,7 @@ namespace mongo { } try { - SimpleMutex::scoped_lock lk(_curLogFileMutex); + stdx::lock_guard<SimpleMutex> lk(_curLogFileMutex); // must already be open -- so that _curFileId is correct for previous buffer building verify( _curLogFile ); diff --git a/src/mongo/db/storage/mmap_v1/dur_journalimpl.h b/src/mongo/db/storage/mmap_v1/dur_journalimpl.h index 7664e1f5265..365f38aec71 100644 --- a/src/mongo/db/storage/mmap_v1/dur_journalimpl.h +++ b/src/mongo/db/storage/mmap_v1/dur_journalimpl.h @@ -65,7 +65,7 @@ namespace mongo { unsigned long long curFileId() const { return _curFileId; } void assureLogFileOpen() { - SimpleMutex::scoped_lock lk(_curLogFileMutex); + stdx::lock_guard<SimpleMutex> lk(_curLogFileMutex); if( _curLogFile == 0 ) _open(); } diff --git a/src/mongo/db/storage/mmap_v1/dur_recover.h b/src/mongo/db/storage/mmap_v1/dur_recover.h index 1e22a693ed6..886f278a66a 100644 --- a/src/mongo/db/storage/mmap_v1/dur_recover.h +++ b/src/mongo/db/storage/mmap_v1/dur_recover.h @@ -85,7 +85,7 @@ namespace mongo { // Set of memory mapped files and a mutex to protect them - mongo::mutex _mx; + stdx::mutex _mx; std::list<std::shared_ptr<DurableMappedFile> > _mmfs; // Are we in recovery or WRITETODATAFILES diff --git a/src/mongo/db/storage/mmap_v1/durable_mapped_file.cpp b/src/mongo/db/storage/mmap_v1/durable_mapped_file.cpp index e78c29281c7..e32c0b15ffe 100644 --- a/src/mongo/db/storage/mmap_v1/durable_mapped_file.cpp +++ b/src/mongo/db/storage/mmap_v1/durable_mapped_file.cpp @@ -107,7 +107,7 @@ namespace mongo { } } - extern mutex mapViewMutex; + extern stdx::mutex mapViewMutex; __declspec(noinline) void PointerToDurableMappedFile::makeChunkWritable(size_t chunkno) { stdx::lock_guard<stdx::mutex> lkPrivateViews(_m); diff --git a/src/mongo/db/storage/mmap_v1/durable_mapped_file.h b/src/mongo/db/storage/mmap_v1/durable_mapped_file.h index 0ebbd9dd7c9..c4cfb5a6131 100644 --- a/src/mongo/db/storage/mmap_v1/durable_mapped_file.h +++ b/src/mongo/db/storage/mmap_v1/durable_mapped_file.h @@ -33,6 +33,7 @@ #include "mongo/db/storage/mmap_v1/mmap.h" #include "mongo/db/storage/paths.h" +#include "mongo/stdx/mutex.h" namespace mongo { @@ -197,7 +198,7 @@ namespace mongo { DurableMappedFile* find(void *p, /*out*/ size_t& ofs); /** for doing many finds in a row with one lock operation */ - mutex& _mutex() { return _m; } + stdx::mutex& _mutex() { return _m; } /** not-threadsafe, caller must hold _mutex() */ DurableMappedFile* find_inlock(void *p, /*out*/ size_t& ofs); @@ -224,7 +225,7 @@ namespace mongo { // Protects internal consistency of data structure // Lock Ordering: // Must be taken before MapViewMutex if both are taken to prevent deadlocks - mutex _m; + stdx::mutex _m; std::map<void*, DurableMappedFile*> _views; #ifdef _WIN32 diff --git a/src/mongo/db/storage/mmap_v1/file_allocator.cpp b/src/mongo/db/storage/mmap_v1/file_allocator.cpp index f785fa2a456..bedd7d9e03d 100644 --- a/src/mongo/db/storage/mmap_v1/file_allocator.cpp +++ b/src/mongo/db/storage/mmap_v1/file_allocator.cpp @@ -78,7 +78,7 @@ namespace mongo { // unique number for temporary file names unsigned long long FileAllocator::_uniqueNumber = 0; - static SimpleMutex _uniqueNumberMutex( "uniqueNumberMutex" ); + static SimpleMutex _uniqueNumberMutex; MONGO_FP_DECLARE(allocateDiskFull); @@ -336,7 +336,7 @@ namespace mongo { { // increment temporary file name counter // TODO: SERVER-6055 -- Unify temporary file name selection - SimpleMutex::scoped_lock lk(_uniqueNumberMutex); + stdx::lock_guard<SimpleMutex> lk(_uniqueNumberMutex); thisUniqueNumber = _uniqueNumber; ++_uniqueNumber; } @@ -354,7 +354,7 @@ namespace mongo { { // initialize unique temporary file name counter // TODO: SERVER-6055 -- Unify temporary file name selection - SimpleMutex::scoped_lock lk(_uniqueNumberMutex); + stdx::lock_guard<SimpleMutex> lk(_uniqueNumberMutex); _uniqueNumber = curTimeMicros64(); } while( 1 ) { diff --git a/src/mongo/db/storage/mmap_v1/file_allocator.h b/src/mongo/db/storage/mmap_v1/file_allocator.h index d42850f1aa0..d3f9b6cceda 100644 --- a/src/mongo/db/storage/mmap_v1/file_allocator.h +++ b/src/mongo/db/storage/mmap_v1/file_allocator.h @@ -91,7 +91,7 @@ namespace mongo { // generate a unique name for temporary files std::string makeTempFileName( boost::filesystem::path root ); - mutable mongo::mutex _pendingMutex; + mutable stdx::mutex _pendingMutex; mutable stdx::condition_variable _pendingUpdated; std::list< std::string > _pending; diff --git a/src/mongo/db/storage/mmap_v1/mmap_v1_extent_manager.h b/src/mongo/db/storage/mmap_v1/mmap_v1_extent_manager.h index c2343205dc9..8253d0f87a3 100644 --- a/src/mongo/db/storage/mmap_v1/mmap_v1_extent_manager.h +++ b/src/mongo/db/storage/mmap_v1/mmap_v1_extent_manager.h @@ -41,7 +41,7 @@ #include "mongo/db/storage/mmap_v1/extent_manager.h" #include "mongo/db/storage/mmap_v1/record_access_tracker.h" #include "mongo/platform/atomic_word.h" -#include "mongo/util/concurrency/mutex.h" +#include "mongo/stdx/mutex.h" namespace mongo { @@ -238,7 +238,7 @@ namespace mongo { void push_back(DataFile* val); private: - mutex _writersMutex; + stdx::mutex _writersMutex; AtomicInt32 _size; // number of files in the array DataFile* _files[DiskLoc::MaxFiles]; }; diff --git a/src/mongo/db/storage/mmap_v1/mmap_windows.cpp b/src/mongo/db/storage/mmap_v1/mmap_windows.cpp index 2b57dc4672b..2969028575a 100644 --- a/src/mongo/db/storage/mmap_v1/mmap_windows.cpp +++ b/src/mongo/db/storage/mmap_v1/mmap_windows.cpp @@ -35,6 +35,7 @@ #include "mongo/db/storage/mmap_v1/durable_mapped_file.h" #include "mongo/db/storage/mmap_v1/file_allocator.h" +#include "mongo/stdx/mutex.h" #include "mongo/util/log.h" #include "mongo/util/processinfo.h" #include "mongo/util/text.h" @@ -69,7 +70,7 @@ namespace mongo { // 2. Prevents calls to VirtualProtect while we remapping files. // Lock Ordering: // - If taken, must be after previewViews._m to prevent deadlocks - mutex mapViewMutex; + stdx::mutex mapViewMutex; MAdvise::MAdvise(void *,unsigned, Advice) { } MAdvise::~MAdvise() { } @@ -84,7 +85,7 @@ namespace mongo { // placing memory mapped files in memory // Lock Ordering: // No restrictions - static SimpleMutex _nextMemoryMappedFileLocationMutex("nextMemoryMappedFileLocationMutex"); + static SimpleMutex _nextMemoryMappedFileLocationMutex; unsigned long long AlignNumber(unsigned long long number, unsigned long long granularity) { @@ -95,7 +96,7 @@ namespace mongo { if (4 == sizeof(void*)) { return 0; } - SimpleMutex::scoped_lock lk(_nextMemoryMappedFileLocationMutex); + stdx::lock_guard<SimpleMutex> lk(_nextMemoryMappedFileLocationMutex); static unsigned long long granularity = 0; @@ -359,7 +360,7 @@ namespace mongo { return view; } - extern mutex mapViewMutex; + extern stdx::mutex mapViewMutex; void* MemoryMappedFile::createPrivateMap() { verify( maphandle ); diff --git a/src/mongo/db/storage/mmap_v1/record_access_tracker.cpp b/src/mongo/db/storage/mmap_v1/record_access_tracker.cpp index d0ca6887127..ab77ad69b08 100644 --- a/src/mongo/db/storage/mmap_v1/record_access_tracker.cpp +++ b/src/mongo/db/storage/mmap_v1/record_access_tracker.cpp @@ -227,8 +227,7 @@ namespace mongo { // Rolling // - RecordAccessTracker::Rolling::Rolling() - : _lock( "ps::Rolling" ){ + RecordAccessTracker::Rolling::Rolling() { _curSlice = 0; _lastRotate = Listener::getElapsedTimeMillis(); } @@ -236,7 +235,7 @@ namespace mongo { bool RecordAccessTracker::Rolling::access(size_t region, short offset, bool doHalf) { int regionHash = hash(region); - SimpleMutex::scoped_lock lk(_lock); + stdx::lock_guard<SimpleMutex> lk(_lock); static int rarelyCount = 0; if (rarelyCount++ % (2048 / BigHashSize) == 0) { diff --git a/src/mongo/dbtests/dbtests.cpp b/src/mongo/dbtests/dbtests.cpp index c6727922ae6..f094709d471 100644 --- a/src/mongo/dbtests/dbtests.cpp +++ b/src/mongo/dbtests/dbtests.cpp @@ -48,6 +48,7 @@ #include "mongo/util/quick_exit.h" #include "mongo/util/signal_handlers_synchronous.h" #include "mongo/util/startup_test.h" +#include "mongo/util/static_observer.h" #include "mongo/util/text.h" namespace mongo { diff --git a/src/mongo/dbtests/documentsourcetests.cpp b/src/mongo/dbtests/documentsourcetests.cpp index e31ab3aa0e0..7eff2147b44 100644 --- a/src/mongo/dbtests/documentsourcetests.cpp +++ b/src/mongo/dbtests/documentsourcetests.cpp @@ -298,7 +298,7 @@ namespace DocumentSourceTests { } private: int _value; - mutable mongo::mutex _mutex; + mutable stdx::mutex _mutex; mutable stdx::condition_variable _condition; }; diff --git a/src/mongo/dbtests/framework.cpp b/src/mongo/dbtests/framework.cpp index dab30d47f74..d91e7012cea 100644 --- a/src/mongo/dbtests/framework.cpp +++ b/src/mongo/dbtests/framework.cpp @@ -50,9 +50,9 @@ #include "mongo/s/d_state.h" #include "mongo/s/grid.h" #include "mongo/s/catalog/legacy/legacy_dist_lock_manager.h" +#include "mongo/stdx/mutex.h" #include "mongo/util/assert_util.h" #include "mongo/util/background.h" -#include "mongo/util/concurrency/mutex.h" #include "mongo/util/exit.h" #include "mongo/util/log.h" #include "mongo/util/version.h" @@ -66,7 +66,7 @@ namespace mongo { namespace dbtests { - mutex globalCurrentTestNameMutex; + stdx::mutex globalCurrentTestNameMutex; std::string globalCurrentTestName; class TestWatchDog : public BackgroundJob { diff --git a/src/mongo/dbtests/mock/mock_conn_registry.h b/src/mongo/dbtests/mock/mock_conn_registry.h index a4177ae5592..6822df4b57e 100644 --- a/src/mongo/dbtests/mock/mock_conn_registry.h +++ b/src/mongo/dbtests/mock/mock_conn_registry.h @@ -115,7 +115,7 @@ namespace mongo { MockConnHook _mockConnStrHook; // protects _registry - mongo::mutex _registryMutex; + stdx::mutex _registryMutex; unordered_map<std::string, MockRemoteDBServer*> _registry; }; } diff --git a/src/mongo/dbtests/perftests.cpp b/src/mongo/dbtests/perftests.cpp index 8eec55fe913..ba0004926b7 100644 --- a/src/mongo/dbtests/perftests.cpp +++ b/src/mongo/dbtests/perftests.cpp @@ -536,7 +536,7 @@ namespace PerfTests { #endif RWLock lk("testrw"); - SimpleMutex m("simptst"); + SimpleMutex m; boost::mutex mboost; boost::timed_mutex mboost_timed; std::mutex mstd; @@ -577,7 +577,7 @@ namespace PerfTests { virtual int howLongMillis() { return 500; } virtual bool showDurStats() { return false; } void timed() { - SimpleMutex::scoped_lock lk(m); + stdx::lock_guard<SimpleMutex> lk(m); } }; diff --git a/src/mongo/dbtests/threadedtests.cpp b/src/mongo/dbtests/threadedtests.cpp index 4f714dd4a10..e8af4c8fdd5 100644 --- a/src/mongo/dbtests/threadedtests.cpp +++ b/src/mongo/dbtests/threadedtests.cpp @@ -591,7 +591,7 @@ namespace ThreadedTests { template <class whichmutex, class scoped> class Slack : public ThreadedTest<17> { public: - Slack() : m("slack") { + Slack() { k = 0; done = false; a = b = 0; @@ -769,7 +769,7 @@ namespace ThreadedTests { verify( _checkedIn >= 0 ); } - mongo::mutex _frontDesk; + stdx::mutex _frontDesk; int _nRooms; int _checkedIn; int _maxRooms; @@ -821,7 +821,7 @@ namespace ThreadedTests { // Slack is a test to see how long it takes for another thread to pick up // and begin work after another relinquishes the lock. e.g. a spin lock // would have very little slack. - add< Slack<SimpleMutex,SimpleMutex::scoped_lock> >(); + add< Slack<SimpleMutex,stdx::lock_guard<SimpleMutex>> >(); add< Slack<SimpleRWLock,SimpleRWLock::Exclusive> >(); add< CondSlack >(); diff --git a/src/mongo/logger/ramlog.cpp b/src/mongo/logger/ramlog.cpp index 30e623983d6..dd2ea4ecc04 100644 --- a/src/mongo/logger/ramlog.cpp +++ b/src/mongo/logger/ramlog.cpp @@ -44,7 +44,7 @@ namespace mongo { namespace { typedef std::map<string,RamLog*> RM; - mongo::mutex* _namedLock = NULL; + stdx::mutex* _namedLock = NULL; RM* _named = NULL; } // namespace @@ -206,7 +206,7 @@ namespace { RamLog* RamLog::get(const std::string& name) { if (!_namedLock) { // Guaranteed to happen before multi-threaded operation. - _namedLock = new mongo::mutex(); + _namedLock = new stdx::mutex(); } stdx::lock_guard<stdx::mutex> lk( *_namedLock ); @@ -251,7 +251,7 @@ namespace { return Status(ErrorCodes::InternalError, "Inconsistent intiailization of RamLogCatalog."); } - _namedLock = new mongo::mutex(); + _namedLock = new stdx::mutex(); _named = new RM(); } diff --git a/src/mongo/s/catalog/legacy/distlock.cpp b/src/mongo/s/catalog/legacy/distlock.cpp index 692b27d4aa1..22c0a4e6128 100644 --- a/src/mongo/s/catalog/legacy/distlock.cpp +++ b/src/mongo/s/catalog/legacy/distlock.cpp @@ -31,13 +31,13 @@ #include "mongo/s/catalog/legacy/distlock.h" - #include "mongo/db/server_options.h" #include "mongo/client/dbclientcursor.h" #include "mongo/client/connpool.h" #include "mongo/s/type_locks.h" #include "mongo/s/type_lockpings.h" #include "mongo/util/concurrency/thread_name.h" +#include "mongo/util/concurrency/threadlocal.h" #include "mongo/util/log.h" #include "mongo/util/timer.h" @@ -60,11 +60,11 @@ namespace mongo { * Module initialization */ - static SimpleMutex _cachedProcessMutex("distlock_initmodule"); + static SimpleMutex _cachedProcessMutex; static string* _cachedProcessString = NULL; static void initModule() { - SimpleMutex::scoped_lock lk(_cachedProcessMutex); + stdx::lock_guard<SimpleMutex> lk(_cachedProcessMutex); if (_cachedProcessString) { // someone got the lock before us return; diff --git a/src/mongo/s/catalog/legacy/distlock.h b/src/mongo/s/catalog/legacy/distlock.h index f5adce576dd..b569080147e 100644 --- a/src/mongo/s/catalog/legacy/distlock.h +++ b/src/mongo/s/catalog/legacy/distlock.h @@ -131,7 +131,7 @@ namespace mongo { const std::string& lockName, const DistLockPingInfo& pd); - mongo::mutex _mutex; + stdx::mutex _mutex; std::map< std::pair<std::string, std::string>, DistLockPingInfo > _lastPings; }; diff --git a/src/mongo/s/catalog/legacy/legacy_dist_lock_pinger.h b/src/mongo/s/catalog/legacy/legacy_dist_lock_pinger.h index d09606c9400..777cb39314b 100644 --- a/src/mongo/s/catalog/legacy/legacy_dist_lock_pinger.h +++ b/src/mongo/s/catalog/legacy/legacy_dist_lock_pinger.h @@ -114,7 +114,7 @@ namespace mongo { // // (M) Must hold _mutex for access. - mongo::mutex _mutex; + stdx::mutex _mutex; // Triggered everytime a pinger thread is stopped. stdx::condition_variable _pingStoppedCV; // (M) diff --git a/src/mongo/s/chunk_manager_targeter.cpp b/src/mongo/s/chunk_manager_targeter.cpp index ae3e79192ef..bac563fc027 100644 --- a/src/mongo/s/chunk_manager_targeter.cpp +++ b/src/mongo/s/chunk_manager_targeter.cpp @@ -32,6 +32,8 @@ #include "mongo/s/chunk_manager_targeter.h" +#include <boost/thread/tss.hpp> + #include "mongo/s/chunk_manager.h" #include "mongo/s/client/shard_registry.h" #include "mongo/s/config.h" diff --git a/src/mongo/s/client/shard_connection.cpp b/src/mongo/s/client/shard_connection.cpp index 56d8b82ca54..226bea4fc2c 100644 --- a/src/mongo/s/client/shard_connection.cpp +++ b/src/mongo/s/client/shard_connection.cpp @@ -79,7 +79,7 @@ namespace { void appendInfo(BSONObjBuilder& b); private: - mongo::mutex _mutex; + stdx::mutex _mutex; set<const ClientConnections*> _clientConnections; } activeClientConnections; diff --git a/src/mongo/s/config.h b/src/mongo/s/config.h index e15d8e54ee0..e2216b67786 100644 --- a/src/mongo/s/config.h +++ b/src/mongo/s/config.h @@ -164,12 +164,12 @@ namespace mongo { bool _shardingEnabled; // Set of collections and lock to protect access - mongo::mutex _lock; + stdx::mutex _lock; CollectionInfoMap _collections; // Ensures that only one thread at a time loads collection configuration data from // the config server - mongo::mutex _hitConfigServerLock; + stdx::mutex _hitConfigServerLock; }; diff --git a/src/mongo/s/cursors.h b/src/mongo/s/cursors.h index c3186156628..2e0d805402e 100644 --- a/src/mongo/s/cursors.h +++ b/src/mongo/s/cursors.h @@ -128,7 +128,7 @@ namespace mongo { void doTimeouts(); void startTimeoutThread(); private: - mutable mongo::mutex _mutex; + mutable stdx::mutex _mutex; PseudoRandom _random; diff --git a/src/mongo/s/d_state.cpp b/src/mongo/s/d_state.cpp index 89c5f2d52c8..e7341e65093 100644 --- a/src/mongo/s/d_state.cpp +++ b/src/mongo/s/d_state.cpp @@ -887,7 +887,7 @@ namespace mongo { } void ShardedConnectionInfo::addHook() { - static mongo::mutex lock; + static stdx::mutex lock; static bool done = false; stdx::lock_guard<stdx::mutex> lk(lock); diff --git a/src/mongo/s/d_state.h b/src/mongo/s/d_state.h index 2337efff8a4..6bd43ce6865 100644 --- a/src/mongo/s/d_state.h +++ b/src/mongo/s/d_state.h @@ -280,7 +280,7 @@ namespace mongo { ChunkVersion* latestShardVersion ); // protects state below - mongo::mutex _mutex; + stdx::mutex _mutex; // Whether ::initialize has been called bool _enabled; diff --git a/src/mongo/s/distlock_test.cpp b/src/mongo/s/distlock_test.cpp index 46c385035dc..9b1dd3f8ab3 100644 --- a/src/mongo/s/distlock_test.cpp +++ b/src/mongo/s/distlock_test.cpp @@ -33,6 +33,7 @@ #include "mongo/s/catalog/legacy/distlock.h" +#include <boost/thread/tss.hpp> #include <iostream> #include <vector> @@ -375,7 +376,7 @@ namespace mongo { } // variables for test - thread_specific_ptr<DistributedLock> lock; + boost::thread_specific_ptr<DistributedLock> lock; AtomicUInt32 count; AtomicWord<bool> keepGoing; diff --git a/src/mongo/s/server.cpp b/src/mongo/s/server.cpp index a9c0f1857fb..092a7339d67 100644 --- a/src/mongo/s/server.cpp +++ b/src/mongo/s/server.cpp @@ -85,6 +85,7 @@ #include "mongo/util/quick_exit.h" #include "mongo/util/signal_handlers.h" #include "mongo/util/stacktrace.h" +#include "mongo/util/static_observer.h" #include "mongo/util/stringutils.h" #include "mongo/util/text.h" #include "mongo/util/version.h" diff --git a/src/mongo/s/version_manager.cpp b/src/mongo/s/version_manager.cpp index 16010d01c9e..ad96e57b3b7 100644 --- a/src/mongo/s/version_manager.cpp +++ b/src/mongo/s/version_manager.cpp @@ -103,7 +103,7 @@ namespace mongo { } // protects _map - mongo::mutex _mutex; + stdx::mutex _mutex; // a map from a connection into ChunkManager's sequence number for each namespace typedef map<unsigned long long, map<string,unsigned long long> > SequenceMap; diff --git a/src/mongo/scripting/engine.cpp b/src/mongo/scripting/engine.cpp index 6c104b50339..36c9104388a 100644 --- a/src/mongo/scripting/engine.cpp +++ b/src/mongo/scripting/engine.cpp @@ -367,7 +367,7 @@ namespace { typedef std::deque<ScopeAndPool> Pools; // More-recently used Scopes are kept at the front. Pools _pools; // protected by _mutex - mongo::mutex _mutex; + stdx::mutex _mutex; }; ScopeCache scopeCache; diff --git a/src/mongo/scripting/engine_v8-3.25.h b/src/mongo/scripting/engine_v8-3.25.h index efe100ac776..4c7f0507efe 100644 --- a/src/mongo/scripting/engine_v8-3.25.h +++ b/src/mongo/scripting/engine_v8-3.25.h @@ -514,7 +514,7 @@ namespace mongo { typedef unordered_map<const char*, v8::Eternal<v8::String> > StrLitMap; StrLitMap _strLitMap; - mongo::mutex _interruptLock; // protects interruption-related flags + stdx::mutex _interruptLock; // protects interruption-related flags bool _inNativeExecution; // protected by _interruptLock bool _pendingKill; // protected by _interruptLock unsigned int _opId; // op id for this scope @@ -563,7 +563,7 @@ namespace mongo { DeadlineMonitor<V8Scope>* getDeadlineMonitor() { return &_deadlineMonitor; } typedef std::map<unsigned, V8Scope*> OpIdToScopeMap; - mongo::mutex _globalInterruptLock; // protects map of all operation ids -> scope + stdx::mutex _globalInterruptLock; // protects map of all operation ids -> scope OpIdToScopeMap _opToScopeMap; // map of mongo op ids to scopes (protected by // _globalInterruptLock). DeadlineMonitor<V8Scope> _deadlineMonitor; diff --git a/src/mongo/scripting/engine_v8.h b/src/mongo/scripting/engine_v8.h index 6c3b482aea3..ae4f8f4c04d 100644 --- a/src/mongo/scripting/engine_v8.h +++ b/src/mongo/scripting/engine_v8.h @@ -494,7 +494,7 @@ namespace mongo { typedef unordered_map<const char*, v8::Handle<v8::String> > StrLitMap; StrLitMap _strLitMap; - mongo::mutex _interruptLock; // protects interruption-related flags + stdx::mutex _interruptLock; // protects interruption-related flags bool _inNativeExecution; // protected by _interruptLock bool _pendingKill; // protected by _interruptLock unsigned int _opId; // op id for this scope @@ -540,7 +540,7 @@ namespace mongo { DeadlineMonitor<V8Scope>* getDeadlineMonitor() { return &_deadlineMonitor; } typedef std::map<unsigned, V8Scope*> OpIdToScopeMap; - mongo::mutex _globalInterruptLock; // protects map of all operation ids -> scope + stdx::mutex _globalInterruptLock; // protects map of all operation ids -> scope OpIdToScopeMap _opToScopeMap; // map of mongo op ids to scopes (protected by // _globalInterruptLock). DeadlineMonitor<V8Scope> _deadlineMonitor; diff --git a/src/mongo/scripting/v8_deadline_monitor_test.cpp b/src/mongo/scripting/v8_deadline_monitor_test.cpp index e9424431911..516a772fbd6 100644 --- a/src/mongo/scripting/v8_deadline_monitor_test.cpp +++ b/src/mongo/scripting/v8_deadline_monitor_test.cpp @@ -56,7 +56,7 @@ namespace mongo { _c.wait(lk); } private: - mongo::mutex _m; + stdx::mutex _m; stdx::condition_variable _c; uint64_t _killCount; uint64_t _targetKillCount; diff --git a/src/mongo/shell/dbshell.cpp b/src/mongo/shell/dbshell.cpp index 14ec8b3fb2c..aa161945e0d 100644 --- a/src/mongo/shell/dbshell.cpp +++ b/src/mongo/shell/dbshell.cpp @@ -63,6 +63,7 @@ #include "mongo/util/signal_handlers.h" #include "mongo/util/stacktrace.h" #include "mongo/util/startup_test.h" +#include "mongo/util/static_observer.h" #include "mongo/util/text.h" #include "mongo/util/version.h" diff --git a/src/mongo/shell/shell_utils.cpp b/src/mongo/shell/shell_utils.cpp index 0b5c78376ae..b70146559de 100644 --- a/src/mongo/shell/shell_utils.cpp +++ b/src/mongo/shell/shell_utils.cpp @@ -40,6 +40,7 @@ #include "mongo/shell/shell_options.h" #include "mongo/shell/shell_utils_extended.h" #include "mongo/shell/shell_utils_launcher.h" +#include "mongo/util/concurrency/threadlocal.h" #include "mongo/util/processinfo.h" #include "mongo/util/quick_exit.h" #include "mongo/util/text.h" @@ -371,6 +372,6 @@ namespace mongo { } - mongo::mutex &mongoProgramOutputMutex(*(new stdx::mutex())); + stdx::mutex &mongoProgramOutputMutex(*(new stdx::mutex())); } } diff --git a/src/mongo/shell/shell_utils.h b/src/mongo/shell/shell_utils.h index 88ba5235013..ee773e9e029 100644 --- a/src/mongo/shell/shell_utils.h +++ b/src/mongo/shell/shell_utils.h @@ -74,7 +74,7 @@ namespace mongo { void killOperationsOnAllConnections( bool withPrompt ) const; private: std::map<std::string,std::set<std::string> > _connectionUris; - mutable mongo::mutex _mutex; + mutable stdx::mutex _mutex; }; extern ConnectionRegistry connectionRegistry; diff --git a/src/mongo/tools/bridge.cpp b/src/mongo/tools/bridge.cpp index 2114dbc72c3..bd8882c4dfc 100644 --- a/src/mongo/tools/bridge.cpp +++ b/src/mongo/tools/bridge.cpp @@ -43,6 +43,7 @@ #include "mongo/util/net/message.h" #include "mongo/util/quick_exit.h" #include "mongo/util/stacktrace.h" +#include "mongo/util/static_observer.h" #include "mongo/util/text.h" #include "mongo/util/timer.h" diff --git a/src/mongo/util/SConscript b/src/mongo/util/SConscript index bc6e9b0d9bd..08f66f615b0 100644 --- a/src/mongo/util/SConscript +++ b/src/mongo/util/SConscript @@ -100,11 +100,11 @@ env.Library( "startup_test.cpp", "touch_pages.cpp", 'assert_util.cpp', - 'concurrency/mutex.cpp', 'exception_filter_win32.cpp', 'file.cpp', 'log.cpp', 'platform_init.cpp', + 'static_observer.cpp', 'system_tick_source.cpp', 'text.cpp', 'thread_safe_string.cpp', diff --git a/src/mongo/util/background.cpp b/src/mongo/util/background.cpp index a7ee913defe..52147e923aa 100644 --- a/src/mongo/util/background.cpp +++ b/src/mongo/util/background.cpp @@ -105,7 +105,7 @@ namespace mongo { // completed. In the former case, we assume no threads are present, so we do not need // to use the mutex. When present, the mutex protects 'runner' and 'runnerDestroyed' // below. - SimpleMutex* const runnerMutex = new SimpleMutex("PeriodicTaskRunner"); + SimpleMutex* const runnerMutex = new SimpleMutex; // A scoped lock like object that only locks/unlocks the mutex if it exists. class ConditionalScopedLock { diff --git a/src/mongo/util/background_job_test.cpp b/src/mongo/util/background_job_test.cpp index 8d3ca7cd356..c13ff444625 100644 --- a/src/mongo/util/background_job_test.cpp +++ b/src/mongo/util/background_job_test.cpp @@ -28,10 +28,10 @@ #include "mongo/platform/basic.h" #include "mongo/db/server_options.h" +#include "mongo/stdx/mutex.h" #include "mongo/stdx/thread.h" #include "mongo/unittest/unittest.h" #include "mongo/util/background.h" -#include "mongo/util/concurrency/mutex.h" #include "mongo/util/concurrency/synchronization.h" #include "mongo/util/time_support.h" @@ -39,7 +39,7 @@ namespace { using mongo::BackgroundJob; using mongo::MsgAssertionException; - using mongo::mutex; + using mongo::stdx::mutex; using mongo::Notification; namespace stdx = mongo::stdx; diff --git a/src/mongo/util/concurrency/mapsf.h b/src/mongo/util/concurrency/mapsf.h index 27e9272f9e7..6aa6617e229 100644 --- a/src/mongo/util/concurrency/mapsf.h +++ b/src/mongo/util/concurrency/mapsf.h @@ -65,16 +65,16 @@ namespace mongo { mapsf() : m("mapsf") { } void swap(M& rhs) { - SimpleMutex::scoped_lock lk(m); + stdx::lock_guard<SimpleMutex> lk(m); val.swap(rhs); } bool empty() { - SimpleMutex::scoped_lock lk(m); + stdx::lock_guard<SimpleMutex> lk(m); return val.empty(); } // safe as we pass by value: mapped_type get(key_type k) { - SimpleMutex::scoped_lock lk(m); + stdx::lock_guard<SimpleMutex> lk(m); const_iterator i = val.find(k); if( i == val.end() ) return mapped_type(); @@ -83,7 +83,7 @@ namespace mongo { // think about deadlocks when using ref. the other methods // above will always be safe as they are "leaf" operations. struct ref { - SimpleMutex::scoped_lock lk; + stdx::lock_guard<SimpleMutex> lk; public: M &r; ref(mapsf &m) : lk(m.m), r(m.val) { } diff --git a/src/mongo/util/concurrency/mutex.h b/src/mongo/util/concurrency/mutex.h index 1d676384311..1e21f81f392 100644 --- a/src/mongo/util/concurrency/mutex.h +++ b/src/mongo/util/concurrency/mutex.h @@ -33,111 +33,69 @@ #include "mongo/platform/windows_basic.h" #endif -#include "mongo/stdx/mutex.h" #include "mongo/util/assert_util.h" -#include "mongo/util/concurrency/threadlocal.h" +#include "mongo/util/static_observer.h" namespace mongo { - // 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 { - MONGO_DISALLOW_COPYING(StaticObserver); - public: - static bool _destroyingStatics; - StaticObserver() = default; - ~StaticObserver() { _destroyingStatics = true; } - }; - - using mutex = stdx::mutex; - - /** The concept with SimpleMutex is that it is a basic lock/unlock with no - special functionality (such as try and try timeout). Thus it can be - implemented using OS-specific facilities in all environments (if desired). - On Windows, the implementation below is faster than boost mutex. + /** The concept with SimpleMutex is that it is a basic lock/unlock + * with no special functionality (such as try and try + * timeout). Thus it can be implemented using OS-specific + * facilities in all environments (if desired). On Windows, + * the implementation below is faster than boost mutex. */ #if defined(_WIN32) + class SimpleMutex { MONGO_DISALLOW_COPYING(SimpleMutex); public: - SimpleMutex( StringData ) { InitializeCriticalSection( &_cs ); } + SimpleMutex() { + InitializeCriticalSection( &_cs ); + } + ~SimpleMutex() { if ( ! StaticObserver::_destroyingStatics ) { DeleteCriticalSection(&_cs); } } - void dassertLocked() const { } - void lock() { EnterCriticalSection( &_cs ); } - void unlock() { LeaveCriticalSection( &_cs ); } - class scoped_lock { - SimpleMutex& _m; - public: - scoped_lock( SimpleMutex &m ) : _m(m) { _m.lock(); } - ~scoped_lock() { _m.unlock(); } - const SimpleMutex& m() const { return _m; } - }; + + void lock() { + EnterCriticalSection( &_cs ); + } + void unlock() { + LeaveCriticalSection( &_cs ); + } private: CRITICAL_SECTION _cs; }; + #else + class SimpleMutex { MONGO_DISALLOW_COPYING(SimpleMutex); public: - void dassertLocked() const { } - SimpleMutex(StringData name) { verify( pthread_mutex_init(&_lock,0) == 0 ); } - ~SimpleMutex(){ + SimpleMutex() { + verify( pthread_mutex_init(&_lock,0) == 0 ); + } + + ~SimpleMutex() { if ( ! StaticObserver::_destroyingStatics ) { verify( pthread_mutex_destroy(&_lock) == 0 ); } } - void lock() { verify( pthread_mutex_lock(&_lock) == 0 ); } - void unlock() { verify( pthread_mutex_unlock(&_lock) == 0 ); } - public: - class scoped_lock { - MONGO_DISALLOW_COPYING(scoped_lock); - SimpleMutex& _m; - public: - scoped_lock( SimpleMutex &m ) : _m(m) { _m.lock(); } - ~scoped_lock() { _m.unlock(); } - const SimpleMutex& m() const { return _m; } - }; + void lock() { + verify( pthread_mutex_lock(&_lock) == 0 ); + } + + void unlock() { + verify( pthread_mutex_unlock(&_lock) == 0 ); + } private: pthread_mutex_t _lock; }; #endif - /** This can be used instead of boost recursive mutex. The advantage is the debug checks - * and ability to assertLocked(). This has not yet been tested for speed vs. the boost one. - */ - class RecursiveMutex { - MONGO_DISALLOW_COPYING(RecursiveMutex); - public: - RecursiveMutex(StringData name) : m(name) { } - bool isLocked() const { return n.get() > 0; } - class scoped_lock { - MONGO_DISALLOW_COPYING(scoped_lock); - - RecursiveMutex& rm; - int& nLocksByMe; - public: - scoped_lock( RecursiveMutex &m ) : rm(m), nLocksByMe(rm.n.getRef()) { - if( nLocksByMe++ == 0 ) - rm.m.lock(); - } - ~scoped_lock() { - verify( nLocksByMe > 0 ); - if( --nLocksByMe == 0 ) { - rm.m.unlock(); - } - } - }; - private: - SimpleMutex m; - ThreadLocalValue<int> n; - }; - -} +} // namespace mongo diff --git a/src/mongo/util/concurrency/rwlock.h b/src/mongo/util/concurrency/rwlock.h index bb9426a68f3..22373efd421 100644 --- a/src/mongo/util/concurrency/rwlock.h +++ b/src/mongo/util/concurrency/rwlock.h @@ -33,6 +33,7 @@ #include "mongo/util/concurrency/mutex.h" #include "mongo/util/concurrency/rwlockimpl.h" #include "mongo/util/concurrency/simplerwlock.h" +#include "mongo/util/concurrency/threadlocal.h" #include "mongo/util/debug_util.h" #include "mongo/util/time_support.h" diff --git a/src/mongo/util/concurrency/simplerwlock.h b/src/mongo/util/concurrency/simplerwlock.h index ceee67f50b2..8a8b3171ec9 100644 --- a/src/mongo/util/concurrency/simplerwlock.h +++ b/src/mongo/util/concurrency/simplerwlock.h @@ -31,6 +31,7 @@ #include "mongo/base/string_data.h" #include "mongo/config.h" #include "mongo/platform/atomic_word.h" +#include "mongo/util/concurrency/threadlocal.h" namespace mongo { diff --git a/src/mongo/util/concurrency/synchronization.h b/src/mongo/util/concurrency/synchronization.h index e8c604ad244..b89320bb8c6 100644 --- a/src/mongo/util/concurrency/synchronization.h +++ b/src/mongo/util/concurrency/synchronization.h @@ -78,7 +78,7 @@ namespace mongo { void notifyOne(); private: - mongo::mutex _mutex; // protects state below + stdx::mutex _mutex; // protects state below unsigned long long lookFor; unsigned long long cur; stdx::condition_variable _condition; // cond over _notified being true @@ -111,7 +111,7 @@ namespace mongo { unsigned nWaiting() const { return _nWaiting; } private: - mongo::mutex _mutex; + stdx::mutex _mutex; stdx::condition_variable _condition; When _lastDone; When _lastReturned; diff --git a/src/mongo/util/net/message_port.cpp b/src/mongo/util/net/message_port.cpp index f35a4883d0d..b4e062456c9 100644 --- a/src/mongo/util/net/message_port.cpp +++ b/src/mongo/util/net/message_port.cpp @@ -113,7 +113,7 @@ namespace mongo { class Ports { std::set<MessagingPort*> ports; - mongo::mutex m; + stdx::mutex m; public: Ports() : ports() {} void closeAll(unsigned skip_mask) { diff --git a/src/mongo/util/net/ssl_manager.cpp b/src/mongo/util/net/ssl_manager.cpp index b2f1df6aa1f..be5165b97b8 100644 --- a/src/mongo/util/net/ssl_manager.cpp +++ b/src/mongo/util/net/ssl_manager.cpp @@ -153,7 +153,7 @@ namespace mongo { //////////////////////////////////////////////////////////////// - SimpleMutex sslManagerMtx("SSL Manager"); + SimpleMutex sslManagerMtx; SSLManagerInterface* theSSLManager = NULL; static const int BUFFER_SIZE = 8*1024; static const int DATE_LEN = 128; @@ -323,7 +323,7 @@ namespace mongo { MONGO_INITIALIZER_WITH_PREREQUISITES(SSLManager, ("SetupOpenSSL")) (InitializerContext*) { - SimpleMutex::scoped_lock lck(sslManagerMtx); + stdx::lock_guard<SimpleMutex> lck(sslManagerMtx); if (sslGlobalParams.sslMode.load() != SSLParams::SSLMode_disabled) { theSSLManager = new SSLManager(sslGlobalParams, isSSLServer); } @@ -336,7 +336,7 @@ namespace mongo { } SSLManagerInterface* getSSLManager() { - SimpleMutex::scoped_lock lck(sslManagerMtx); + stdx::lock_guard<SimpleMutex> lck(sslManagerMtx); if (theSSLManager) return theSSLManager; return NULL; diff --git a/src/mongo/util/processinfo.h b/src/mongo/util/processinfo.h index 367d4c5f0e4..ad0a3fbb6a7 100644 --- a/src/mongo/util/processinfo.h +++ b/src/mongo/util/processinfo.h @@ -199,7 +199,7 @@ namespace mongo { }; ProcessId _pid; - static mongo::mutex _sysInfoLock; + static stdx::mutex _sysInfoLock; static bool checkNumaEnabled(); diff --git a/src/mongo/util/stacktrace_windows.cpp b/src/mongo/util/stacktrace_windows.cpp index b11ae1d630e..e99f0c4d87a 100644 --- a/src/mongo/util/stacktrace_windows.cpp +++ b/src/mongo/util/stacktrace_windows.cpp @@ -174,7 +174,7 @@ namespace mongo { printWindowsStackTrace( context, os ); } - static SimpleMutex _stackTraceMutex( "stackTraceMutex" ); + static SimpleMutex _stackTraceMutex; /** * Print stack trace (using a specified stack context) to "os" @@ -183,7 +183,7 @@ namespace mongo { * @param os ostream& to receive printed stack backtrace */ void printWindowsStackTrace( CONTEXT& context, std::ostream& os ) { - SimpleMutex::scoped_lock lk(_stackTraceMutex); + stdx::lock_guard<SimpleMutex> lk(_stackTraceMutex); HANDLE process = GetCurrentProcess(); BOOL ret = SymInitialize(process, getSymbolSearchPath(process), TRUE); if ( ret == FALSE ) { diff --git a/src/mongo/util/concurrency/mutex.cpp b/src/mongo/util/static_observer.cpp index e881ac2272c..7ce63da0e42 100644 --- a/src/mongo/util/concurrency/mutex.cpp +++ b/src/mongo/util/static_observer.cpp @@ -28,7 +28,7 @@ #include "mongo/platform/basic.h" -#include "mongo/util/concurrency/mutex.h" +#include "mongo/util/static_observer.h" namespace mongo { diff --git a/src/mongo/util/static_observer.h b/src/mongo/util/static_observer.h new file mode 100644 index 00000000000..eec10d52437 --- /dev/null +++ b/src/mongo/util/static_observer.h @@ -0,0 +1,45 @@ +/* Copyright 2015 MongoDB Inc. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License, version 3, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * As a special exception, the copyright holders give permission to link the + * code of portions of this program with the OpenSSL library under certain + * conditions as described in each individual source file and distribute + * linked combinations including the program with the OpenSSL library. You + * must comply with the GNU Affero General Public License in all respects + * for all of the code used other than as permitted herein. If you modify + * file(s) with this exception, you may extend this exception to your + * version of the file(s), but you are not obligated to do so. If you do not + * wish to do so, delete this exception statement from your version. If you + * delete this exception statement from all source files in the program, + * then also delete it in the license file. + */ + +#pragma once + +#include "mongo/base/disallow_copying.h" + +namespace mongo { + + // 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 { + MONGO_DISALLOW_COPYING(StaticObserver); + public: + static bool _destroyingStatics; + StaticObserver() = default; + ~StaticObserver() { _destroyingStatics = true; } + }; + +} // namespace mongo diff --git a/src/mongo/util/time_support.cpp b/src/mongo/util/time_support.cpp index e72158f7e0c..7d44ce64972 100644 --- a/src/mongo/util/time_support.cpp +++ b/src/mongo/util/time_support.cpp @@ -924,8 +924,8 @@ namespace { static unsigned long long baseFiletime = 0; static unsigned long long basePerfCounter = 0; static unsigned long long resyncInterval = 0; - static SimpleMutex _curTimeMicros64ReadMutex("curTimeMicros64Read"); - static SimpleMutex _curTimeMicros64ResyncMutex("curTimeMicros64Resync"); + static SimpleMutex _curTimeMicros64ReadMutex; + static SimpleMutex _curTimeMicros64ResyncMutex; typedef WINBASEAPI VOID (WINAPI *pGetSystemTimePreciseAsFileTime) (_Out_ LPFILETIME lpSystemTimeAsFileTime); @@ -943,7 +943,7 @@ namespace { } static unsigned long long resyncTime() { - SimpleMutex::scoped_lock lkResync(_curTimeMicros64ResyncMutex); + stdx::lock_guard<SimpleMutex> lkResync(_curTimeMicros64ResyncMutex); unsigned long long ftOld; unsigned long long ftNew; ftOld = ftNew = getFiletime(); @@ -955,7 +955,7 @@ namespace { // Make sure that we use consistent values for baseFiletime and basePerfCounter. // - SimpleMutex::scoped_lock lkRead(_curTimeMicros64ReadMutex); + stdx::lock_guard<SimpleMutex> lkRead(_curTimeMicros64ReadMutex); baseFiletime = ftNew; basePerfCounter = newPerfCounter; resyncInterval = 60 * SystemTickSource::get()->getTicksPerSecond(); @@ -986,7 +986,7 @@ namespace { // Make sure that we use consistent values for baseFiletime and basePerfCounter. // - SimpleMutex::scoped_lock lkRead(_curTimeMicros64ReadMutex); + stdx::lock_guard<SimpleMutex> lkRead(_curTimeMicros64ReadMutex); // Compute the current time in FILETIME format by adding our base FILETIME and an offset // from that time based on QueryPerformanceCounter. The math is (logically) to compute the |