summaryrefslogtreecommitdiff
path: root/src/mongo/db/service_context.cpp
diff options
context:
space:
mode:
authorBen Shteinfeld <ben.shteinfeld@mongodb.com>2017-07-06 16:11:24 -0400
committerBen Shteinfeld <ben.shteinfeld@mongodb.com>2017-07-11 13:37:35 -0400
commitee08e773208ca4421c72913048915c20b75fac80 (patch)
treeb7f5144b941e01a0fd8ca2623da3833f81b2fe54 /src/mongo/db/service_context.cpp
parenteb43e76f419566c24624067edc6ae723ac57865f (diff)
downloadmongo-ee08e773208ca4421c72913048915c20b75fac80.tar.gz
SERVER-29720 Provide 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 f4083be9901..6c93f038eda 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(40533, 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();
}