glapi: Support "ELF" TLS on Windows

To avoid a massive rename, I'm leaving this as a misnomer, it's not
really ELF TLS, but it's the same concept.

Note that Windows doesn't support thread-local variables imported
or exported between modules, so we can only support this when we're
not using a shared glapi.

Closes: https://gitlab.freedesktop.org/mesa/mesa/-/issues/4050
Reviewed-by: Jose Fonseca <jfonseca@vmware.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/9165>
This commit is contained in:
Jesse Natalie
2021-02-19 14:55:57 -08:00
committed by Marge Bot
parent d7e1f492bc
commit ba141b95a7
3 changed files with 14 additions and 1 deletions

View File

@@ -449,7 +449,9 @@ endif
# Android uses emutls for versions <= P/28. For USE_ELF_TLS we need ELF TLS.
use_elf_tls = false
if not ['windows', 'freebsd', 'openbsd', 'haiku'].contains(host_machine.system()) and (not with_platform_android or get_option('platform-sdk-version') >= 29)
if (not ['freebsd', 'openbsd', 'haiku'].contains(host_machine.system()) and
(not with_platform_android or get_option('platform-sdk-version') >= 29) and
(not with_platform_windows or not with_shared_glapi))
pre_args += '-DUSE_ELF_TLS'
use_elf_tls = true
endif

View File

@@ -78,11 +78,16 @@ struct _glapi_table;
#if defined (USE_ELF_TLS)
#ifdef _WIN32
extern __declspec(thread) struct _glapi_table * _glapi_tls_Dispatch;
extern __declspec(thread) void * _glapi_tls_Context;
#else
_GLAPI_EXPORT extern __thread struct _glapi_table * _glapi_tls_Dispatch
__attribute__((tls_model("initial-exec")));
_GLAPI_EXPORT extern __thread void * _glapi_tls_Context
__attribute__((tls_model("initial-exec")));
#endif
_GLAPI_EXPORT extern const struct _glapi_table *_glapi_Dispatch;
_GLAPI_EXPORT extern const void *_glapi_Context;

View File

@@ -99,12 +99,18 @@ extern void (*__glapi_noop_table[])(void);
/*@{*/
#if defined(USE_ELF_TLS)
#ifdef _WIN32
__declspec(thread) struct _glapi_table *u_current_table
= (struct _glapi_table *) table_noop_array;
__declspec(thread) void *u_current_context;
#else
__thread struct _glapi_table *u_current_table
__attribute__((tls_model("initial-exec")))
= (struct _glapi_table *) table_noop_array;
__thread void *u_current_context
__attribute__((tls_model("initial-exec")));
#endif
#else