c11: call impl_tss_dtor_invoke with tls callback for win32

Signed-off-by: Yonggang Luo <luoyonggang@gmail.com>
Reviewed-by: Jesse Natalie <jenatali@microsoft.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/17071>
This commit is contained in:
Yonggang Luo 2022-08-10 01:32:33 +08:00 committed by Marge Bot
parent e819f71379
commit 125a952b66
4 changed files with 46 additions and 3 deletions

View file

@ -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

View file

@ -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);
}

View file

@ -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

View file

@ -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;