From 6efa2e128c40d714b048dd370cb8aa32c37bd2c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B3zef=20Kucia?= Date: Thu, 31 May 2018 15:17:34 +0200 Subject: [PATCH] winex11: Make get_vulkan_driver() thread-safe. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Józef Kucia Signed-off-by: Alexandre Julliard --- dlls/winex11.drv/vulkan.c | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/dlls/winex11.drv/vulkan.c b/dlls/winex11.drv/vulkan.c index 148908b5117..a72be33be34 100644 --- a/dlls/winex11.drv/vulkan.c +++ b/dlls/winex11.drv/vulkan.c @@ -86,21 +86,17 @@ static inline struct wine_vk_surface *surface_from_handle(VkSurfaceKHR handle) return (struct wine_vk_surface *)(uintptr_t)handle; } -static BOOL wine_vk_init(void) +static void *vulkan_handle; + +static BOOL WINAPI wine_vk_init(INIT_ONCE *once, void *param, void **context) { - static BOOL init_done = FALSE; - static void *vulkan_handle; - - if (init_done) return (vulkan_handle != NULL); - init_done = TRUE; - if (!(vulkan_handle = wine_dlopen(SONAME_LIBVULKAN, RTLD_NOW, NULL, 0))) { ERR("Failed to load %s\n", SONAME_LIBVULKAN); - return FALSE; + return TRUE; } -#define LOAD_FUNCPTR(f) if ((p##f = wine_dlsym(vulkan_handle, #f, NULL, 0)) == NULL) return FALSE; +#define LOAD_FUNCPTR(f) if ((p##f = wine_dlsym(vulkan_handle, #f, NULL, 0)) == NULL) goto fail; LOAD_FUNCPTR(vkAcquireNextImageKHR) LOAD_FUNCPTR(vkCreateInstance) LOAD_FUNCPTR(vkCreateSwapchainKHR) @@ -121,6 +117,11 @@ static BOOL wine_vk_init(void) #undef LOAD_FUNCPTR return TRUE; + +fail: + wine_dlclose(vulkan_handle, NULL, 0); + vulkan_handle = NULL; + return TRUE; } /* Helper function for converting between win32 and X11 compatible VkInstanceCreateInfo. @@ -558,13 +559,16 @@ static void *X11DRV_get_vk_instance_proc_addr(VkInstance instance, const char *n const struct vulkan_funcs *get_vulkan_driver(UINT version) { + static INIT_ONCE init_once = INIT_ONCE_STATIC_INIT; + if (version != WINE_VULKAN_DRIVER_VERSION) { ERR("version mismatch, vulkan wants %u but driver has %u\n", version, WINE_VULKAN_DRIVER_VERSION); return NULL; } - if (wine_vk_init()) + InitOnceExecuteOnce(&init_once, wine_vk_init, NULL, NULL); + if (vulkan_handle) return &vulkan_funcs; return NULL;