From c39bc4ecabae37e2f7670c443449e5b8377e2232 Mon Sep 17 00:00:00 2001 From: lifajucejo Date: Sun, 30 Sep 2018 19:07:06 -0400 Subject: [PATCH] [LIBNX] Synchronize nxlink logging - Logs were interleaved and caused instability on certain setups --- frontend/drivers/platform_switch.c | 6 +++++- verbosity.c | 19 +++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/frontend/drivers/platform_switch.c b/frontend/drivers/platform_switch.c index 171d05d8ac..6bdea42936 100644 --- a/frontend/drivers/platform_switch.c +++ b/frontend/drivers/platform_switch.c @@ -62,6 +62,10 @@ static uint32_t *splashData = NULL; static bool psmInitialized = false; +#ifdef NXLINK +extern bool nxlink_connected; +#endif + #endif // HAVE_LIBNX static void get_first_valid_core(char *path_return) @@ -614,7 +618,7 @@ static void frontend_switch_init(void *data) #endif // HAVE_OPENGL #ifdef NXLINK socketInitializeDefault(); - nxlinkStdio(); + nxlink_connected = nxlinkStdio() != -1; #ifndef IS_SALAMANDER verbosity_enable(); #endif // IS_SALAMANDER diff --git a/verbosity.c b/verbosity.c index 4b8dd7cc92..823607b583 100644 --- a/verbosity.c +++ b/verbosity.c @@ -63,6 +63,11 @@ static void* log_file_buf = NULL; static bool main_verbosity = false; static bool log_file_initialized = false; +#ifdef NXLINK +static Mutex nxlink_mtx; +bool nxlink_connected = false; +#endif + void verbosity_enable(void) { main_verbosity = true; @@ -101,6 +106,11 @@ void retro_main_log_file_init(const char *path) if (log_file_initialized) return; +#ifdef NXLINK + if (path == NULL && nxlink_connected) + mutexInit(&nxlink_mtx); +#endif + log_file_fp = stderr; if (path == NULL) return; @@ -199,6 +209,10 @@ void RARCH_LOG_V(const char *tag, const char *fmt, va_list ap) ui_companion_driver_log_msg(buffer); #else +#if defined(NXLINK) && !defined(HAVE_FILE_LOGGER) + if (nxlink_connected) + mutexLock(&nxlink_mtx); +#endif if (fp) { fprintf(fp, "%s ", @@ -206,6 +220,11 @@ void RARCH_LOG_V(const char *tag, const char *fmt, va_list ap) vfprintf(fp, fmt, ap); fflush(fp); } +#if defined(NXLINK) && !defined(HAVE_FILE_LOGGER) + if (nxlink_connected) + mutexUnlock(&nxlink_mtx); +#endif + #endif } #endif