diff --git a/src/c11/impl/meson.build b/src/c11/impl/meson.build index dbd9ecfdd05..c12f0e9eff9 100644 --- a/src/c11/impl/meson.build +++ b/src/c11/impl/meson.build @@ -24,6 +24,7 @@ files_mesa_util_c11 = files( if host_machine.system() == 'windows' files_mesa_util_c11 += 'threads_win32.c' + files_mesa_util_c11 += 'threads_win32_tls_callback.cpp' else files_mesa_util_c11 += 'threads_posix.c' endif diff --git a/src/c11/impl/threads_win32.c b/src/c11/impl/threads_win32.c index 5d78542dab4..1b2b42bce94 100644 --- a/src/c11/impl/threads_win32.c +++ b/src/c11/impl/threads_win32.c @@ -34,6 +34,8 @@ #include "c11/threads.h" +#include "threads_win32.h" + #ifndef WIN32_LEAN_AND_MEAN #define WIN32_LEAN_AND_MEAN 1 #endif @@ -77,7 +79,6 @@ Implementation limits: (see EMULATED_THREADS_USE_NATIVE_CALL_ONCE macro) - Emulated `mtx_timelock()' with mtx_trylock() + *busy loop* */ -static void impl_tss_dtor_invoke(void); // forward decl. struct impl_thrd_param { thrd_start_t func; @@ -91,7 +92,6 @@ static unsigned __stdcall impl_thrd_routine(void *p) memcpy(&pack, p, sizeof(struct impl_thrd_param)); free(p); code = pack.func(pack.arg); - impl_tss_dtor_invoke(); return (unsigned)code; } @@ -304,6 +304,11 @@ mtx_unlock(mtx_t *mtx) return thrd_success; } +void +__threads_win32_tls_callback(void) +{ + impl_tss_dtor_invoke(); +} /*------------------- 7.25.5 Thread functions -------------------*/ // 7.25.5.1 @@ -389,7 +394,6 @@ _Noreturn void thrd_exit(int res) { - impl_tss_dtor_invoke(); _endthreadex((unsigned)res); } diff --git a/src/c11/impl/threads_win32.h b/src/c11/impl/threads_win32.h new file mode 100644 index 00000000000..ef75fb03555 --- /dev/null +++ b/src/c11/impl/threads_win32.h @@ -0,0 +1,20 @@ +/* + * Copyright 2022 Yonggang Luo + * SPDX-License-Identifier: MIT + */ + +#ifndef C11_IMPL_THREADS_WIN32_H_ +#define C11_IMPL_THREADS_WIN32_H_ + + +#ifdef __cplusplus +extern "C" { +#endif + +void __threads_win32_tls_callback(void); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/src/c11/impl/threads_win32_tls_callback.cpp b/src/c11/impl/threads_win32_tls_callback.cpp new file mode 100644 index 00000000000..2d0506a75d2 --- /dev/null +++ b/src/c11/impl/threads_win32_tls_callback.cpp @@ -0,0 +1,18 @@ +/* + * Copyright 2022 Yonggang Luo + * SPDX-License-Identifier: MIT + */ + +#include "threads_win32.h" + +struct tls_callback +{ + tls_callback() + { + } + ~tls_callback() + { + __threads_win32_tls_callback(); + } +}; +static thread_local tls_callback tls_callback_instance;