summaryrefslogtreecommitdiff
path: root/src/mongo/db/service_context.cpp
diff options
context:
space:
mode:
authorBen Shteinfeld <ben.shteinfeld@mongodb.com>2017-07-11 14:06:53 -0400
committerBen Shteinfeld <ben.shteinfeld@mongodb.com>2017-07-11 14:11:19 -0400
commitf7f3946600e6a5c6612ba6763ca91d93b5a023f7 (patch)
treea2c8bfbfbf08e43fece9d728ed1dfcff8a0b4e84 /src/mongo/db/service_context.cpp
parent6a649373bde66a24ecb286aceb14bd12bcaa5a1c (diff)
downloadmongo-f7f3946600e6a5c6612ba6763ca91d93b5a023f7.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..72ef69afee8 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();
}