From: Florian Dold Date: Thu, 9 May 2019 12:51:50 +0000 (+0200) Subject: towards thread-safe logging X-Git-Tag: v0.11.4~18 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=67c3314628930be7e6a9d224456c8dac0f4c8fd4;p=oweals%2Fgnunet.git towards thread-safe logging (Thread-safe logging isn't really relevant for GNUnet itself, but it is necessary for the GNU Taler exchange) --- diff --git a/configure.ac b/configure.ac index e00b8ae1b..b1e1c1aca 100644 --- a/configure.ac +++ b/configure.ac @@ -1795,6 +1795,20 @@ else fi AC_DEFINE_UNQUOTED([ENABLE_WINDOWS_WORKAROUNDS], $workarounds, [enable workarounds used on Windows (only useful for test cases)]) + +# Check if the __thread storage class for thread-local storage is available. +AC_MSG_CHECKING(whether __thread is supported) +AC_LINK_IFELSE( + [AC_LANG_PROGRAM([#include + #undef __thread + static __thread int a = 1;], + [exit(a-1);])], + [have_thread_local_gcc=1],[have_thread_local_gcc=0]) +AC_DEFINE_UNQUOTED([HAVE_THREAD_LOCAL_GCC],$have_thread_local_gcc,[Define this if __thread is supported]) +AS_IF([test "x$have_thread_local_gcc" = "x1"], + [AC_MSG_RESULT(yes)], + [AC_MSG_RESULT(no)]) + # gcov compilation AC_MSG_CHECKING(whether to compile with support for code coverage analysis) AC_ARG_ENABLE([coverage], diff --git a/src/include/platform.h b/src/include/platform.h index 01b0bcf9e..23e640ec1 100644 --- a/src/include/platform.h +++ b/src/include/platform.h @@ -289,6 +289,10 @@ atoll (const char *nptr); #define PATH_MAX 4096 #endif - +#if HAVE_THREAD_LOCAL_GCC +#define GNUNET_THREAD_LOCAL __thread +#else +#define GNUNET_THREAD_LOCAL +#endif #endif diff --git a/src/util/common_logging.c b/src/util/common_logging.c index de30cab3a..34002e0fc 100644 --- a/src/util/common_logging.c +++ b/src/util/common_logging.c @@ -100,27 +100,27 @@ struct CustomLogger * Note that this message maybe truncated to the first BULK_TRACK_SIZE * characters, in which case it is NOT 0-terminated! */ -static char last_bulk[BULK_TRACK_SIZE] __attribute__ ((nonstring)); +static GNUNET_THREAD_LOCAL char last_bulk[BULK_TRACK_SIZE] __attribute__ ((nonstring)); /** * Type of the last bulk message. */ -static enum GNUNET_ErrorType last_bulk_kind; +static GNUNET_THREAD_LOCAL enum GNUNET_ErrorType last_bulk_kind; /** * Time of the last bulk error message (0 for none) */ -static struct GNUNET_TIME_Absolute last_bulk_time; +static GNUNET_THREAD_LOCAL struct GNUNET_TIME_Absolute last_bulk_time; /** * Number of times that bulk message has been repeated since. */ -static unsigned int last_bulk_repeat; +static GNUNET_THREAD_LOCAL unsigned int last_bulk_repeat; /** * Component when the last bulk was logged. Will be 0-terminated. */ -static char last_bulk_comp[COMP_TRACK_SIZE + 1]; +static GNUNET_THREAD_LOCAL char last_bulk_comp[COMP_TRACK_SIZE + 1]; /** * Running component. @@ -150,7 +150,7 @@ static struct CustomLogger *loggers; /** * Number of log calls to ignore. */ -static int skip_log = 0; +static GNUNET_THREAD_LOCAL int skip_log = 0; /** * File descriptor to use for "stderr", or NULL for none.