summaryrefslogtreecommitdiff
path: root/src/mongo/db/client.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/mongo/db/client.cpp')
-rw-r--r--src/mongo/db/client.cpp162
1 files changed, 80 insertions, 82 deletions
diff --git a/src/mongo/db/client.cpp b/src/mongo/db/client.cpp
index 8ab9a7995f3..5da6d24c835 100644
--- a/src/mongo/db/client.cpp
+++ b/src/mongo/db/client.cpp
@@ -49,106 +49,104 @@
namespace mongo {
- using logger::LogComponent;
+using logger::LogComponent;
- TSP_DECLARE(ServiceContext::UniqueClient, currentClient)
- TSP_DEFINE(ServiceContext::UniqueClient, currentClient)
+TSP_DECLARE(ServiceContext::UniqueClient, currentClient)
+TSP_DEFINE(ServiceContext::UniqueClient, currentClient)
- void Client::initThreadIfNotAlready(const char* desc) {
- if (currentClient.getMake()->get())
- return;
- initThread(desc);
- }
+void Client::initThreadIfNotAlready(const char* desc) {
+ if (currentClient.getMake()->get())
+ return;
+ initThread(desc);
+}
- void Client::initThreadIfNotAlready() {
- initThreadIfNotAlready(getThreadName().c_str());
- }
+void Client::initThreadIfNotAlready() {
+ initThreadIfNotAlready(getThreadName().c_str());
+}
- void Client::initThread(const char *desc, AbstractMessagingPort *mp) {
- initThread(desc, getGlobalServiceContext(), mp);
- }
+void Client::initThread(const char* desc, AbstractMessagingPort* mp) {
+ initThread(desc, getGlobalServiceContext(), mp);
+}
- /**
- * This must be called whenever a new thread is started, so that active threads can be tracked
- * so each thread has a Client object in TLS.
- */
- void Client::initThread(const char *desc, ServiceContext* service, AbstractMessagingPort *mp) {
- invariant(currentClient.getMake()->get() == nullptr);
-
- std::string fullDesc;
- if (mp != NULL) {
- fullDesc = str::stream() << desc << mp->connectionId();
- }
- else {
- fullDesc = desc;
- }
-
- setThreadName(fullDesc.c_str());
-
- // Create the client obj, attach to thread
- *currentClient.get() = service->makeClient(fullDesc, mp);
+/**
+ * This must be called whenever a new thread is started, so that active threads can be tracked
+ * so each thread has a Client object in TLS.
+ */
+void Client::initThread(const char* desc, ServiceContext* service, AbstractMessagingPort* mp) {
+ invariant(currentClient.getMake()->get() == nullptr);
+
+ std::string fullDesc;
+ if (mp != NULL) {
+ fullDesc = str::stream() << desc << mp->connectionId();
+ } else {
+ fullDesc = desc;
}
- Client::Client(std::string desc,
- ServiceContext* serviceContext,
- AbstractMessagingPort *p)
- : ClientBasic(serviceContext, p),
- _desc(std::move(desc)),
- _threadId(stdx::this_thread::get_id()),
- _connectionId(p ? p->connectionId() : 0) {
- }
+ setThreadName(fullDesc.c_str());
- void Client::reportState(BSONObjBuilder& builder) {
- builder.append("desc", desc());
+ // Create the client obj, attach to thread
+ *currentClient.get() = service->makeClient(fullDesc, mp);
+}
- std::stringstream ss;
- ss << _threadId;
- builder.append("threadId", ss.str());
+Client::Client(std::string desc, ServiceContext* serviceContext, AbstractMessagingPort* p)
+ : ClientBasic(serviceContext, p),
+ _desc(std::move(desc)),
+ _threadId(stdx::this_thread::get_id()),
+ _connectionId(p ? p->connectionId() : 0) {}
- if (_connectionId) {
- builder.appendNumber("connectionId", _connectionId);
- }
+void Client::reportState(BSONObjBuilder& builder) {
+ builder.append("desc", desc());
- if (hasRemote()) {
- builder.append("client", getRemote().toString());
- }
- }
+ std::stringstream ss;
+ ss << _threadId;
+ builder.append("threadId", ss.str());
- ServiceContext::UniqueOperationContext Client::makeOperationContext() {
- return getServiceContext()->makeOperationContext(this);
+ if (_connectionId) {
+ builder.appendNumber("connectionId", _connectionId);
}
- void Client::setOperationContext(OperationContext* txn) {
- // We can only set the OperationContext once before resetting it.
- invariant(txn != NULL && _txn == NULL);
- _txn = txn;
+ if (hasRemote()) {
+ builder.append("client", getRemote().toString());
}
-
- void Client::resetOperationContext() {
- invariant(_txn != NULL);
- _txn = NULL;
+}
+
+ServiceContext::UniqueOperationContext Client::makeOperationContext() {
+ return getServiceContext()->makeOperationContext(this);
+}
+
+void Client::setOperationContext(OperationContext* txn) {
+ // We can only set the OperationContext once before resetting it.
+ invariant(txn != NULL && _txn == NULL);
+ _txn = txn;
+}
+
+void Client::resetOperationContext() {
+ invariant(_txn != NULL);
+ _txn = NULL;
+}
+
+std::string Client::clientAddress(bool includePort) const {
+ if (!hasRemote()) {
+ return "";
}
-
- std::string Client::clientAddress(bool includePort) const {
- if (!hasRemote()) {
- return "";
- }
- if (includePort) {
- return getRemote().toString();
- }
- return getRemote().host();
+ if (includePort) {
+ return getRemote().toString();
}
+ return getRemote().host();
+}
- ClientBasic* ClientBasic::getCurrent() {
- return currentClient.getMake()->get();
- }
+ClientBasic* ClientBasic::getCurrent() {
+ return currentClient.getMake()->get();
+}
- Client& cc() {
- Client* c = currentClient.getMake()->get();
- verify(c);
- return *c;
- }
+Client& cc() {
+ Client* c = currentClient.getMake()->get();
+ verify(c);
+ return *c;
+}
- bool haveClient() { return currentClient.getMake()->get(); }
+bool haveClient() {
+ return currentClient.getMake()->get();
+}
-} // namespace mongo
+} // namespace mongo