Skip to content

Commit 45a3dea

Browse files
capicxx-core-runtime 3.1.12.2
1 parent 5152d31 commit 45a3dea

File tree

7 files changed

+28
-233
lines changed

7 files changed

+28
-233
lines changed

.cproject

Lines changed: 0 additions & 158 deletions
This file was deleted.

.gitattributes

Lines changed: 0 additions & 42 deletions
This file was deleted.

.gitignore

Lines changed: 0 additions & 2 deletions
This file was deleted.

.project

Lines changed: 0 additions & 27 deletions
This file was deleted.

CHANGES

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
Changes
22
=======
3+
v3.1.12.2
4+
- Defer Runtime destruction till shared object is unloaded
5+
36
v3.1.12.1
47
- replaced std::chrono::high_resolution_clock by std::chrono::steady_clock in MainLoopContext.cpp
58

include/CommonAPI/Runtime.hpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,6 @@ class Runtime {
188188
bool isInitialized_;
189189

190190
static std::map<std::string, std::string> properties_;
191-
static std::shared_ptr<Runtime> theRuntime__;
192191

193192
friend class ProxyManager;
194193
};

src/CommonAPI/Runtime.cpp

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,19 @@ const char *COMMONAPI_DEFAULT_CONFIG_FILE = "commonapi.ini";
2727
const char *COMMONAPI_DEFAULT_CONFIG_FOLDER = "/etc";
2828

2929
std::map<std::string, std::string> properties__;
30-
std::shared_ptr<Runtime> Runtime::theRuntime__ = std::make_shared<Runtime>();
30+
static std::shared_ptr<Runtime> * theRuntimePtr__;
31+
static std::mutex getMutex__;
32+
33+
#ifndef _WIN32
34+
DEINITIALIZER(RuntimeDeinit) {
35+
if (theRuntimePtr__) {
36+
std::lock_guard<std::mutex> itsLock(getMutex__);
37+
theRuntimePtr__->reset();
38+
delete theRuntimePtr__;
39+
theRuntimePtr__ = nullptr;
40+
}
41+
}
42+
#endif
3143

3244
std::string
3345
Runtime::getProperty(const std::string &_name) {
@@ -43,8 +55,18 @@ Runtime::setProperty(const std::string &_name, const std::string &_value) {
4355
}
4456

4557
std::shared_ptr<Runtime> Runtime::get() {
46-
theRuntime__->init();
47-
return theRuntime__;
58+
std::lock_guard<std::mutex> itsLock(getMutex__);
59+
if(!theRuntimePtr__) {
60+
theRuntimePtr__ = new std::shared_ptr<Runtime>();
61+
}
62+
if (theRuntimePtr__) {
63+
if (!*theRuntimePtr__) {
64+
*theRuntimePtr__ = std::make_shared<Runtime>();
65+
(*theRuntimePtr__)->init();
66+
}
67+
return *theRuntimePtr__;
68+
}
69+
return nullptr;
4870
}
4971

5072
Runtime::Runtime()

0 commit comments

Comments
 (0)