mirror of
https://gitlab.winehq.org/wine/vkd3d.git
synced 2025-01-28 13:05:02 -08:00
vkd3d: Factor out vkd3d_create_thread().
Signed-off-by: Józef Kucia <jkucia@codeweavers.com> Signed-off-by: Henri Verbeet <hverbeet@codeweavers.com> Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
parent
843349c5e0
commit
bc5e8a9cc2
@ -410,6 +410,7 @@ static void *vkd3d_fence_worker_main(void *arg)
|
||||
HRESULT vkd3d_fence_worker_start(struct vkd3d_fence_worker *worker,
|
||||
struct d3d12_device *device)
|
||||
{
|
||||
HRESULT hr;
|
||||
int rc;
|
||||
|
||||
TRACE("worker %p.\n", worker);
|
||||
@ -437,28 +438,14 @@ HRESULT vkd3d_fence_worker_start(struct vkd3d_fence_worker *worker,
|
||||
return hresult_from_errno(rc);
|
||||
}
|
||||
|
||||
if (device->create_thread)
|
||||
if (FAILED(hr = vkd3d_create_thread(device->vkd3d_instance,
|
||||
vkd3d_fence_worker_main, worker, &worker->thread)))
|
||||
{
|
||||
if (!(worker->u.handle = device->create_thread(vkd3d_fence_worker_main, worker)))
|
||||
{
|
||||
ERR("Failed to create fence worker thread.\n");
|
||||
pthread_mutex_destroy(&worker->mutex);
|
||||
pthread_cond_destroy(&worker->cond);
|
||||
return E_FAIL;
|
||||
}
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
if ((rc = pthread_create(&worker->u.thread, NULL, vkd3d_fence_worker_main, worker)))
|
||||
{
|
||||
ERR("Failed to create fence worker thread, error %d.\n", rc);
|
||||
pthread_mutex_destroy(&worker->mutex);
|
||||
pthread_cond_destroy(&worker->cond);
|
||||
return hresult_from_errno(rc);
|
||||
}
|
||||
|
||||
return S_OK;
|
||||
return hr;
|
||||
}
|
||||
|
||||
HRESULT vkd3d_fence_worker_stop(struct vkd3d_fence_worker *worker,
|
||||
@ -482,7 +469,7 @@ HRESULT vkd3d_fence_worker_stop(struct vkd3d_fence_worker *worker,
|
||||
|
||||
if (device->join_thread)
|
||||
{
|
||||
if (FAILED(hr = device->join_thread(worker->u.handle)))
|
||||
if (FAILED(hr = device->join_thread(worker->thread.handle)))
|
||||
{
|
||||
ERR("Failed to join fence worker thread, hr %#x.\n", hr);
|
||||
return hr;
|
||||
@ -490,7 +477,7 @@ HRESULT vkd3d_fence_worker_stop(struct vkd3d_fence_worker *worker,
|
||||
}
|
||||
else
|
||||
{
|
||||
if ((rc = pthread_join(worker->u.thread, NULL)))
|
||||
if ((rc = pthread_join(worker->thread.pthread, NULL)))
|
||||
{
|
||||
ERR("Failed to join fence worker thread, error %d.\n", rc);
|
||||
return hresult_from_errno(rc);
|
||||
|
@ -3112,7 +3112,6 @@ static HRESULT d3d12_device_init(struct d3d12_device *device,
|
||||
vkd3d_instance_incref(device->vkd3d_instance = instance);
|
||||
device->vk_info = instance->vk_info;
|
||||
device->signal_event = instance->signal_event;
|
||||
device->create_thread = instance->create_thread;
|
||||
device->join_thread = instance->join_thread;
|
||||
device->wchar_size = instance->wchar_size;
|
||||
|
||||
@ -3198,6 +3197,32 @@ void d3d12_device_mark_as_removed(struct d3d12_device *device, HRESULT reason,
|
||||
device->removed_reason = reason;
|
||||
}
|
||||
|
||||
HRESULT vkd3d_create_thread(struct vkd3d_instance *instance,
|
||||
PFN_vkd3d_thread thread_main, void *data, union vkd3d_thread_handle *thread)
|
||||
{
|
||||
HRESULT hr = S_OK;
|
||||
int rc;
|
||||
|
||||
if (instance->create_thread)
|
||||
{
|
||||
if (!(thread->handle = instance->create_thread(thread_main, data)))
|
||||
{
|
||||
ERR("Failed to create thread.\n");
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
return hr;
|
||||
}
|
||||
|
||||
IUnknown *vkd3d_get_device_parent(ID3D12Device *device)
|
||||
{
|
||||
struct d3d12_device *d3d12_device = impl_from_ID3D12Device(device);
|
||||
|
@ -141,13 +141,18 @@ struct vkd3d_instance
|
||||
LONG refcount;
|
||||
};
|
||||
|
||||
union vkd3d_thread_handle
|
||||
{
|
||||
pthread_t pthread;
|
||||
void *handle;
|
||||
};
|
||||
|
||||
HRESULT vkd3d_create_thread(struct vkd3d_instance *instance,
|
||||
PFN_vkd3d_thread thread_main, void *data, union vkd3d_thread_handle *thread) DECLSPEC_HIDDEN;
|
||||
|
||||
struct vkd3d_fence_worker
|
||||
{
|
||||
union
|
||||
{
|
||||
pthread_t thread;
|
||||
void *handle;
|
||||
} u;
|
||||
union vkd3d_thread_handle thread;
|
||||
pthread_mutex_t mutex;
|
||||
pthread_cond_t cond;
|
||||
bool should_exit;
|
||||
@ -1014,7 +1019,6 @@ struct d3d12_device
|
||||
|
||||
struct vkd3d_instance *vkd3d_instance;
|
||||
|
||||
PFN_vkd3d_create_thread create_thread;
|
||||
PFN_vkd3d_join_thread join_thread;
|
||||
|
||||
IUnknown *parent;
|
||||
|
Loading…
x
Reference in New Issue
Block a user