diff options
author | Ben Caimano <ben.caimano@mongodb.com> | 2019-12-13 19:24:43 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2020-03-03 18:12:45 +0000 |
commit | 678fdee6c4785242b6de417a8026596519fc32ed (patch) | |
tree | e2bd98ecf26efc567c1ad80e268984737e470635 | |
parent | 80657b5df42cf95135cdfd3b47d94f35cfcfa344 (diff) | |
download | mongo-678fdee6c4785242b6de417a8026596519fc32ed.tar.gz |
SERVER-45029 Add getCurrentServiceContext()
(cherry picked from commit 0649034e411fc20d26efce791af276e727db62d5)
-rw-r--r-- | src/mongo/db/service_context.cpp | 9 | ||||
-rw-r--r-- | src/mongo/db/service_context.h | 9 |
2 files changed, 18 insertions, 0 deletions
diff --git a/src/mongo/db/service_context.cpp b/src/mongo/db/service_context.cpp index c3d486fa100..f14fce1404c 100644 --- a/src/mongo/db/service_context.cpp +++ b/src/mongo/db/service_context.cpp @@ -72,6 +72,15 @@ ServiceContext* getGlobalServiceContext() { return globalServiceContext; } +ServiceContext* getCurrentServiceContext() { + auto client = Client::getCurrent(); + if (client) { + return client->getServiceContext(); + } + + return nullptr; +} + void setGlobalServiceContext(ServiceContext::UniqueServiceContext&& serviceContext) { if (globalServiceContext) { // Make sure that calling getGlobalServiceContext() during the destructor results in diff --git a/src/mongo/db/service_context.h b/src/mongo/db/service_context.h index fb350baad55..792066d571d 100644 --- a/src/mongo/db/service_context.h +++ b/src/mongo/db/service_context.h @@ -609,6 +609,15 @@ bool hasGlobalServiceContext(); ServiceContext* getGlobalServiceContext(); /** + * Returns the ServiceContext associated with the current Client. + * + * Returns a nullptr if there is not a current Client + * + * Caller does not own pointer. + */ +ServiceContext* getCurrentServiceContext(); + +/** * Sets the global ServiceContext. If 'serviceContext' is NULL, un-sets and deletes * the current global ServiceContext. * |