Mon, 22 Dec 2025 00:20:41 +0100
define own cx_thread_local macro that is compatible to C11/C17, C23, and MSVC
| src/array_list.c | file | annotate | diff | comparison | revisions | |
| src/cx/common.h | file | annotate | diff | comparison | revisions |
--- a/src/array_list.c Mon Dec 22 00:20:01 2025 +0100 +++ b/src/array_list.c Mon Dec 22 00:20:41 2025 +0100 @@ -356,8 +356,8 @@ } #ifndef WITH_QSORT_R -static _Thread_local cx_compare_func2 cx_array_fn_for_qsort; -static _Thread_local void *cx_array_context_for_qsort; +static cx_thread_local cx_compare_func2 cx_array_fn_for_qsort; +static cx_thread_local void *cx_array_context_for_qsort; static int cx_array_qsort_wrapper(const void *l, const void *r) { return cx_array_fn_for_qsort(l, r, cx_array_context_for_qsort); }
--- a/src/cx/common.h Mon Dec 22 00:20:01 2025 +0100 +++ b/src/cx/common.h Mon Dec 22 00:20:41 2025 +0100 @@ -257,13 +257,22 @@ // --------------------------------------------------------------------------- -// MSVC specifics +// Support for thread_local // --------------------------------------------------------------------------- +#ifdef __cplusplus +#define cx_thread_local thread_local +#else // ! __cplusplus #ifdef _MSC_VER -// fix missing _Thread_local support -#define _Thread_local __declspec(thread) +#define cx_thread_local __declspec(thread) +#else // ! _MSC_VER +#if __STDC_VERSION__ < 202300L +#define cx_thread_local _Thread_local +#else // C23 or newer +#define cx_thread_local thread_local +#endif // C23 #endif // _MSC_VER +#endif // __cplusplus // --------------------------------------------------------------------------- // Exported and inlined functions