diff --git a/epan/except.c b/epan/except.c index b37cbdb04b..a9bf83fb6a 100644 --- a/epan/except.c +++ b/epan/except.c @@ -143,7 +143,7 @@ static void (*uh_catcher_ptr)(except_t *) = unhandled_catcher; * the size_t issue doesn't exists here. Pheew.. */ static void *(*allocator)(size_t) = (void *(*)(size_t)) g_malloc; static void (*deallocator)(void *) = g_free; -static struct except_stacknode *stack_top; +static WS_THREAD_LOCAL struct except_stacknode *stack_top; #define get_top() (stack_top) #define set_top(T) (stack_top = (T)) diff --git a/include/ws_attributes.h b/include/ws_attributes.h index c1082d1530..f3ecf598f1 100644 --- a/include/ws_attributes.h +++ b/include/ws_attributes.h @@ -75,6 +75,23 @@ extern "C" { #define WS_RETNONNULL #endif +/* + * WS_THREAD_LOCAL means "this variable should go in thread-local + * storage. + * + * Based on + * + * https://en.wikipedia.org/w/index.php?title=Thread-local_storage&oldid=1064900318#C_and_C++ + * + * the major UN*X C compilers support __thread and the major Windows C + * compilers support __declspec(thread). + */ +#ifdef _WIN32 + #define WS_THREAD_LOCAL __declspec(thread) +#else + #define WS_THREAD_LOCAL __thread +#endif + #ifdef __cplusplus } #endif /* __cplusplus */