Hans Leidekker : winhttp: Use the thread pool for asynchronous tasks.

Alexandre Julliard julliard at winehq.org
Fri Nov 23 14:18:02 CST 2018


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

Author: Hans Leidekker <hans at codeweavers.com>
Date:   Fri Nov 23 11:35:26 2018 +0100

winhttp: Use the thread pool for asynchronous tasks.

Signed-off-by: Hans Leidekker <hans at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 dlls/winhttp/request.c         | 12 ++++++------
 dlls/winhttp/session.c         |  9 +++------
 dlls/winhttp/winhttp_private.h |  2 +-
 3 files changed, 10 insertions(+), 13 deletions(-)

diff --git a/dlls/winhttp/request.c b/dlls/winhttp/request.c
index 27628c3..9817287 100644
--- a/dlls/winhttp/request.c
+++ b/dlls/winhttp/request.c
@@ -191,9 +191,9 @@ static struct task_header *dequeue_task( struct request *request )
     return task;
 }
 
-static DWORD CALLBACK task_proc( LPVOID param )
+static void CALLBACK task_proc( TP_CALLBACK_INSTANCE *instance, void *ctx )
 {
-    struct request *request = param;
+    struct request *request = ctx;
     HANDLE handles[2];
 
     handles[0] = request->task_wait;
@@ -221,21 +221,20 @@ static DWORD CALLBACK task_proc( LPVOID param )
             request->task_cs.DebugInfo->Spare[0] = 0;
             DeleteCriticalSection( &request->task_cs );
             request->hdr.vtbl->destroy( &request->hdr );
-            return 0;
+            return;
 
         default:
             ERR("wait failed %u (%u)\n", err, GetLastError());
             break;
         }
     }
-    return 0;
 }
 
 static BOOL queue_task( struct task_header *task )
 {
     struct request *request = task->request;
 
-    if (!request->task_thread)
+    if (!request->task_wait)
     {
         if (!(request->task_wait = CreateEventW( NULL, FALSE, FALSE, NULL ))) return FALSE;
         if (!(request->task_cancel = CreateEventW( NULL, FALSE, FALSE, NULL )))
@@ -244,7 +243,7 @@ static BOOL queue_task( struct task_header *task )
             request->task_wait = NULL;
             return FALSE;
         }
-        if (!(request->task_thread = CreateThread( NULL, 0, task_proc, request, 0, NULL )))
+        if (!TrySubmitThreadpoolCallback( task_proc, request, NULL ))
         {
             CloseHandle( request->task_wait );
             request->task_wait = NULL;
@@ -252,6 +251,7 @@ static BOOL queue_task( struct task_header *task )
             request->task_cancel = NULL;
             return FALSE;
         }
+        request->task_proc_running = TRUE;
         InitializeCriticalSection( &request->task_cs );
         request->task_cs.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": request.task_cs");
     }
diff --git a/dlls/winhttp/session.c b/dlls/winhttp/session.c
index 2051d42..f8d98d0 100644
--- a/dlls/winhttp/session.c
+++ b/dlls/winhttp/session.c
@@ -601,14 +601,11 @@ static void request_destroy( struct object_header *hdr )
 
     TRACE("%p\n", request);
 
-    if (request->task_thread)
+    if (request->task_proc_running)
     {
-        /* Signal to the task proc to quit.  It will call
-           this again when it does. */
-        HANDLE thread = request->task_thread;
-        request->task_thread = 0;
+        /* Signal to the task proc to quit. It will call this again when it does. */
+        request->task_proc_running = FALSE;
         SetEvent( request->task_cancel );
-        CloseHandle( thread );
         return;
     }
     release_object( &request->connect->hdr );
diff --git a/dlls/winhttp/winhttp_private.h b/dlls/winhttp/winhttp_private.h
index 2ee868c..14cee44 100644
--- a/dlls/winhttp/winhttp_private.h
+++ b/dlls/winhttp/winhttp_private.h
@@ -204,7 +204,7 @@ struct request
     struct authinfo *proxy_authinfo;
     HANDLE task_wait;
     HANDLE task_cancel;
-    HANDLE task_thread;
+    BOOL   task_proc_running;
     struct list task_queue;
     CRITICAL_SECTION task_cs;
     struct




More information about the wine-cvs mailing list