summaryrefslogtreecommitdiff
path: root/src/mongo/db/client.cpp
diff options
context:
space:
mode:
authorJonathan Reams <jbreams@mongodb.com>2017-04-12 22:27:27 -0400
committerJonathan Reams <jbreams@mongodb.com>2017-04-19 13:40:30 -0400
commit4fc596bd6f53c5c168d8643b447d8d6c78f61f14 (patch)
tree2e647354ddb3722c7ee6e291fb5124d74f253a74 /src/mongo/db/client.cpp
parent3483a1c42f9d5f3fd38e671684e9157821cf48df (diff)
downloadmongo-4fc596bd6f53c5c168d8643b447d8d6c78f61f14.tar.gz
SERVER-28201 Allow detatching of the current Client
Diffstat (limited to 'src/mongo/db/client.cpp')
-rw-r--r--src/mongo/db/client.cpp24
1 files changed, 16 insertions, 8 deletions
diff --git a/src/mongo/db/client.cpp b/src/mongo/db/client.cpp
index 3f26dc039c0..6ecfeb3195b 100644
--- a/src/mongo/db/client.cpp
+++ b/src/mongo/db/client.cpp
@@ -70,7 +70,7 @@ void Client::initThread(StringData desc, transport::SessionHandle session) {
void Client::initThread(StringData desc,
ServiceContext* service,
transport::SessionHandle session) {
- invariant(currentClient.getMake()->get() == nullptr);
+ invariant(!haveClient());
std::string fullDesc;
if (session) {
@@ -82,12 +82,11 @@ void Client::initThread(StringData desc,
setThreadName(fullDesc);
// Create the client obj, attach to thread
- *currentClient.get() = service->makeClient(fullDesc, std::move(session));
+ *currentClient.getMake() = service->makeClient(fullDesc, std::move(session));
}
void Client::destroy() {
- invariant(currentClient.get());
- invariant(currentClient.get()->get());
+ invariant(haveClient());
currentClient.reset(nullptr);
}
@@ -155,13 +154,22 @@ Client* Client::getCurrent() {
}
Client& cc() {
- Client* c = currentClient.getMake()->get();
- invariant(c);
- return *c;
+ invariant(haveClient());
+ return *Client::getCurrent();
}
bool haveClient() {
- return currentClient.getMake()->get();
+ return currentClient.get() && currentClient.get()->get();
+}
+
+ServiceContext::UniqueClient Client::releaseCurrent() {
+ invariant(haveClient());
+ return ServiceContext::UniqueClient(currentClient.get()->release());
+}
+
+void Client::setCurrent(ServiceContext::UniqueClient client) {
+ invariant(!haveClient());
+ *currentClient.getMake() = std::move(client);
}
} // namespace mongo