aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlorian Dold <florian.dold@gmail.com>2019-05-09 14:51:50 +0200
committerFlorian Dold <florian.dold@gmail.com>2019-05-09 14:54:00 +0200
commit67c3314628930be7e6a9d224456c8dac0f4c8fd4 (patch)
tree6d4a141ee37d13aaea3435a1621ca4e323b7ff3f
parent95096540e381d784ab0d28b6cde2935b9b269558 (diff)
downloadgnunet-67c3314628930be7e6a9d224456c8dac0f4c8fd4.tar.gz
gnunet-67c3314628930be7e6a9d224456c8dac0f4c8fd4.zip
towards thread-safe logging
(Thread-safe logging isn't really relevant for GNUnet itself, but it is necessary for the GNU Taler exchange)
-rw-r--r--configure.ac14
-rw-r--r--src/include/platform.h6
-rw-r--r--src/util/common_logging.c12
3 files changed, 25 insertions, 7 deletions
diff --git a/configure.ac b/configure.ac
index e00b8ae1b..b1e1c1aca 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1795,6 +1795,20 @@ else
1795fi 1795fi
1796AC_DEFINE_UNQUOTED([ENABLE_WINDOWS_WORKAROUNDS], $workarounds, [enable workarounds used on Windows (only useful for test cases)]) 1796AC_DEFINE_UNQUOTED([ENABLE_WINDOWS_WORKAROUNDS], $workarounds, [enable workarounds used on Windows (only useful for test cases)])
1797 1797
1798
1799# Check if the __thread storage class for thread-local storage is available.
1800AC_MSG_CHECKING(whether __thread is supported)
1801AC_LINK_IFELSE(
1802 [AC_LANG_PROGRAM([#include <stdlib.h>
1803 #undef __thread
1804 static __thread int a = 1;],
1805 [exit(a-1);])],
1806 [have_thread_local_gcc=1],[have_thread_local_gcc=0])
1807AC_DEFINE_UNQUOTED([HAVE_THREAD_LOCAL_GCC],$have_thread_local_gcc,[Define this if __thread is supported])
1808AS_IF([test "x$have_thread_local_gcc" = "x1"],
1809 [AC_MSG_RESULT(yes)],
1810 [AC_MSG_RESULT(no)])
1811
1798# gcov compilation 1812# gcov compilation
1799AC_MSG_CHECKING(whether to compile with support for code coverage analysis) 1813AC_MSG_CHECKING(whether to compile with support for code coverage analysis)
1800AC_ARG_ENABLE([coverage], 1814AC_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);
289#define PATH_MAX 4096 289#define PATH_MAX 4096
290#endif 290#endif
291 291
292 292#if HAVE_THREAD_LOCAL_GCC
293#define GNUNET_THREAD_LOCAL __thread
294#else
295#define GNUNET_THREAD_LOCAL
296#endif
293 297
294#endif 298#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
100 * Note that this message maybe truncated to the first BULK_TRACK_SIZE 100 * Note that this message maybe truncated to the first BULK_TRACK_SIZE
101 * characters, in which case it is NOT 0-terminated! 101 * characters, in which case it is NOT 0-terminated!
102 */ 102 */
103static char last_bulk[BULK_TRACK_SIZE] __attribute__ ((nonstring)); 103static GNUNET_THREAD_LOCAL char last_bulk[BULK_TRACK_SIZE] __attribute__ ((nonstring));
104 104
105/** 105/**
106 * Type of the last bulk message. 106 * Type of the last bulk message.
107 */ 107 */
108static enum GNUNET_ErrorType last_bulk_kind; 108static GNUNET_THREAD_LOCAL enum GNUNET_ErrorType last_bulk_kind;
109 109
110/** 110/**
111 * Time of the last bulk error message (0 for none) 111 * Time of the last bulk error message (0 for none)
112 */ 112 */
113static struct GNUNET_TIME_Absolute last_bulk_time; 113static GNUNET_THREAD_LOCAL struct GNUNET_TIME_Absolute last_bulk_time;
114 114
115/** 115/**
116 * Number of times that bulk message has been repeated since. 116 * Number of times that bulk message has been repeated since.
117 */ 117 */
118static unsigned int last_bulk_repeat; 118static GNUNET_THREAD_LOCAL unsigned int last_bulk_repeat;
119 119
120/** 120/**
121 * Component when the last bulk was logged. Will be 0-terminated. 121 * Component when the last bulk was logged. Will be 0-terminated.
122 */ 122 */
123static char last_bulk_comp[COMP_TRACK_SIZE + 1]; 123static GNUNET_THREAD_LOCAL char last_bulk_comp[COMP_TRACK_SIZE + 1];
124 124
125/** 125/**
126 * Running component. 126 * Running component.
@@ -150,7 +150,7 @@ static struct CustomLogger *loggers;
150/** 150/**
151 * Number of log calls to ignore. 151 * Number of log calls to ignore.
152 */ 152 */
153static int skip_log = 0; 153static GNUNET_THREAD_LOCAL int skip_log = 0;
154 154
155/** 155/**
156 * File descriptor to use for "stderr", or NULL for none. 156 * File descriptor to use for "stderr", or NULL for none.