summaryrefslogtreecommitdiff
path: root/src/mongo/db/service_context.cpp
diff options
context:
space:
mode:
authorBen Shteinfeld <ben.shteinfeld@mongodb.com>2017-07-14 09:22:33 -0400
committerBen Shteinfeld <ben.shteinfeld@mongodb.com>2017-07-14 09:22:33 -0400
commitf8cb28f58485f89758a3cdca27186aa762313088 (patch)
tree0639655cc549cd96d5f24636485961606c82fd72 /src/mongo/db/service_context.cpp
parent6d921f47c0fcb29266c57286f1dd0d411cc459f0 (diff)
downloadmongo-f8cb28f58485f89758a3cdca27186aa762313088.tar.gz
SERVER-29720 Provide a libmongodbcapi database wrapper for service context
Diffstat (limited to 'src/mongo/db/service_context.cpp')
-rw-r--r--src/mongo/db/service_context.cpp15
1 files changed, 15 insertions, 0 deletions
diff --git a/src/mongo/db/service_context.cpp b/src/mongo/db/service_context.cpp
index 05d89c4cc6f..805a6f0802e 100644
--- a/src/mongo/db/service_context.cpp
+++ b/src/mongo/db/service_context.cpp
@@ -46,6 +46,8 @@ namespace mongo {
namespace {
ServiceContext* globalServiceContext = nullptr;
+stdx::mutex globalServiceContextMutex;
+stdx::condition_variable globalServiceContextCV;
} // namespace
@@ -58,11 +60,24 @@ ServiceContext* getGlobalServiceContext() {
return globalServiceContext;
}
+ServiceContext* waitAndGetGlobalServiceContext() {
+ stdx::unique_lock<stdx::mutex> lk(globalServiceContextMutex);
+ globalServiceContextCV.wait(lk, [] { return globalServiceContext; });
+ fassert(40549, globalServiceContext);
+ return globalServiceContext;
+}
+
void setGlobalServiceContext(std::unique_ptr<ServiceContext>&& serviceContext) {
fassert(17509, serviceContext.get());
delete globalServiceContext;
+ stdx::lock_guard<stdx::mutex> lk(globalServiceContextMutex);
+
+ if (!globalServiceContext) {
+ globalServiceContextCV.notify_all();
+ }
+
globalServiceContext = serviceContext.release();
}