diff --git a/dlls/wined3d/adapter_vk.c b/dlls/wined3d/adapter_vk.c index 343abac1004..8e149de028f 100644 --- a/dlls/wined3d/adapter_vk.c +++ b/dlls/wined3d/adapter_vk.c @@ -518,9 +518,7 @@ static HRESULT adapter_vk_create_device(struct wined3d *wined3d, const struct wi goto fail; } - InitializeCriticalSection(&device_vk->allocator_cs); - if (device_vk->allocator_cs.DebugInfo != (RTL_CRITICAL_SECTION_DEBUG *)-1) - device_vk->allocator_cs.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": wined3d_device_vk.allocator_cs"); + wined3d_lock_init(&device_vk->allocator_cs, "wined3d_device_vk.allocator_cs"); *device = &device_vk->d; @@ -540,9 +538,7 @@ static void adapter_vk_destroy_device(struct wined3d_device *device) wined3d_device_cleanup(&device_vk->d); wined3d_allocator_cleanup(&device_vk->allocator); - if (device_vk->allocator_cs.DebugInfo != (RTL_CRITICAL_SECTION_DEBUG *)-1) - device_vk->allocator_cs.DebugInfo->Spare[0] = 0; - DeleteCriticalSection(&device_vk->allocator_cs); + wined3d_lock_cleanup(&device_vk->allocator_cs); VK_CALL(vkDestroyDevice(device_vk->vk_device, NULL)); heap_free(device_vk); diff --git a/dlls/wined3d/wined3d_private.h b/dlls/wined3d/wined3d_private.h index ef1062ec9b4..88c2f5ba285 100644 --- a/dlls/wined3d/wined3d_private.h +++ b/dlls/wined3d/wined3d_private.h @@ -5650,6 +5650,21 @@ struct wined3d_shader_limits unsigned int packed_input; }; +#define wined3d_lock_init(lock, name) wined3d_lock_init_(lock, __FILE__ ": " name) +static inline void wined3d_lock_init_(CRITICAL_SECTION *lock, const char *name) +{ + InitializeCriticalSection(lock); + if (lock->DebugInfo != (RTL_CRITICAL_SECTION_DEBUG *)-1) + lock->DebugInfo->Spare[0] = (DWORD_PTR)name; +} + +static inline void wined3d_lock_cleanup(CRITICAL_SECTION *lock) +{ + if (lock->DebugInfo != (RTL_CRITICAL_SECTION_DEBUG *)-1) + lock->DebugInfo->Spare[0] = 0; + DeleteCriticalSection(lock); +} + #ifdef __GNUC__ #define PRINTF_ATTR(fmt,args) __attribute__((format (printf,fmt,args))) #else