creation fix

Change-Id: I717d96555677664ce0a926cf1c3c3c48f55287d9
This commit is contained in:
Evgeny
2019-03-13 15:17:56 -05:00
parent f834529669
commit 1ed97815f1
6 changed files with 217 additions and 65 deletions
+11 -5
View File
@@ -66,13 +66,19 @@ class Tracker {
static Tracker* Create() {
std::lock_guard<mutex_t> lck(glob_mutex_);
if (instance_ == NULL) instance_ = new Tracker;
return instance_;
Tracker* obj = instance_.load(std::memory_order_relaxed);
if (obj == NULL) {
obj = new Tracker;
if (obj == NULL) EXC_ABORT(HSA_STATUS_ERROR, "Tracker creation failed");
instance_.store(obj, std::memory_order_release);
}
return obj;
}
static Tracker& Instance() {
if (instance_ == NULL) instance_ = Create();
return *instance_;
Tracker* obj = instance_.load(std::memory_order_acquire);
if (obj == NULL) obj = Create();
return *obj;
}
static void Destroy() {
@@ -261,7 +267,7 @@ class Tracker {
}
// instance
static Tracker* instance_;
static std::atomic<Tracker*> instance_;
static mutex_t glob_mutex_;
static counter_t counter_;