diff --git a/src/xenia/logging.cc b/src/xenia/logging.cc index 99f3963e6..14b19aaf2 100644 --- a/src/xenia/logging.cc +++ b/src/xenia/logging.cc @@ -10,6 +10,18 @@ #include #include +#include + +#include + + +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()) {