=?UTF-8?Q?J=C3=B3zef=20Kucia=20?=: vkd3d: Factor out vkd3d_create_thread() .

Alexandre Julliard julliard at winehq.org
Tue Jun 11 16:49:25 CDT 2019


Module: vkd3d
Branch: master
Commit: bc5e8a9cc2fd19aab45a7127b9f23114e65dbc4e
URL:    https://source.winehq.org/git/vkd3d.git/?a=commit;h=bc5e8a9cc2fd19aab45a7127b9f23114e65dbc4e

Author: Józef Kucia <jkucia at codeweavers.com>
Date:   Tue Jun 11 10:13:37 2019 +0200

vkd3d: Factor out vkd3d_create_thread().

Signed-off-by: Józef Kucia <jkucia at codeweavers.com>
Signed-off-by: Henri Verbeet <hverbeet at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 libs/vkd3d/command.c       | 25 ++++++-------------------
 libs/vkd3d/device.c        | 27 ++++++++++++++++++++++++++-
 libs/vkd3d/vkd3d_private.h | 16 ++++++++++------
 3 files changed, 42 insertions(+), 26 deletions(-)

diff --git a/libs/vkd3d/command.c b/libs/vkd3d/command.c
index 97cc7de..0c2fd3e 100644
--- a/libs/vkd3d/command.c
+++ b/libs/vkd3d/command.c
@@ -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 (!(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)))
+    if (FAILED(hr = vkd3d_create_thread(device->vkd3d_instance,
+            vkd3d_fence_worker_main, worker, &worker->thread)))
     {
-        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);
diff --git a/libs/vkd3d/device.c b/libs/vkd3d/device.c
index 4df2462..e88d3c2 100644
--- a/libs/vkd3d/device.c
+++ b/libs/vkd3d/device.c
@@ -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);
diff --git a/libs/vkd3d/vkd3d_private.h b/libs/vkd3d/vkd3d_private.h
index 9191ae2..2fbf692 100644
--- a/libs/vkd3d/vkd3d_private.h
+++ b/libs/vkd3d/vkd3d_private.h
@@ -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;




More information about the wine-cvs mailing list