From 4beaf8200aa658c15d2b138d1754983a7eb253e3 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Sat, 23 Jun 2012 22:25:58 +0000 Subject: [PATCH] -LRN: Lock the output on W32: Purely W32 patch. It was needed for some threading-related debugging i did for select() wrapper. Shouldn't harm to have it, in case i do logging from multiple threads again. --- src/util/common_logging.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/util/common_logging.c b/src/util/common_logging.c index 20f852c35..6c3dda9bc 100644 --- a/src/util/common_logging.c +++ b/src/util/common_logging.c @@ -737,6 +737,10 @@ GNUNET_logger_remove (GNUNET_Logger logger, void *logger_cls) GNUNET_free (pos); } +#if WINDOWS +CRITICAL_SECTION output_message_cs; +#endif + /** * Actually output the log message. @@ -751,7 +755,9 @@ output_message (enum GNUNET_ErrorType kind, const char *comp, const char *datestr, const char *msg) { struct CustomLogger *pos; - +#if WINDOWS + EnterCriticalSection (&output_message_cs); +#endif if (NULL != GNUNET_stderr) { FPRINTF (GNUNET_stderr, "%s %s %s %s", datestr, comp, @@ -764,6 +770,9 @@ output_message (enum GNUNET_ErrorType kind, const char *comp, pos->logger (pos->logger_cls, kind, comp, datestr, msg); pos = pos->next; } +#if WINDOWS + LeaveCriticalSection (&output_message_cs); +#endif } @@ -1141,6 +1150,10 @@ void __attribute__ ((constructor)) GNUNET_util_cl_init () #ifdef MINGW GNInitWinEnv (NULL); #endif +#if WINDOWS + if (!InitializeCriticalSectionAndSpinCount (&output_message_cs, 0x00000400)) + GNUNET_abort (); +#endif } @@ -1149,6 +1162,9 @@ void __attribute__ ((constructor)) GNUNET_util_cl_init () */ void __attribute__ ((destructor)) GNUNET_util_cl_fini () { +#if WINDOWS + DeleteCriticalSection (&output_message_cs); +#endif #ifdef MINGW GNShutdownWinEnv (); #endif -- 2.25.1