diff options
author | Alexander Kutsan (GitHub) <akutsan@luxoft.com> | 2020-09-03 23:51:34 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-09-03 16:51:34 -0400 |
commit | 99a74995974cd658f06e7b69e9531f2959f31fd1 (patch) | |
tree | 95513a3a6e164d75f025073057550c5ab4f062f6 | |
parent | 1ee365e7b462128b03e197b01f546edc0c757973 (diff) | |
download | sdl_core-99a74995974cd658f06e7b69e9531f2959f31fd1.tar.gz |
Removed unconsistent logger_status variable. (#3489)
Fix adopted from SYNC4 codebase
-rw-r--r-- | src/components/include/utils/logger.h | 32 | ||||
-rw-r--r-- | src/components/include/utils/logger_status.h | 53 | ||||
-rw-r--r-- | src/components/utils/include/utils/logger/logger_impl.h | 1 | ||||
-rw-r--r-- | src/components/utils/src/auto_trace.cc | 40 | ||||
-rw-r--r-- | src/components/utils/src/logger/logger_impl.cc | 26 | ||||
-rw-r--r-- | src/components/utils/src/logger_status.cc | 39 |
6 files changed, 41 insertions, 150 deletions
diff --git a/src/components/include/utils/logger.h b/src/components/include/utils/logger.h index 197b2ec5d9..6ceff88738 100644 --- a/src/components/include/utils/logger.h +++ b/src/components/include/utils/logger.h @@ -40,8 +40,6 @@ #include <string> #include "utils/auto_trace.h" -#include "utils/logger_status.h" - #define SDL_CREATE_LOG_VARIABLE(component_name) \ namespace { \ static std::string logger_(component_name); \ @@ -59,22 +57,20 @@ // destroyed by exit() #define SDL_DEINIT_LOGGER() logger::Logger::instance().DeInit(); -#define LOG_WITH_LEVEL(logLevel, logEvent) \ - do { \ - if (logger::logger_status != logger::DeletingLoggerThread) { \ - if (logger::Logger::instance().IsEnabledFor(logger_, logLevel)) { \ - std::stringstream accumulator; \ - accumulator << logEvent; \ - logger::LogMessage message{ \ - logger_, \ - logLevel, \ - accumulator.str(), \ - std::chrono::high_resolution_clock::now(), \ - logger::LocationInfo{__FILE__, __PRETTY_FUNCTION__, __LINE__}, \ - std::this_thread::get_id()}; \ - logger::Logger::instance().PushLog(message); \ - } \ - } \ +#define LOG_WITH_LEVEL(logLevel, logEvent) \ + do { \ + if (logger::Logger::instance().IsEnabledFor(logger_, logLevel)) { \ + std::stringstream accumulator; \ + accumulator << logEvent; \ + logger::LogMessage message{ \ + logger_, \ + logLevel, \ + accumulator.str(), \ + std::chrono::high_resolution_clock::now(), \ + logger::LocationInfo{__FILE__, __PRETTY_FUNCTION__, __LINE__}, \ + std::this_thread::get_id()}; \ + logger::Logger::instance().PushLog(message); \ + } \ } while (false) #define SDL_LOG_TRACE(logEvent) \ diff --git a/src/components/include/utils/logger_status.h b/src/components/include/utils/logger_status.h deleted file mode 100644 index b16920704a..0000000000 --- a/src/components/include/utils/logger_status.h +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright (c) 2014, Ford Motor Company - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following - * disclaimer in the documentation and/or other materials provided with the - * distribution. - * - * Neither the name of the Ford Motor Company nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef SRC_COMPONENTS_INCLUDE_UTILS_LOGGER_STATUS_H_ -#define SRC_COMPONENTS_INCLUDE_UTILS_LOGGER_STATUS_H_ - -namespace logger { - -typedef enum { - LoggerThreadNotCreated, - CreatingLoggerThread, - LoggerThreadCreated, - DeletingLoggerThread, - LoggerThreadIsNotUsed -} LoggerStatus; - -// this variable is only changed when creating and deleting logger thread -// its reads and writes are believed to be atomic -// thus it shall be considered thread safe -extern volatile LoggerStatus logger_status; - -} // namespace logger - -#endif // SRC_COMPONENTS_INCLUDE_UTILS_LOGGER_STATUS_H_ diff --git a/src/components/utils/include/utils/logger/logger_impl.h b/src/components/utils/include/utils/logger/logger_impl.h index 5f32b45664..faff8f167d 100644 --- a/src/components/utils/include/utils/logger/logger_impl.h +++ b/src/components/utils/include/utils/logger/logger_impl.h @@ -37,7 +37,6 @@ #include <functional> -#include "utils/logger_status.h" #include "utils/threads/message_loop_thread.h" namespace logger { diff --git a/src/components/utils/src/auto_trace.cc b/src/components/utils/src/auto_trace.cc index 8f83494c3c..3d9c82a955 100644 --- a/src/components/utils/src/auto_trace.cc +++ b/src/components/utils/src/auto_trace.cc @@ -37,32 +37,28 @@ namespace logger { AutoTrace::AutoTrace(const std::string& component, const LocationInfo& location) : component_(component), location_(location) { - if (logger::logger_status != logger::DeletingLoggerThread) { - if (logger::Logger::instance().IsEnabledFor( - component_, logger::LogLevel::TRACE_LEVEL)) { - logger::LogMessage message{component_, - LogLevel::TRACE_LEVEL, - "Enter", - std::chrono::high_resolution_clock::now(), - location_, - std::this_thread::get_id()}; - logger::Logger::instance().PushLog(message); - } + if (logger::Logger::instance().IsEnabledFor(component_, + logger::LogLevel::TRACE_LEVEL)) { + logger::LogMessage message{component_, + LogLevel::TRACE_LEVEL, + "Enter", + std::chrono::high_resolution_clock::now(), + location_, + std::this_thread::get_id()}; + logger::Logger::instance().PushLog(message); } } AutoTrace::~AutoTrace() { - if (logger::logger_status != logger::DeletingLoggerThread) { - if (logger::Logger::instance().IsEnabledFor( - component_, logger::LogLevel::TRACE_LEVEL)) { - logger::LogMessage message{component_, - LogLevel::TRACE_LEVEL, - "Exit", - std::chrono::high_resolution_clock::now(), - location_, - std::this_thread::get_id()}; - logger::Logger::instance().PushLog(message); - } + if (logger::Logger::instance().IsEnabledFor(component_, + logger::LogLevel::TRACE_LEVEL)) { + logger::LogMessage message{component_, + LogLevel::TRACE_LEVEL, + "Exit", + std::chrono::high_resolution_clock::now(), + location_, + std::this_thread::get_id()}; + logger::Logger::instance().PushLog(message); } } diff --git a/src/components/utils/src/logger/logger_impl.cc b/src/components/utils/src/logger/logger_impl.cc index 1dae0ede3c..1439f7327a 100644 --- a/src/components/utils/src/logger/logger_impl.cc +++ b/src/components/utils/src/logger/logger_impl.cc @@ -37,10 +37,7 @@ namespace logger { LoggerImpl::LoggerImpl(bool use_message_loop_thread) - : impl_(nullptr), use_message_loop_thread_(use_message_loop_thread) { - if (!use_message_loop_thread_) - logger::logger_status = LoggerThreadIsNotUsed; -} + : impl_(nullptr), use_message_loop_thread_(use_message_loop_thread) {} void LoggerImpl::Init(std::unique_ptr<ThirdPartyLoggerInterface>&& impl) { assert(impl_ == nullptr); @@ -51,7 +48,6 @@ void LoggerImpl::Init(std::unique_ptr<ThirdPartyLoggerInterface>&& impl) { if (use_message_loop_thread_) { auto deinit_logger = [](LogMessageLoopThread* logMsgThread) { delete logMsgThread; - logger::logger_status = logger::LoggerThreadNotCreated; }; if (!loop_thread_) { @@ -60,14 +56,12 @@ void LoggerImpl::Init(std::unique_ptr<ThirdPartyLoggerInterface>&& impl) { [this](LogMessage message) { impl_->PushLog(message); }), deinit_logger); } - logger::logger_status = logger::LoggerThreadCreated; } } void LoggerImpl::DeInit() { if (use_message_loop_thread_) { Flush(); - logger::logger_status = logger::LoggerThreadNotCreated; loop_thread_.reset(); } @@ -77,12 +71,10 @@ void LoggerImpl::DeInit() { } void LoggerImpl::Flush() { - if (use_message_loop_thread_ && - (logger::LoggerThreadCreated == logger::logger_status)) { - logger::LoggerStatus old_status = logger::logger_status; - logger::logger_status = logger::DeletingLoggerThread; - loop_thread_->WaitDumpQueue(); - logger::logger_status = old_status; + if (use_message_loop_thread_) { + if (loop_thread_) { + loop_thread_->WaitDumpQueue(); + } } } @@ -93,9 +85,10 @@ bool LoggerImpl::IsEnabledFor(const std::string& component, void LoggerImpl::PushLog(const LogMessage& log_message) { if (impl_) { - if (use_message_loop_thread_ && - (logger::LoggerThreadCreated == logger::logger_status)) { - loop_thread_->Push(log_message); + if (use_message_loop_thread_) { + if (loop_thread_) { + loop_thread_->Push(log_message); + } } else { impl_->PushLog(log_message); } @@ -126,7 +119,6 @@ void LogMessageLoopThread::Handle(const LogMessage message) { LogMessageLoopThread::~LogMessageLoopThread() { // we'll have to drop messages // while deleting logger thread - logger::logger_status = logger::DeletingLoggerThread; LogMessageLoopThreadTemplate::Shutdown(); } diff --git a/src/components/utils/src/logger_status.cc b/src/components/utils/src/logger_status.cc deleted file mode 100644 index ea9dfa3f22..0000000000 --- a/src/components/utils/src/logger_status.cc +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright (c) 2014, Ford Motor Company - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following - * disclaimer in the documentation and/or other materials provided with the - * distribution. - * - * Neither the name of the Ford Motor Company nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -#include "utils/logger_status.h" - -namespace logger { - -volatile LoggerStatus logger_status = LoggerThreadNotCreated; - -} // namespace logger |