From 8e4f4e04ca61594e3dec31bad70eaf6cdf86ad8f Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Tue, 14 Jan 2014 00:56:03 +0300 Subject: add support for thread safe writing to log. --- src/logger.h | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'src/logger.h') diff --git a/src/logger.h b/src/logger.h index 0941a0e63..c68277ce5 100644 --- a/src/logger.h +++ b/src/logger.h @@ -24,7 +24,11 @@ #define LOGGER_H #include "main.h" + +#include + #include +#include #include "localconsts.h" @@ -75,6 +79,19 @@ class Logger final #else __attribute__((__format__(gnu_printf, 2, 3))) #endif +#endif + ; + + /** + * Enters a message in the log (thread safe). + */ + void log_r(const char *const log_text, ...) +#ifdef __GNUC__ +#ifdef __OpenBSD__ + __attribute__((__format__(printf, 2, 3))) +#else + __attribute__((__format__(gnu_printf, 2, 3))) +#endif #endif ; @@ -88,6 +105,8 @@ class Logger final */ void log(const std::string &str); + void flush(); + #ifdef ENABLEDEBUGLOG /** * Enters debug message in the log. The message will be timestamped. @@ -113,6 +132,9 @@ class Logger final private: std::ofstream mLogFile; + std::vector mDelayedLog; + SDL_mutex *mMutex; + volatile bool mThreadLocked; bool mLogToStandardOut; bool mDebugLog; }; -- cgit v1.2.3-60-g2f50