creation fix

Change-Id: I717d96555677664ce0a926cf1c3c3c48f55287d9


[ROCm/rocprofiler commit: 1ed97815f1]
Tá an tiomantas seo le fáil i:
Evgeny
2019-03-13 15:17:56 -05:00
tuismitheoir 1ecd03ea5e
tiomantas 8b6c9cc839
D'athraigh 6 comhad le 217 breiseanna agus 65 scriosta
+15 -6
Féach ar an gComhad
@@ -76,8 +76,16 @@ class Logger {
static Logger* Create() {
std::lock_guard<mutex_t> lck(mutex_);
if (instance_ == NULL) instance_ = new Logger();
return instance_;
Logger* obj = instance_.load(std::memory_order_relaxed);
if (obj == NULL) {
obj = new Logger();
if (obj == NULL) {
std::cerr << "ROCProfiler: log object creation failed" << std::endl << std::flush;
abort();
}
instance_.store(obj, std::memory_order_release);
}
return obj;
}
static void Destroy() {
@@ -87,8 +95,9 @@ class Logger {
}
static Logger& Instance() {
Create();
return *instance_;
Logger* obj = instance_.load(std::memory_order_acquire);
if (obj == NULL) obj = Create();
return *obj;
}
private:
@@ -179,10 +188,10 @@ class Logger {
bool messaging_;
bool error_;
std::string session_dir_;
std::map<uint32_t, std::string> message_;
static mutex_t mutex_;
static Logger* instance_;
std::map<uint32_t, std::string> message_;
static std::atomic<Logger*> instance_;
};
} // namespace util