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/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(
@ -54,15 +66,18 @@ void xe_log_line(const char* file_path, const uint32_t line_number,
fmt, args);
va_end(args);
fprintf(stderr, buffer);
fflush(stderr);
if (!FLAGS_fast_stdout) {
xe_mutex_lock(log_lock);
}
#if 0// defined(OutputDebugString)
OutputDebugStringA(buffer);
#else
XEIGNORE(fprintf(stdout, buffer));
fflush(stdout);
#endif // OutputDebugString
if (!FLAGS_fast_stdout) {
xe_mutex_unlock(log_lock);
}
}
void xe_handle_fatal(
@ -76,12 +91,18 @@ void xe_handle_fatal(
fmt, args);
va_end(args);
if (!FLAGS_fast_stdout) {
xe_mutex_lock(log_lock);
}
#if defined(OutputDebugString)
OutputDebugStringA(buffer);
#endif // OutputDebugString
fprintf(stderr, buffer);
#else
XEIGNORE(fprintf(stderr, buffer));
fflush(stderr);
#endif // OutputDebugString
if (!FLAGS_fast_stdout) {
xe_mutex_unlock(log_lock);
}
#if XE_LIKE_WIN32
if (!xe_has_console()) {