winevulkan: Use pthread_rwlock_t in VkInstance_T.

Signed-off-by: Jacek Caban <jacek@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Jacek Caban 2021-04-13 00:53:31 +02:00 committed by Alexandre Julliard
parent a27d5bae11
commit 504213c9a7
3 changed files with 12 additions and 8 deletions

View File

@ -1,6 +1,7 @@
MODULE = winevulkan.dll MODULE = winevulkan.dll
IMPORTLIB = winevulkan IMPORTLIB = winevulkan
IMPORTS = user32 gdi32 advapi32 setupapi IMPORTS = user32 gdi32 advapi32 setupapi
EXTRALIBS = $(PTHREAD_LIBS)
C_SRCS = \ C_SRCS = \
vulkan.c \ vulkan.c \

View File

@ -91,9 +91,9 @@ static void wine_vk_add_handle_mapping(struct VkInstance_T *instance, uint64_t
{ {
mapping->native_handle = native_handle; mapping->native_handle = native_handle;
mapping->wine_wrapped_handle = wrapped_handle; mapping->wine_wrapped_handle = wrapped_handle;
AcquireSRWLockExclusive(&instance->wrapper_lock); pthread_rwlock_wrlock(&instance->wrapper_lock);
list_add_tail(&instance->wrappers, &mapping->link); list_add_tail(&instance->wrappers, &mapping->link);
ReleaseSRWLockExclusive(&instance->wrapper_lock); pthread_rwlock_unlock(&instance->wrapper_lock);
} }
} }
@ -103,9 +103,9 @@ static void wine_vk_remove_handle_mapping(struct VkInstance_T *instance, struct
{ {
if (instance->enable_wrapper_list) if (instance->enable_wrapper_list)
{ {
AcquireSRWLockExclusive(&instance->wrapper_lock); pthread_rwlock_wrlock(&instance->wrapper_lock);
list_remove(&mapping->link); list_remove(&mapping->link);
ReleaseSRWLockExclusive(&instance->wrapper_lock); pthread_rwlock_unlock(&instance->wrapper_lock);
} }
} }
@ -114,7 +114,7 @@ static uint64_t wine_vk_get_wrapper(struct VkInstance_T *instance, uint64_t nati
struct wine_vk_mapping *mapping; struct wine_vk_mapping *mapping;
uint64_t result = 0; uint64_t result = 0;
AcquireSRWLockShared(&instance->wrapper_lock); pthread_rwlock_rdlock(&instance->wrapper_lock);
LIST_FOR_EACH_ENTRY(mapping, &instance->wrappers, struct wine_vk_mapping, link) LIST_FOR_EACH_ENTRY(mapping, &instance->wrappers, struct wine_vk_mapping, link)
{ {
if (mapping->native_handle == native_handle) if (mapping->native_handle == native_handle)
@ -123,7 +123,7 @@ static uint64_t wine_vk_get_wrapper(struct VkInstance_T *instance, uint64_t nati
break; break;
} }
} }
ReleaseSRWLockShared(&instance->wrapper_lock); pthread_rwlock_unlock(&instance->wrapper_lock);
return result; return result;
} }
@ -666,6 +666,7 @@ static void wine_vk_instance_free(struct VkInstance_T *instance)
WINE_VK_REMOVE_HANDLE_MAPPING(instance, instance); WINE_VK_REMOVE_HANDLE_MAPPING(instance, instance);
} }
pthread_rwlock_destroy(&instance->wrapper_lock);
free(instance->utils_messengers); free(instance->utils_messengers);
free(instance); free(instance);
@ -882,7 +883,7 @@ VkResult WINAPI wine_vkCreateInstance(const VkInstanceCreateInfo *create_info,
} }
object->base.loader_magic = VULKAN_ICD_MAGIC_VALUE; object->base.loader_magic = VULKAN_ICD_MAGIC_VALUE;
list_init(&object->wrappers); list_init(&object->wrappers);
InitializeSRWLock(&object->wrapper_lock); pthread_rwlock_init(&object->wrapper_lock, NULL);
res = wine_vk_instance_convert_create_info(create_info, &create_info_host, object); res = wine_vk_instance_convert_create_info(create_info, &create_info_host, object);
if (res != VK_SUCCESS) if (res != VK_SUCCESS)

View File

@ -25,6 +25,8 @@
#define USE_STRUCT_CONVERSION #define USE_STRUCT_CONVERSION
#endif #endif
#include <pthread.h>
#include "wine/debug.h" #include "wine/debug.h"
#include "wine/heap.h" #include "wine/heap.h"
#include "wine/list.h" #include "wine/list.h"
@ -123,7 +125,7 @@ struct VkInstance_T
VkBool32 enable_wrapper_list; VkBool32 enable_wrapper_list;
struct list wrappers; struct list wrappers;
SRWLOCK wrapper_lock; pthread_rwlock_t wrapper_lock;
struct wine_debug_utils_messenger *utils_messengers; struct wine_debug_utils_messenger *utils_messengers;
uint32_t utils_messenger_count; uint32_t utils_messenger_count;