summary refs log tree commit diff stats
path: root/qemu-thread-win32.c
diff options
context:
space:
mode:
Diffstat (limited to 'qemu-thread-win32.c')
-rw-r--r--qemu-thread-win32.c29
1 files changed, 23 insertions, 6 deletions
diff --git a/qemu-thread-win32.c b/qemu-thread-win32.c
index a13ffcca69..fe9b931863 100644
--- a/qemu-thread-win32.c
+++ b/qemu-thread-win32.c
@@ -252,14 +252,10 @@ void *qemu_thread_join(QemuThread *thread)
      * discard the handle that _beginthreadex gives back, and
      * get another copy of the handle here.
      */
-    EnterCriticalSection(&data->cs);
-    if (!data->exited) {
-        handle = OpenThread(SYNCHRONIZE, FALSE, thread->tid);
-        LeaveCriticalSection(&data->cs);
+    handle = qemu_thread_get_handle(thread);
+    if (handle) {
         WaitForSingleObject(handle, INFINITE);
         CloseHandle(handle);
-    } else {
-        LeaveCriticalSection(&data->cs);
     }
     ret = data->ret;
     DeleteCriticalSection(&data->cs);
@@ -308,6 +304,27 @@ void qemu_thread_get_self(QemuThread *thread)
     thread->tid = GetCurrentThreadId();
 }
 
+HANDLE qemu_thread_get_handle(QemuThread *thread)
+{
+    QemuThreadData *data;
+    HANDLE handle;
+
+    data = thread->data;
+    if (!data) {
+        return NULL;
+    }
+
+    EnterCriticalSection(&data->cs);
+    if (!data->exited) {
+        handle = OpenThread(SYNCHRONIZE | THREAD_SUSPEND_RESUME, FALSE,
+                            thread->tid);
+    } else {
+        handle = NULL;
+    }
+    LeaveCriticalSection(&data->cs);
+    return handle;
+}
+
 int qemu_thread_is_self(QemuThread *thread)
 {
     return GetCurrentThreadId() == thread->tid;