From bb8b889cf5cc4a6c4cc64c2761ee2bae975c22c3 Mon Sep 17 00:00:00 2001 From: Rick Winter Date: Thu, 16 Sep 2021 11:54:18 -0700 Subject: [PATCH] Remove static_cast (#2815) * Remove static_cast * Add additional checks around our Logger::Level to ensure its lock_free --- .../inc/azure/core/internal/diagnostics/log.hpp | 10 +++++----- sdk/core/azure-core/src/logger.cpp | 9 +++------ 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/sdk/core/azure-core/inc/azure/core/internal/diagnostics/log.hpp b/sdk/core/azure-core/inc/azure/core/internal/diagnostics/log.hpp index 8c6c3afc2..c4b700ed7 100644 --- a/sdk/core/azure-core/inc/azure/core/internal/diagnostics/log.hpp +++ b/sdk/core/azure-core/inc/azure/core/internal/diagnostics/log.hpp @@ -11,16 +11,16 @@ namespace Azure { namespace Core { namespace Diagnostics { namespace _internal { class Log final { - using LogLevelInt = std::underlying_type::type; - static_assert( - std::is_same::value == true && ATOMIC_INT_LOCK_FREE == 2, + std::is_same::type>::value == true, "Logger::Level values must be representable as lock-free"); + static_assert(ATOMIC_INT_LOCK_FREE == 2, "atomic must be lock-free"); + static_assert(ATOMIC_BOOL_LOCK_FREE == 2, "atomic must be lock-free"); static AZ_CORE_DLLEXPORT std::atomic g_isLoggingEnabled; - static AZ_CORE_DLLEXPORT std::atomic g_logLevel; + static AZ_CORE_DLLEXPORT std::atomic g_logLevel; Log() = delete; ~Log() = delete; @@ -28,7 +28,7 @@ namespace Azure { namespace Core { namespace Diagnostics { namespace _internal { public: static bool ShouldWrite(Logger::Level level) { - return g_isLoggingEnabled && static_cast(level) >= g_logLevel; + return g_isLoggingEnabled && level >= g_logLevel; } static void Write(Logger::Level level, std::string const& message); diff --git a/sdk/core/azure-core/src/logger.cpp b/sdk/core/azure-core/src/logger.cpp index fa5ace4b7..e502e5be9 100644 --- a/sdk/core/azure-core/src/logger.cpp +++ b/sdk/core/azure-core/src/logger.cpp @@ -21,15 +21,12 @@ static std::function g_lo std::atomic Log::g_isLoggingEnabled( _detail::EnvironmentLogLevelListener::GetLogListener() != nullptr); -std::atomic Log::g_logLevel(static_cast( - _detail::EnvironmentLogLevelListener::GetLogLevel(Logger::Level::Warning))); +std::atomic Log::g_logLevel( + _detail::EnvironmentLogLevelListener::GetLogLevel(Logger::Level::Warning)); inline void Log::EnableLogging(bool isEnabled) { g_isLoggingEnabled = isEnabled; } -inline void Log::SetLogLevel(Logger::Level logLevel) -{ - g_logLevel = static_cast(logLevel); -} +inline void Log::SetLogLevel(Logger::Level logLevel) { g_logLevel = logLevel; } void Log::Write(Logger::Level level, std::string const& message) {