Adding lock to stdout logging. Disable with --fast_stdout.

Fixes #78.
This commit is contained in:
Ben Vanik 2014-05-21 11:24:44 -07:00
parent 1bb0b08a14
commit a001714fb0
1 changed files with 27 additions and 6 deletions

View File

@ -10,6 +10,18 @@
#include <xenia/logging.h> #include <xenia/logging.h>
#include <xenia/common.h> #include <xenia/common.h>
#include <xenia/core/mutex.h>
#include <gflags/gflags.h>
DEFINE_bool(fast_stdout, false,
"Don't lock around stdout/stderr. May introduce weirdness.");
namespace {
xe_mutex_t* log_lock = xe_mutex_alloc();
} // namespace
void xe_format_log_line( void xe_format_log_line(
@ -54,15 +66,18 @@ void xe_log_line(const char* file_path, const uint32_t line_number,
fmt, args); fmt, args);
va_end(args); va_end(args);
fprintf(stderr, buffer); if (!FLAGS_fast_stdout) {
fflush(stderr); xe_mutex_lock(log_lock);
}
#if 0// defined(OutputDebugString) #if 0// defined(OutputDebugString)
OutputDebugStringA(buffer); OutputDebugStringA(buffer);
#else #else
XEIGNORE(fprintf(stdout, buffer)); XEIGNORE(fprintf(stdout, buffer));
fflush(stdout); fflush(stdout);
#endif // OutputDebugString #endif // OutputDebugString
if (!FLAGS_fast_stdout) {
xe_mutex_unlock(log_lock);
}
} }
void xe_handle_fatal( void xe_handle_fatal(
@ -76,12 +91,18 @@ void xe_handle_fatal(
fmt, args); fmt, args);
va_end(args); va_end(args);
if (!FLAGS_fast_stdout) {
xe_mutex_lock(log_lock);
}
#if defined(OutputDebugString) #if defined(OutputDebugString)
OutputDebugStringA(buffer); OutputDebugStringA(buffer);
#endif // OutputDebugString #else
XEIGNORE(fprintf(stderr, buffer));
fprintf(stderr, buffer);
fflush(stderr); fflush(stderr);
#endif // OutputDebugString
if (!FLAGS_fast_stdout) {
xe_mutex_unlock(log_lock);
}
#if XE_LIKE_WIN32 #if XE_LIKE_WIN32
if (!xe_has_console()) { if (!xe_has_console()) {