From ec80932c2170337fc8eebba30ed890d1ce6ac2a4 Mon Sep 17 00:00:00 2001 From: Nekotekina Date: Sat, 1 Feb 2020 10:30:03 +0300 Subject: [PATCH] logs: use relaxed atomics May help with optimizations. --- Utilities/Log.cpp | 8 ++++---- Utilities/Log.h | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Utilities/Log.cpp b/Utilities/Log.cpp index 0d2f21ca5a..0a685ae379 100644 --- a/Utilities/Log.cpp +++ b/Utilities/Log.cpp @@ -169,7 +169,7 @@ namespace logs for (auto&& pair : get_logger()->channels) { - pair.second->enabled = level::notice; + pair.second->enabled.store(level::notice, std::memory_order_relaxed); } } @@ -179,7 +179,7 @@ namespace logs for (auto&& pair : get_logger()->channels) { - pair.second->enabled = level::always; + pair.second->enabled.store(level::always, std::memory_order_relaxed); } } @@ -191,7 +191,7 @@ namespace logs while (found.first != found.second) { - found.first->second->enabled = value; + found.first->second->enabled.store(value, std::memory_order_relaxed); found.first++; } } @@ -204,7 +204,7 @@ namespace logs if (found.first != found.second) { - return found.first->second->enabled; + return found.first->second->enabled.load(std::memory_order_relaxed); } else { diff --git a/Utilities/Log.h b/Utilities/Log.h index 1a1e2431b8..d822e6119c 100644 --- a/Utilities/Log.h +++ b/Utilities/Log.h @@ -1,9 +1,9 @@ #pragma once #include "types.h" -#include "util/atomic.hpp" #include "StrFmt.h" -#include +#include "util/atomic.hpp" +#include namespace logs { @@ -59,7 +59,7 @@ namespace logs const char* const name; // The lowest logging level enabled for this channel (used for early filtering) - atomic_t enabled; + std::atomic enabled; // Initialize and register channel channel(const char* name); @@ -69,7 +69,7 @@ namespace logs template \ void _sev(const char(&fmt)[N], const Args&... args)\ {\ - if (UNLIKELY(level::_sev <= enabled))\ + if (UNLIKELY(level::_sev <= enabled.load(std::memory_order_relaxed)))\ {\ static constexpr fmt_type_info type_list[sizeof...(Args) + 1]{fmt_type_info::make>()...};\ msg_##_sev.broadcast(fmt, type_list, u64{fmt_unveil::get(args)}...);\