From 84c4b7d15c6b98c7bb648bc60ade93b6af62b129 Mon Sep 17 00:00:00 2001 From: Andy Schwerin Date: Tue, 7 Apr 2015 16:49:06 -0400 Subject: SERVER-17817 Make ServiceContext create and manage Client objects. Also, deduplicate Client::* method implementations, guard the identity of the current CurOp of a Client with the Client's _mutex instead of the mutex guarding the list of all clients. Makes the currentClient object private to client.cpp, and all access to the thread-bound client is now done with haveClient() and cc() free functions in the mongo namespace. Removes the vesitgal Client::shutdown() methods. --- src/mongo/db/service_context_d.cpp | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) (limited to 'src/mongo/db/service_context_d.cpp') diff --git a/src/mongo/db/service_context_d.cpp b/src/mongo/db/service_context_d.cpp index 50a9b660394..d78cf0be802 100644 --- a/src/mongo/db/service_context_d.cpp +++ b/src/mongo/db/service_context_d.cpp @@ -28,6 +28,8 @@ #define MONGO_LOG_DEFAULT_COMPONENT ::mongo::logger::LogComponent::kDefault +#include "mongo/platform/basic.h" + #include "mongo/db/service_context_d.h" #include "mongo/base/init.h" @@ -169,7 +171,7 @@ namespace mongo { } void ServiceContextMongoD::setKillAllOperations() { - boost::lock_guard clientLock(Client::clientsMutex); + boost::lock_guard clientLock(_mutex); _globalKill = true; for (size_t i = 0; i < _killOpListeners.size(); i++) { try { @@ -210,13 +212,7 @@ namespace mongo { } bool ServiceContextMongoD::killOperation(unsigned int opId) { - boost::lock_guard clientLock(Client::clientsMutex); - - for(ClientSet::const_iterator j = Client::clients.begin(); - j != Client::clients.end(); ++j) { - - Client* client = *j; - + for (LockedClientsCursor cursor(this); Client* client = cursor.next();) { bool found = _killOperationsAssociatedWithClientAndOpId_inlock(client, opId); if (found) { return true; @@ -227,11 +223,7 @@ namespace mongo { } void ServiceContextMongoD::killAllUserOperations(const OperationContext* txn) { - boost::lock_guard scopedLock(Client::clientsMutex); - for (ClientSet::const_iterator i = Client::clients.begin(); - i != Client::clients.end(); i++) { - - Client* client = *i; + for (LockedClientsCursor cursor(this); Client* client = cursor.next();) { if (!client->isFromUserConnection()) { // Don't kill system operations. continue; @@ -256,7 +248,7 @@ namespace mongo { } void ServiceContextMongoD::registerKillOpListener(KillOpListenerInterface* listener) { - boost::lock_guard clientLock(Client::clientsMutex); + boost::lock_guard clientLock(_mutex); _killOpListeners.push_back(listener); } -- cgit v1.2.1