diff --git a/meson.build b/meson.build index 9d59158e941..142f3839e91 100644 --- a/meson.build +++ b/meson.build @@ -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 diff --git a/src/mapi/glapi/glapi.h b/src/mapi/glapi/glapi.h index b11fe46107b..da3d4524931 100644 --- a/src/mapi/glapi/glapi.h +++ b/src/mapi/glapi/glapi.h @@ -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; diff --git a/src/mapi/u_current.c b/src/mapi/u_current.c index 0e133e0e419..0a749ec87d2 100644 --- a/src/mapi/u_current.c +++ b/src/mapi/u_current.c @@ -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