mirror of
https://gitlab.winehq.org/wine/vkd3d.git
synced 2025-04-13 05:43:18 -07:00
vkd3d: Add a create thread implementation for Windows.
Signed-off-by: Alexandre Julliard <julliard@winehq.org> Signed-off-by: Henri Verbeet <hverbeet@codeweavers.com>
This commit is contained in:
parent
923ea7bb1e
commit
c78174f004
@ -4037,6 +4037,23 @@ void d3d12_device_mark_as_removed(struct d3d12_device *device, HRESULT reason,
|
|||||||
device->removed_reason = 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,
|
HRESULT vkd3d_create_thread(struct vkd3d_instance *instance,
|
||||||
PFN_vkd3d_thread thread_main, void *data, union vkd3d_thread_handle *thread)
|
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
|
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)))
|
if ((rc = pthread_create(&thread->pthread, NULL, thread_main, data)))
|
||||||
{
|
{
|
||||||
ERR("Failed to create thread, error %d.\n", rc);
|
ERR("Failed to create thread, error %d.\n", rc);
|
||||||
hr = hresult_from_errno(rc);
|
hr = hresult_from_errno(rc);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
return hr;
|
return hr;
|
||||||
@ -4075,11 +4108,20 @@ HRESULT vkd3d_join_thread(struct vkd3d_instance *instance, union vkd3d_thread_ha
|
|||||||
}
|
}
|
||||||
else
|
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)))
|
if ((rc = pthread_join(thread->pthread, NULL)))
|
||||||
{
|
{
|
||||||
ERR("Failed to join thread, error %d.\n", rc);
|
ERR("Failed to join thread, error %d.\n", rc);
|
||||||
hr = hresult_from_errno(rc);
|
hr = hresult_from_errno(rc);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
return hr;
|
return hr;
|
||||||
|
@ -40,7 +40,6 @@
|
|||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
#include <pthread.h>
|
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
|
||||||
#define VK_CALL(f) (vk_procs->f)
|
#define VK_CALL(f) (vk_procs->f)
|
||||||
@ -169,14 +168,13 @@ struct vkd3d_instance
|
|||||||
LONG refcount;
|
LONG refcount;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#ifdef _WIN32
|
||||||
|
|
||||||
union vkd3d_thread_handle
|
union vkd3d_thread_handle
|
||||||
{
|
{
|
||||||
pthread_t pthread;
|
|
||||||
void *handle;
|
void *handle;
|
||||||
};
|
};
|
||||||
|
|
||||||
#ifdef _WIN32
|
|
||||||
|
|
||||||
struct vkd3d_mutex
|
struct vkd3d_mutex
|
||||||
{
|
{
|
||||||
CRITICAL_SECTION lock;
|
CRITICAL_SECTION lock;
|
||||||
@ -241,6 +239,14 @@ static inline int vkd3d_cond_destroy(struct vkd3d_cond *cond)
|
|||||||
|
|
||||||
#else /* _WIN32 */
|
#else /* _WIN32 */
|
||||||
|
|
||||||
|
#include <pthread.h>
|
||||||
|
|
||||||
|
union vkd3d_thread_handle
|
||||||
|
{
|
||||||
|
pthread_t pthread;
|
||||||
|
void *handle;
|
||||||
|
};
|
||||||
|
|
||||||
struct vkd3d_mutex
|
struct vkd3d_mutex
|
||||||
{
|
{
|
||||||
pthread_mutex_t lock;
|
pthread_mutex_t lock;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user