mirror of
https://github.com/RetroDECK/ES-DE.git
synced 2025-02-18 04:45:39 +00:00
Removed some code comments.
This commit is contained in:
parent
309a87a2a3
commit
502fb69b87
|
@ -11,35 +11,23 @@
|
||||||
|
|
||||||
LogLevel Log::getReportingLevel()
|
LogLevel Log::getReportingLevel()
|
||||||
{
|
{
|
||||||
// Static Log functions need to grab the lock.
|
|
||||||
std::unique_lock<std::mutex> lock {sLogMutex};
|
std::unique_lock<std::mutex> lock {sLogMutex};
|
||||||
return sReportingLevel;
|
return sReportingLevel;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Log::setReportingLevel(LogLevel level)
|
void Log::setReportingLevel(LogLevel level)
|
||||||
{
|
{
|
||||||
// Static Log functions need to grab the lock.
|
|
||||||
std::unique_lock<std::mutex> lock {sLogMutex};
|
std::unique_lock<std::mutex> lock {sLogMutex};
|
||||||
sReportingLevel = level;
|
sReportingLevel = level;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string Log::getLogPath()
|
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";
|
return Utils::FileSystem::getHomePath() + "/.emulationstation/es_log.txt";
|
||||||
}
|
}
|
||||||
|
|
||||||
void Log::init()
|
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");
|
Utils::FileSystem::removeFile(getLogPath() + ".bak");
|
||||||
// Rename the previous log file.
|
// Rename the previous log file.
|
||||||
Utils::FileSystem::renameFile(getLogPath(), getLogPath() + ".bak", true);
|
Utils::FileSystem::renameFile(getLogPath(), getLogPath() + ".bak", true);
|
||||||
|
@ -48,7 +36,6 @@ void Log::init()
|
||||||
|
|
||||||
void Log::open()
|
void Log::open()
|
||||||
{
|
{
|
||||||
// Static Log functions need to grab the lock.
|
|
||||||
std::unique_lock<std::mutex> lock {sLogMutex};
|
std::unique_lock<std::mutex> lock {sLogMutex};
|
||||||
#if defined(_WIN64)
|
#if defined(_WIN64)
|
||||||
sFile.open(Utils::String::stringToWideString(getLogPath()).c_str());
|
sFile.open(Utils::String::stringToWideString(getLogPath()).c_str());
|
||||||
|
@ -59,14 +46,12 @@ void Log::open()
|
||||||
|
|
||||||
void Log::flush()
|
void Log::flush()
|
||||||
{
|
{
|
||||||
// Flush file. Static Log functions need to grab the lock.
|
|
||||||
std::unique_lock<std::mutex> lock {sLogMutex};
|
std::unique_lock<std::mutex> lock {sLogMutex};
|
||||||
sFile.flush();
|
sFile.flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Log::close()
|
void Log::close()
|
||||||
{
|
{
|
||||||
// Static Log functions need to grab the lock.
|
|
||||||
std::unique_lock<std::mutex> lock {sLogMutex};
|
std::unique_lock<std::mutex> lock {sLogMutex};
|
||||||
if (sFile.is_open())
|
if (sFile.is_open())
|
||||||
sFile.close();
|
sFile.close();
|
||||||
|
@ -74,8 +59,6 @@ void Log::close()
|
||||||
|
|
||||||
std::ostringstream& Log::get(LogLevel level)
|
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)};
|
time_t t {time(nullptr)};
|
||||||
struct tm tm;
|
struct tm tm;
|
||||||
#if defined(_WIN64)
|
#if defined(_WIN64)
|
||||||
|
@ -95,14 +78,6 @@ std::ostringstream& Log::get(LogLevel level)
|
||||||
Log::~Log()
|
Log::~Log()
|
||||||
{
|
{
|
||||||
mOutStringStream << std::endl;
|
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<std::mutex> lock {sLogMutex};
|
std::unique_lock<std::mutex> lock {sLogMutex};
|
||||||
|
|
||||||
if (!sFile.is_open()) {
|
if (!sFile.is_open()) {
|
||||||
|
|
|
@ -34,25 +34,18 @@ enum LogLevel {
|
||||||
class Log
|
class Log
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
// Deconstructor grabs the lock.
|
|
||||||
~Log();
|
~Log();
|
||||||
|
|
||||||
// No lock needed for get() as it operates on and returns non-static members.
|
|
||||||
std::ostringstream& get(LogLevel level = LogInfo);
|
std::ostringstream& get(LogLevel level = LogInfo);
|
||||||
|
|
||||||
// Lock is grabbed for sReportingLevel.
|
|
||||||
// This means level > Log::getReportingLevel() still requires the lock.
|
|
||||||
static LogLevel getReportingLevel();
|
static LogLevel getReportingLevel();
|
||||||
static void setReportingLevel(LogLevel level);
|
static void setReportingLevel(LogLevel level);
|
||||||
|
|
||||||
// getLogPath() is not thread-safe.
|
// These functions are not thread safe.
|
||||||
static std::string getLogPath();
|
static std::string getLogPath();
|
||||||
// init() is not thread-safe.
|
|
||||||
static void init();
|
static void init();
|
||||||
// open() is not fully thread-safe, as it uses getLogPath().
|
|
||||||
static void open();
|
static void open();
|
||||||
|
|
||||||
// The following static functions are thread-safe.
|
|
||||||
static void flush();
|
static void flush();
|
||||||
static void close();
|
static void close();
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue