Skip to content

Commit a706b8a

Browse files
committed
fix a few bugs
1 parent 73115fa commit a706b8a

File tree

2 files changed

+22
-5
lines changed

2 files changed

+22
-5
lines changed

xpti/src/xpti_proxy.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -152,10 +152,10 @@ XPTI_EXPORT_API void xptiFrameworkInitialize() {
152152

153153
XPTI_EXPORT_API void xptiFrameworkFinalize() {
154154
if (xpti::ProxyLoader::instance().noErrors()) {
155-
void *f = xpti::ProxyLoader::instance().functionByIndex(
156-
XPTI_FRAMEWORK_INITIALIZE);
155+
void *f =
156+
xpti::ProxyLoader::instance().functionByIndex(XPTI_FRAMEWORK_FINALIZE);
157157
if (f) {
158-
(*reinterpret_cast<xpti_framework_initialize_t>(f))();
158+
(*reinterpret_cast<xpti_framework_finalize_t>(f))();
159159
}
160160
}
161161

xptifw/src/xpti_trace_framework.cpp

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include "xpti_int64_hash_table.hpp"
88
#include "xpti_string_table.hpp"
99

10+
#include <atomic>
1011
#include <cassert>
1112
#include <cstdio>
1213
#include <iostream>
@@ -976,11 +977,24 @@ class Framework {
976977
}
977978

978979
static Framework &instance() {
979-
static Framework *framework = new Framework();
980-
return *framework;
980+
Framework *TmpFramework = MInstance.load(std::memory_order_relaxed);
981+
std::atomic_thread_fence(std::memory_order_acquire);
982+
if (TmpFramework == nullptr) {
983+
std::lock_guard<utils::SpinLock> Lock{MSingletoneMutex};
984+
TmpFramework = MInstance.load(std::memory_order_relaxed);
985+
if (TmpFramework == nullptr) {
986+
TmpFramework = new Framework();
987+
std::atomic_thread_fence(std::memory_order_release);
988+
MInstance.store(TmpFramework, std::memory_order_relaxed);
989+
}
990+
}
991+
992+
return *TmpFramework;
981993
}
982994

983995
private:
996+
static std::atomic<Framework *> MInstance;
997+
static utils::SpinLock MSingletoneMutex;
984998
/// Thread-safe counter used for generating universal IDs
985999
xpti::safe_uint64_t MUniversalIDs;
9861000
/// Manages loading the subscribers and calling their init() functions
@@ -1000,6 +1014,9 @@ class Framework {
10001014
};
10011015

10021016
static int GFrameworkReferenceCounter = 0;
1017+
1018+
std::atomic<Framework *> Framework::MInstance;
1019+
utils::SpinLock Framework::MSingletoneMutex;
10031020
} // namespace xpti
10041021

10051022
extern "C" {

0 commit comments

Comments
 (0)