Skip to content

Commit

Permalink
SERVER-17310 Replace boost::*_mutex::scoped_lock with boost::lock_guard.
Browse files Browse the repository at this point in the history
Achieved via grep, sed and bash:
grep -Irl mutex::scoped_lock src/mongo | xargs sed -i.orig -E 's/(boost::(recursive_|timed_)?)mutex::scoped_lock/boost::lock_guard<\1mutex>/'

Then, by converting boost::lock_guard to boost::unique_lock as appropriate.

Finally, by removing unused mongo::mutex::try_lock.
  • Loading branch information
amschwerin committed Mar 5, 2015
1 parent ac525a4 commit 59a9a04
Show file tree
Hide file tree
Showing 36 changed files with 147 additions and 159 deletions.
22 changes: 11 additions & 11 deletions src/mongo/client/replica_set_monitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ namespace {

HostAndPort ReplicaSetMonitor::getHostOrRefresh(const ReadPreferenceSetting& criteria) {
{
boost::mutex::scoped_lock lk(_state->mutex);
boost::lock_guard<boost::mutex> lk(_state->mutex);
HostAndPort out = _state->getMatchingHost(criteria);
if (!out.empty())
return out;
Expand Down Expand Up @@ -313,35 +313,35 @@ namespace {
}

Refresher ReplicaSetMonitor::startOrContinueRefresh() {
boost::mutex::scoped_lock lk(_state->mutex);
boost::lock_guard<boost::mutex> lk(_state->mutex);

Refresher out(_state);
DEV _state->checkInvariants();
return out;
}

void ReplicaSetMonitor::failedHost(const HostAndPort& host) {
boost::mutex::scoped_lock lk(_state->mutex);
boost::lock_guard<boost::mutex> lk(_state->mutex);
Node* node = _state->findNode(host);
if (node)
node->markFailed();
DEV _state->checkInvariants();
}

bool ReplicaSetMonitor::isPrimary(const HostAndPort& host) const {
boost::mutex::scoped_lock lk(_state->mutex);
boost::lock_guard<boost::mutex> lk(_state->mutex);
Node* node = _state->findNode(host);
return node ? node->isMaster : false;
}

bool ReplicaSetMonitor::isHostUp(const HostAndPort& host) const {
boost::mutex::scoped_lock lk(_state->mutex);
boost::lock_guard<boost::mutex> lk(_state->mutex);
Node* node = _state->findNode(host);
return node ? node->isUp : false;
}

int ReplicaSetMonitor::getConsecutiveFailedScans() const {
boost::mutex::scoped_lock lk(_state->mutex);
boost::lock_guard<boost::mutex> lk(_state->mutex);
return _state->consecutiveFailedScans;
}

Expand All @@ -351,12 +351,12 @@ namespace {
}

std::string ReplicaSetMonitor::getServerAddress() const {
boost::mutex::scoped_lock lk(_state->mutex);
boost::lock_guard<boost::mutex> lk(_state->mutex);
return _state->getServerAddress();
}

bool ReplicaSetMonitor::contains(const HostAndPort& host) const {
boost::mutex::scoped_lock lk(_state->mutex);
boost::lock_guard<boost::mutex> lk(_state->mutex);
return _state->seedNodes.count(host);
}

Expand Down Expand Up @@ -413,7 +413,7 @@ namespace {
if (!clearSeedCache) {
// Save list of current set members so that the monitor can be rebuilt if needed.
const ReplicaSetMonitorPtr& rsm = setIt->second;
boost::mutex::scoped_lock lk(rsm->_state->mutex);
boost::lock_guard<boost::mutex> lk(rsm->_state->mutex);
seedServers[name] = rsm->_state->seedNodes;
}
sets.erase(setIt);
Expand All @@ -436,7 +436,7 @@ namespace {

// TODO move to correct order with non-statics before pushing
void ReplicaSetMonitor::appendInfo(BSONObjBuilder& bsonObjBuilder) const {
boost::mutex::scoped_lock lk(_state->mutex);
boost::lock_guard<boost::mutex> lk(_state->mutex);

// NOTE: the format here must be consistent for backwards compatibility
BSONArrayBuilder hosts(bsonObjBuilder.subarrayStart("hosts"));
Expand Down Expand Up @@ -746,7 +746,7 @@ namespace {
}

HostAndPort Refresher::_refreshUntilMatches(const ReadPreferenceSetting* criteria) {
boost::mutex::scoped_lock lk(_set->mutex);
boost::unique_lock<boost::mutex> lk(_set->mutex);
while (true) {
if (criteria) {
HostAndPort out = _set->getMatchingHost(*criteria);
Expand Down
4 changes: 2 additions & 2 deletions src/mongo/db/auth/internal_user_auth.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ namespace mongo {
if (!isInternalAuthSet()) {
authParamsSet = true;
}
boost::mutex::scoped_lock lk(authParamMutex);
boost::lock_guard<boost::mutex> lk(authParamMutex);

if (authParamsIn["mechanism"].String() != "SCRAM-SHA-1") {
authParams = authParamsIn.copy();
Expand All @@ -83,7 +83,7 @@ namespace mongo {
return BSONObj();
}

boost::mutex::scoped_lock lk(authParamMutex);
boost::lock_guard<boost::mutex> lk(authParamMutex);
return authParams.copy();
}

Expand Down
10 changes: 5 additions & 5 deletions src/mongo/db/background.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,12 +119,12 @@ namespace {

} // namespace
bool BackgroundOperation::inProgForDb(StringData db) {
boost::mutex::scoped_lock lk(m);
boost::lock_guard<boost::mutex> lk(m);
return dbsInProg.find(db) != dbsInProg.end();
}

bool BackgroundOperation::inProgForNs(StringData ns) {
boost::mutex::scoped_lock lk(m);
boost::lock_guard<boost::mutex> lk(m);
return nsInProg.find(ns) != nsInProg.end();
}

Expand Down Expand Up @@ -153,19 +153,19 @@ namespace {
}

BackgroundOperation::BackgroundOperation(StringData ns) : _ns(ns) {
boost::mutex::scoped_lock lk(m);
boost::lock_guard<boost::mutex> lk(m);
recordBeginAndInsert(&dbsInProg, _ns.db());
recordBeginAndInsert(&nsInProg, _ns.ns());
}

BackgroundOperation::~BackgroundOperation() {
boost::mutex::scoped_lock lk(m);
boost::lock_guard<boost::mutex> lk(m);
recordEndAndRemove(&dbsInProg, _ns.db());
recordEndAndRemove(&nsInProg, _ns.ns());
}

void BackgroundOperation::dump(std::ostream& ss) {
boost::mutex::scoped_lock lk(m);
boost::lock_guard<boost::mutex> lk(m);
if( nsInProg.size() ) {
ss << "\n<b>Background Jobs in Progress</b>\n";
for( BgInfoMapIterator i = nsInProg.begin(); i != nsInProg.end(); ++i )
Expand Down
6 changes: 3 additions & 3 deletions src/mongo/db/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ namespace {
currentClient.reset(client);

// This makes the client visible to maintenance threads
boost::mutex::scoped_lock clientLock(clientsMutex);
boost::lock_guard<boost::mutex> clientLock(clientsMutex);
clients.insert(client);
}

Expand All @@ -143,7 +143,7 @@ namespace {
if ( ! inShutdown() ) {
// we can't clean up safely once we're in shutdown
{
boost::mutex::scoped_lock clientLock(clientsMutex);
boost::lock_guard<boost::mutex> clientLock(clientsMutex);
if ( ! _shutdown )
clients.erase(this);
}
Expand All @@ -162,7 +162,7 @@ namespace {
if ( inShutdown() )
return false;
{
boost::mutex::scoped_lock clientLock(clientsMutex);
boost::lock_guard<boost::mutex> clientLock(clientsMutex);
clients.erase(this);
}

Expand Down
2 changes: 1 addition & 1 deletion src/mongo/db/clientcursor.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@

namespace mongo {

typedef boost::recursive_mutex::scoped_lock recursive_scoped_lock;
typedef boost::lock_guard<boost::recursive_mutex> recursive_scoped_lock;
class ClientCursor;
class Collection;
class CurOp;
Expand Down
4 changes: 2 additions & 2 deletions src/mongo/db/clientlistplugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ namespace {
static void _processAllClients(std::stringstream& ss) {
using namespace html;

boost::mutex::scoped_lock scopedLock(Client::clientsMutex);
boost::lock_guard<boost::mutex> scopedLock(Client::clientsMutex);

ClientSet::const_iterator it = Client::clients.begin();
for (; it != Client::clients.end(); it++) {
Expand Down Expand Up @@ -198,7 +198,7 @@ namespace {
static BSONArray _processAllClients(MatchExpression* matcher) {
BSONArrayBuilder array;

boost::mutex::scoped_lock scopedLock(Client::clientsMutex);
boost::lock_guard<boost::mutex> scopedLock(Client::clientsMutex);

ClientSet::const_iterator it = Client::clients.begin();
for (; it != Client::clients.end(); it++) {
Expand Down
2 changes: 1 addition & 1 deletion src/mongo/db/curop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ namespace mongo {

CurOp::~CurOp() {
if ( _wrapped ) {
boost::mutex::scoped_lock clientLock(Client::clientsMutex);
boost::lock_guard<boost::mutex> clientLock(Client::clientsMutex);
_client->_curOp = _wrapped;
}
_client = 0;
Expand Down
2 changes: 1 addition & 1 deletion src/mongo/db/currentop_command.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ namespace mongo {

BSONArrayBuilder inprogBuilder(retVal.subarrayStart("inprog"));

boost::mutex::scoped_lock scopedLock(Client::clientsMutex);
boost::lock_guard<boost::mutex> scopedLock(Client::clientsMutex);

ClientSet::const_iterator it = Client::clients.begin();
for ( ; it != Client::clients.end(); it++) {
Expand Down
8 changes: 4 additions & 4 deletions src/mongo/db/global_environment_d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ namespace mongo {
}

void GlobalEnvironmentMongoD::setKillAllOperations() {
boost::mutex::scoped_lock clientLock(Client::clientsMutex);
boost::lock_guard<boost::mutex> clientLock(Client::clientsMutex);
_globalKill = true;
for (size_t i = 0; i < _killOpListeners.size(); i++) {
try {
Expand Down Expand Up @@ -207,7 +207,7 @@ namespace mongo {
}

bool GlobalEnvironmentMongoD::killOperation(unsigned int opId) {
boost::mutex::scoped_lock clientLock(Client::clientsMutex);
boost::lock_guard<boost::mutex> clientLock(Client::clientsMutex);

for(ClientSet::const_iterator j = Client::clients.begin();
j != Client::clients.end(); ++j) {
Expand All @@ -224,7 +224,7 @@ namespace mongo {
}

void GlobalEnvironmentMongoD::killAllUserOperations(const OperationContext* txn) {
boost::mutex::scoped_lock scopedLock(Client::clientsMutex);
boost::lock_guard<boost::mutex> scopedLock(Client::clientsMutex);
for (ClientSet::const_iterator i = Client::clients.begin();
i != Client::clients.end(); i++) {

Expand All @@ -250,7 +250,7 @@ namespace mongo {
}

void GlobalEnvironmentMongoD::registerKillOpListener(KillOpListenerInterface* listener) {
boost::mutex::scoped_lock clientLock(Client::clientsMutex);
boost::lock_guard<boost::mutex> clientLock(Client::clientsMutex);
_killOpListeners.push_back(listener);
}

Expand Down
2 changes: 1 addition & 1 deletion src/mongo/db/index_builder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ namespace {
boost::condition_variable _bgIndexStartingCondVar;

void _setBgIndexStarting() {
boost::mutex::scoped_lock lk(_bgIndexStartingMutex);
boost::lock_guard<boost::mutex> lk(_bgIndexStartingMutex);
invariant(_bgIndexStarting == false);
_bgIndexStarting = true;
_bgIndexStartingCondVar.notify_one();
Expand Down
2 changes: 1 addition & 1 deletion src/mongo/db/repl/replication_coordinator_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2203,7 +2203,7 @@ namespace {
}

WriteConcernOptions ReplicationCoordinatorImpl::getGetLastErrorDefault() {
boost::mutex::scoped_lock lock(_mutex);
boost::lock_guard<boost::mutex> lock(_mutex);
if (_rsConfig.isInitialized()) {
return _rsConfig.getDefaultWriteConcern();
}
Expand Down
2 changes: 1 addition & 1 deletion src/mongo/db/stats/lock_server_status_section.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ namespace {

// This returns the blocked lock states
{
boost::mutex::scoped_lock scopedLock(Client::clientsMutex);
boost::lock_guard<boost::mutex> scopedLock(Client::clientsMutex);

// Count all clients
numTotal = Client::clients.size();
Expand Down
8 changes: 4 additions & 4 deletions src/mongo/db/storage/in_memory/in_memory_engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ namespace mongo {
StringData ns,
StringData ident,
const CollectionOptions& options) {
boost::mutex::scoped_lock lk(_mutex);
boost::lock_guard<boost::mutex> lk(_mutex);
if (options.capped) {
return new InMemoryRecordStore(ns,
&_dataMap[ident],
Expand All @@ -77,13 +77,13 @@ namespace mongo {
SortedDataInterface* InMemoryEngine::getSortedDataInterface(OperationContext* opCtx,
StringData ident,
const IndexDescriptor* desc) {
boost::mutex::scoped_lock lk(_mutex);
boost::lock_guard<boost::mutex> lk(_mutex);
return getInMemoryBtreeImpl(Ordering::make(desc->keyPattern()), &_dataMap[ident]);
}

Status InMemoryEngine::dropIdent(OperationContext* opCtx,
StringData ident) {
boost::mutex::scoped_lock lk(_mutex);
boost::lock_guard<boost::mutex> lk(_mutex);
_dataMap.erase(ident);
return Status::OK();
}
Expand All @@ -96,7 +96,7 @@ namespace mongo {
std::vector<std::string> InMemoryEngine::getAllIdents( OperationContext* opCtx ) const {
std::vector<std::string> all;
{
boost::mutex::scoped_lock lk(_mutex);
boost::lock_guard<boost::mutex> lk(_mutex);
for ( DataMap::const_iterator it = _dataMap.begin(); it != _dataMap.end(); ++it ) {
all.push_back( it->first );
}
Expand Down
18 changes: 9 additions & 9 deletions src/mongo/db/storage/kv/kv_catalog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ namespace {

virtual void commit() {}
virtual void rollback() {
boost::mutex::scoped_lock lk(_catalog->_identsLock);
boost::lock_guard<boost::mutex> lk(_catalog->_identsLock);
_catalog->_idents.erase(_ident);
}

Expand All @@ -80,7 +80,7 @@ namespace {

virtual void commit() {}
virtual void rollback() {
boost::mutex::scoped_lock lk(_catalog->_identsLock);
boost::lock_guard<boost::mutex> lk(_catalog->_identsLock);
_catalog->_idents[_ident] = _entry;
}

Expand Down Expand Up @@ -152,7 +152,7 @@ namespace {
}

void KVCatalog::getAllCollections( std::vector<std::string>* out ) const {
boost::mutex::scoped_lock lk( _identsLock );
boost::lock_guard<boost::mutex> lk( _identsLock );
for ( NSToIdentMap::const_iterator it = _idents.begin(); it != _idents.end(); ++it ) {
out->push_back( it->first );
}
Expand All @@ -173,7 +173,7 @@ namespace {

const string ident = _newUniqueIdent(ns, "collection");

boost::mutex::scoped_lock lk( _identsLock );
boost::lock_guard<boost::mutex> lk( _identsLock );
Entry& old = _idents[ns.toString()];
if ( !old.ident.empty() ) {
return Status( ErrorCodes::NamespaceExists, "collection already exists" );
Expand Down Expand Up @@ -203,7 +203,7 @@ namespace {
}

std::string KVCatalog::getCollectionIdent( StringData ns ) const {
boost::mutex::scoped_lock lk( _identsLock );
boost::lock_guard<boost::mutex> lk( _identsLock );
NSToIdentMap::const_iterator it = _idents.find( ns.toString() );
invariant( it != _idents.end() );
return it->second.ident;
Expand All @@ -230,7 +230,7 @@ namespace {

RecordId dl;
{
boost::mutex::scoped_lock lk( _identsLock );
boost::lock_guard<boost::mutex> lk( _identsLock );
NSToIdentMap::const_iterator it = _idents.find( ns.toString() );
invariant( it != _idents.end() );
dl = it->second.storedLoc;
Expand Down Expand Up @@ -356,7 +356,7 @@ namespace {
invariant( status.getValue() == loc );
}

boost::mutex::scoped_lock lk( _identsLock );
boost::lock_guard<boost::mutex> lk( _identsLock );
const NSToIdentMap::iterator fromIt = _idents.find(fromNS.toString());
invariant(fromIt != _idents.end());

Expand All @@ -380,7 +380,7 @@ namespace {
MODE_X));
}

boost::mutex::scoped_lock lk( _identsLock );
boost::lock_guard<boost::mutex> lk( _identsLock );
const NSToIdentMap::iterator it = _idents.find(ns.toString());
if (it == _idents.end()) {
return Status( ErrorCodes::NamespaceNotFound, "collection not found" );
Expand All @@ -399,7 +399,7 @@ namespace {
std::vector<std::string> v;

{
boost::mutex::scoped_lock lk( _identsLock );
boost::lock_guard<boost::mutex> lk( _identsLock );
for ( NSToIdentMap::const_iterator it = _idents.begin(); it != _idents.end(); ++it ) {
NamespaceString ns( it->first );
if ( ns.db() != db )
Expand Down
Loading

0 comments on commit 59a9a04

Please sign in to comment.