Просмотр исходного кода

logging/backend: Make time_origin a class variable instead of a local static

Moves local global state into the Impl class itself and initializes it
at the creation of the instance instead of in the function.

This makes it nicer for weakly-ordered architectures, given the
CreateEntry() class won't need to have atomic loads executed for each
individual call to the CreateEntry class.
Lioncash 7 лет назад
Родитель
Сommit
f8f1ff0b4f
1 измененных файлов с 1 добавлено и 2 удалено
  1. 1 2
      src/common/logging/backend.cpp

+ 1 - 2
src/common/logging/backend.cpp

@@ -115,8 +115,6 @@ private:
         using std::chrono::duration_cast;
         using std::chrono::duration_cast;
         using std::chrono::steady_clock;
         using std::chrono::steady_clock;
 
 
-        static steady_clock::time_point time_origin = steady_clock::now();
-
         Entry entry;
         Entry entry;
         entry.timestamp =
         entry.timestamp =
             duration_cast<std::chrono::microseconds>(steady_clock::now() - time_origin);
             duration_cast<std::chrono::microseconds>(steady_clock::now() - time_origin);
@@ -135,6 +133,7 @@ private:
     std::vector<std::unique_ptr<Backend>> backends;
     std::vector<std::unique_ptr<Backend>> backends;
     Common::MPSCQueue<Log::Entry> message_queue;
     Common::MPSCQueue<Log::Entry> message_queue;
     Filter filter;
     Filter filter;
+    std::chrono::steady_clock::time_point time_origin{std::chrono::steady_clock::now()};
 };
 };
 
 
 void ConsoleBackend::Write(const Entry& entry) {
 void ConsoleBackend::Write(const Entry& entry) {