diff options
author | Ben Shteinfeld <ben.shteinfeld@mongodb.com> | 2017-07-11 14:06:53 -0400 |
---|---|---|
committer | Ben Shteinfeld <ben.shteinfeld@mongodb.com> | 2017-07-11 14:11:19 -0400 |
commit | f7f3946600e6a5c6612ba6763ca91d93b5a023f7 (patch) | |
tree | a2c8bfbfbf08e43fece9d728ed1dfcff8a0b4e84 /src/mongo/db/service_context.cpp | |
parent | 6a649373bde66a24ecb286aceb14bd12bcaa5a1c (diff) | |
download | mongo-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.cpp | 15 |
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(); } |