summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJuergen Gehring <juergen.gehring@bmw.de>2018-01-25 01:01:22 -0800
committerJuergen Gehring <juergen.gehring@bmw.de>2018-01-25 01:01:22 -0800
commit45a3dea2e8226f2f6bd7017bd0e122419f77fdd7 (patch)
tree1f76e4c815f01c20826bd47a61b4d7df04d38105 /src
parent5152d31a5607393103ef01f2bb034bd267064b81 (diff)
downloadgenivi-common-api-runtime-45a3dea2e8226f2f6bd7017bd0e122419f77fdd7.tar.gz
capicxx-core-runtime 3.1.12.23.1.12.2
Diffstat (limited to 'src')
-rw-r--r--src/CommonAPI/Runtime.cpp28
1 files changed, 25 insertions, 3 deletions
diff --git a/src/CommonAPI/Runtime.cpp b/src/CommonAPI/Runtime.cpp
index b9124cd..c8176aa 100644
--- a/src/CommonAPI/Runtime.cpp
+++ b/src/CommonAPI/Runtime.cpp
@@ -27,7 +27,19 @@ const char *COMMONAPI_DEFAULT_CONFIG_FILE = "commonapi.ini";
const char *COMMONAPI_DEFAULT_CONFIG_FOLDER = "/etc";
std::map<std::string, std::string> properties__;
-std::shared_ptr<Runtime> Runtime::theRuntime__ = std::make_shared<Runtime>();
+static std::shared_ptr<Runtime> * theRuntimePtr__;
+static std::mutex getMutex__;
+
+#ifndef _WIN32
+DEINITIALIZER(RuntimeDeinit) {
+ if (theRuntimePtr__) {
+ std::lock_guard<std::mutex> itsLock(getMutex__);
+ theRuntimePtr__->reset();
+ delete theRuntimePtr__;
+ theRuntimePtr__ = nullptr;
+ }
+}
+#endif
std::string
Runtime::getProperty(const std::string &_name) {
@@ -43,8 +55,18 @@ Runtime::setProperty(const std::string &_name, const std::string &_value) {
}
std::shared_ptr<Runtime> Runtime::get() {
- theRuntime__->init();
- return theRuntime__;
+ std::lock_guard<std::mutex> itsLock(getMutex__);
+ if(!theRuntimePtr__) {
+ theRuntimePtr__ = new std::shared_ptr<Runtime>();
+ }
+ if (theRuntimePtr__) {
+ if (!*theRuntimePtr__) {
+ *theRuntimePtr__ = std::make_shared<Runtime>();
+ (*theRuntimePtr__)->init();
+ }
+ return *theRuntimePtr__;
+ }
+ return nullptr;
}
Runtime::Runtime()