[neurun] initialize logging only once (#8570)
authorVladimir Plazun/Engineer/AI Tools Lab /SRR/Samsung Electronics <v.plazun@samsung.com>
Wed, 30 Oct 2019 03:38:40 +0000 (06:38 +0300)
committer이한종/On-Device Lab(SR)/Engineer/삼성전자 <hanjoung.lee@samsung.com>
Wed, 30 Oct 2019 03:38:40 +0000 (12:38 +0900)
Currently logging::Context is instantiated inside each translation unit separately

Signed-off-by: Vladimir Plazun <v.plazun@samsung.com>
runtimes/neurun/core/include/util/logging.h
runtimes/neurun/core/src/util/logging.cc [new file with mode: 0644]

index a2fdbdd..8ecd0ac 100644 (file)
@@ -31,7 +31,7 @@ namespace logging
 class Context
 {
 public:
-  Context() : _enabled{false}
+  Context() noexcept : _enabled{false}
   {
     const auto env = util::getConfigBool(util::config::NEURUN_LOG_ENABLE);
 
@@ -41,6 +41,8 @@ public:
     }
   }
 
+  static Context &get() noexcept;
+
 public:
   bool enabled(void) const { return _enabled; }
 
@@ -48,7 +50,7 @@ private:
   bool _enabled;
 };
 
-static Context ctx;
+static Context &ctx = Context::get();
 
 } // namespace logging
 } // namespace util
diff --git a/runtimes/neurun/core/src/util/logging.cc b/runtimes/neurun/core/src/util/logging.cc
new file mode 100644 (file)
index 0000000..c23e2b5
--- /dev/null
@@ -0,0 +1,7 @@
+#include "util/logging.h"
+
+neurun::util::logging::Context &neurun::util::logging::Context::get() noexcept
+{
+  static Context ctx;
+  return ctx;
+}