Signed-off-by: Alexandre Julliard julliard@winehq.org --- libs/vkd3d/device.c | 42 ++++++++++++++++++++++++++++++++++++++ libs/vkd3d/vkd3d_private.h | 14 +++++++++---- 2 files changed, 52 insertions(+), 4 deletions(-)
diff --git a/libs/vkd3d/device.c b/libs/vkd3d/device.c index fe90eb37ef00..3360fd6eeeb8 100644 --- a/libs/vkd3d/device.c +++ b/libs/vkd3d/device.c @@ -4037,6 +4037,23 @@ void d3d12_device_mark_as_removed(struct d3d12_device *device, HRESULT reason, device->removed_reason = reason; }
+ +#ifdef _WIN32 +struct thread_data +{ + PFN_vkd3d_thread main_pfn; + void *data; +}; + +static DWORD WINAPI call_thread_main(void *data) +{ + struct thread_data *thread_data = data; + thread_data->main_pfn(thread_data->data); + vkd3d_free(thread_data); + return 0; +} +#endif + HRESULT vkd3d_create_thread(struct vkd3d_instance *instance, PFN_vkd3d_thread thread_main, void *data, union vkd3d_thread_handle *thread) { @@ -4053,11 +4070,27 @@ HRESULT vkd3d_create_thread(struct vkd3d_instance *instance, } else { +#ifdef _WIN32 + struct thread_data *thread_data; + + if (!(thread_data = vkd3d_malloc(sizeof(*thread_data)))) + return E_OUTOFMEMORY; + + thread_data->main_pfn = thread_main; + thread_data->data = data; + if (!(thread->handle = CreateThread(NULL, 0, call_thread_main, thread_data, 0, NULL))) + { + ERR("Failed to create thread, error %d.\n", GetLastError()); + vkd3d_free(thread_data); + hr = E_FAIL; + } +#else if ((rc = pthread_create(&thread->pthread, NULL, thread_main, data))) { ERR("Failed to create thread, error %d.\n", rc); hr = hresult_from_errno(rc); } +#endif }
return hr; @@ -4075,11 +4108,20 @@ HRESULT vkd3d_join_thread(struct vkd3d_instance *instance, union vkd3d_thread_ha } else { +#ifdef _WIN32 + if ((rc = WaitForSingleObject(thread->handle, INFINITE)) != WAIT_OBJECT_0) + { + ERR("Failed to wait for thread, ret %#x.\n", rc); + hr = E_FAIL; + } + CloseHandle(thread->handle); +#else if ((rc = pthread_join(thread->pthread, NULL))) { ERR("Failed to join thread, error %d.\n", rc); hr = hresult_from_errno(rc); } +#endif }
return hr; diff --git a/libs/vkd3d/vkd3d_private.h b/libs/vkd3d/vkd3d_private.h index ece111325e77..67989c11285a 100644 --- a/libs/vkd3d/vkd3d_private.h +++ b/libs/vkd3d/vkd3d_private.h @@ -40,7 +40,6 @@ #include <assert.h> #include <inttypes.h> #include <limits.h> -#include <pthread.h> #include <stdbool.h>
#define VK_CALL(f) (vk_procs->f) @@ -169,14 +168,13 @@ struct vkd3d_instance LONG refcount; };
+#ifdef _WIN32 + union vkd3d_thread_handle { - pthread_t pthread; void *handle; };
-#ifdef _WIN32 - struct vkd3d_mutex { CRITICAL_SECTION lock; @@ -241,6 +239,14 @@ static inline int vkd3d_cond_destroy(struct vkd3d_cond *cond)
#else /* _WIN32 */
+#include <pthread.h> + +union vkd3d_thread_handle +{ + pthread_t pthread; + void *handle; +}; + struct vkd3d_mutex { pthread_mutex_t lock;