From 502fb69b87f0cba68c2cb1c742201ac126fc3199 Mon Sep 17 00:00:00 2001 From: Leon Styhre Date: Fri, 4 Nov 2022 12:55:00 +0100 Subject: [PATCH] Removed some code comments. --- es-core/src/Log.cpp | 25 ------------------------- es-core/src/Log.h | 9 +-------- 2 files changed, 1 insertion(+), 33 deletions(-) diff --git a/es-core/src/Log.cpp b/es-core/src/Log.cpp index fea8a2635..8e2ab5de3 100644 --- a/es-core/src/Log.cpp +++ b/es-core/src/Log.cpp @@ -11,35 +11,23 @@ LogLevel Log::getReportingLevel() { - // Static Log functions need to grab the lock. std::unique_lock lock {sLogMutex}; return sReportingLevel; } void Log::setReportingLevel(LogLevel level) { - // Static Log functions need to grab the lock. std::unique_lock lock {sLogMutex}; sReportingLevel = level; } std::string Log::getLogPath() { - // No attempt is made to make this thread-safe. - // Currently getLogPath is public, and called in contexts with - // and without sLogMutex locked. - - // getHomePath() currently does not generate any Log messages. return Utils::FileSystem::getHomePath() + "/.emulationstation/es_log.txt"; } void Log::init() { - // No attempt is made to make this thread-safe. - // It is unlikely to be called across multiple threads. - // Both removeFile and renameFile might generate log messages, - // so they might try to grab the lock. - Utils::FileSystem::removeFile(getLogPath() + ".bak"); // Rename the previous log file. Utils::FileSystem::renameFile(getLogPath(), getLogPath() + ".bak", true); @@ -48,7 +36,6 @@ void Log::init() void Log::open() { - // Static Log functions need to grab the lock. std::unique_lock lock {sLogMutex}; #if defined(_WIN64) sFile.open(Utils::String::stringToWideString(getLogPath()).c_str()); @@ -59,14 +46,12 @@ void Log::open() void Log::flush() { - // Flush file. Static Log functions need to grab the lock. std::unique_lock lock {sLogMutex}; sFile.flush(); } void Log::close() { - // Static Log functions need to grab the lock. std::unique_lock lock {sLogMutex}; if (sFile.is_open()) sFile.close(); @@ -74,8 +59,6 @@ void Log::close() std::ostringstream& Log::get(LogLevel level) { - // This function is not-static, but only touches instance member variables. - // The lock is not needed. time_t t {time(nullptr)}; struct tm tm; #if defined(_WIN64) @@ -95,14 +78,6 @@ std::ostringstream& Log::get(LogLevel level) Log::~Log() { mOutStringStream << std::endl; - - // Log() constructor does not need the lock. - // Log::get() does not need the lock. - // get(..) << msg << msg also does not need the lock, - // since get() returns the instance member mOutStringStream. - - // It is only now that we need the lock, to guard access to - // both std::cerr and sFile. std::unique_lock lock {sLogMutex}; if (!sFile.is_open()) { diff --git a/es-core/src/Log.h b/es-core/src/Log.h index 833de1603..0f412b4eb 100644 --- a/es-core/src/Log.h +++ b/es-core/src/Log.h @@ -34,25 +34,18 @@ enum LogLevel { class Log { public: - // Deconstructor grabs the lock. ~Log(); - // No lock needed for get() as it operates on and returns non-static members. std::ostringstream& get(LogLevel level = LogInfo); - // Lock is grabbed for sReportingLevel. - // This means level > Log::getReportingLevel() still requires the lock. static LogLevel getReportingLevel(); static void setReportingLevel(LogLevel level); - // getLogPath() is not thread-safe. + // These functions are not thread safe. static std::string getLogPath(); - // init() is not thread-safe. static void init(); - // open() is not fully thread-safe, as it uses getLogPath(). static void open(); - // The following static functions are thread-safe. static void flush(); static void close();