diff options
author | Andy Schwerin <schwerin@mongodb.com> | 2015-04-07 16:49:06 -0400 |
---|---|---|
committer | Andy Schwerin <schwerin@mongodb.com> | 2015-04-20 14:06:16 -0400 |
commit | 84c4b7d15c6b98c7bb648bc60ade93b6af62b129 (patch) | |
tree | 6a0afa97d6f911c07089ccdf7bc29aa2deaed314 /src/mongo/db/client.h | |
parent | 8e5b16fe0d64d587e0741dab7cabe64b0a818e51 (diff) | |
download | mongo-84c4b7d15c6b98c7bb648bc60ade93b6af62b129.tar.gz |
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.
Diffstat (limited to 'src/mongo/db/client.h')
-rw-r--r-- | src/mongo/db/client.h | 43 |
1 files changed, 9 insertions, 34 deletions
diff --git a/src/mongo/db/client.h b/src/mongo/db/client.h index b01656d3407..f81bc91bf37 100644 --- a/src/mongo/db/client.h +++ b/src/mongo/db/client.h @@ -43,6 +43,7 @@ #include "mongo/db/lasterror.h" #include "mongo/db/namespace_string.h" #include "mongo/db/operation_context.h" +#include "mongo/db/service_context.h" #include "mongo/platform/unordered_set.h" #include "mongo/util/concurrency/spin_lock.h" #include "mongo/util/concurrency/threadlocal.h" @@ -52,21 +53,11 @@ namespace mongo { class Collection; class AbstractMessagingPort; - TSP_DECLARE(Client, currentClient) - typedef long long ConnectionId; - typedef unordered_set<Client*> ClientSet; - /** the database's concept of an outside "client" */ class Client : public ClientBasic { public: - // A set of currently active clients along with a mutex to protect the list - static boost::mutex clientsMutex; - static ClientSet clients; - - ~Client(); - /** each thread which does db operations has a Client object in TLS. * call this when your thread starts. */ @@ -79,25 +70,12 @@ namespace mongo { * Inits a thread if that thread has not already been init'd, setting the thread name to * "desc". */ - static void initThreadIfNotAlready(const char* desc) { - if (currentClient.get()) - return; - initThread(desc); - } + static void initThreadIfNotAlready(const char* desc); /** * Inits a thread if that thread has not already been init'd, using the existing thread name */ - static void initThreadIfNotAlready() { - if (currentClient.get()) - return; - initThread(getThreadName().c_str()); - } - - /** this has to be called as the client goes away, but before thread termination - * @return true if anything was done - */ - void shutdown(); + static void initThreadIfNotAlready(); std::string clientAddress(bool includePort = false) const; const std::string& desc() const { return _desc; } @@ -123,7 +101,8 @@ namespace mongo { bool isFromUserConnection() const { return _connectionId > 0; } private: - Client(const std::string& desc, + friend class ServiceContext; + Client(std::string desc, ServiceContext* serviceContext, AbstractMessagingPort *p = 0); @@ -141,19 +120,15 @@ namespace mongo { mutable SpinLock _lock; // Whether this client is running as DBDirectClient - bool _inDirectClient; + bool _inDirectClient = false; // If != NULL, then contains the currently active OperationContext - OperationContext* _txn; + OperationContext* _txn = nullptr; }; /** get the Client object for this thread. */ - inline Client& cc() { - Client * c = currentClient.get(); - verify( c ); - return *c; - } + Client& cc(); - inline bool haveClient() { return currentClient.get() != NULL; } + bool haveClient(); }; |