[PATCH 4/6] winhttp: Use the thread pool for the connection collector.
Signed-off-by: Hans Leidekker <hans(a)codeweavers.com> --- dlls/winhttp/request.c | 24 ++++++------------------ 1 file changed, 6 insertions(+), 18 deletions(-) diff --git a/dlls/winhttp/request.c b/dlls/winhttp/request.c index 61af6ea977..0f9580734d 100644 --- a/dlls/winhttp/request.c +++ b/dlls/winhttp/request.c @@ -1457,7 +1457,7 @@ void release_host( struct hostdata *host ) static BOOL connection_collector_running; -static DWORD WINAPI connection_collector(void *arg) +static void CALLBACK connection_collector( TP_CALLBACK_INSTANCE *instance, void *ctx ) { unsigned int remaining_connections; struct netconn *netconn, *next_netconn; @@ -1483,10 +1483,7 @@ static DWORD WINAPI connection_collector(void *arg) list_remove(&netconn->entry); netconn_close(netconn); } - else - { - remaining_connections++; - } + else remaining_connections++; } } @@ -1495,7 +1492,7 @@ static DWORD WINAPI connection_collector(void *arg) LeaveCriticalSection(&connection_pool_cs); } while(remaining_connections); - FreeLibraryAndExitThread( winhttp_instance, 0 ); + FreeLibrary( winhttp_instance ); } static void cache_connection( struct netconn *netconn ) @@ -1510,20 +1507,11 @@ static void cache_connection( struct netconn *netconn ) if (!connection_collector_running) { HMODULE module; - HANDLE thread; - GetModuleHandleExW( GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS, (const WCHAR*)winhttp_instance, &module ); + GetModuleHandleExW( GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS, (const WCHAR *)winhttp_instance, &module ); - thread = CreateThread(NULL, 0, connection_collector, NULL, 0, NULL); - if (thread) - { - CloseHandle( thread ); - connection_collector_running = TRUE; - } - else - { - FreeLibrary( winhttp_instance ); - } + if (TrySubmitThreadpoolCallback( connection_collector, NULL, NULL )) connection_collector_running = TRUE; + else FreeLibrary( winhttp_instance ); } LeaveCriticalSection( &connection_pool_cs ); -- 2.11.0
Hi Hans, On 11/23/18 11:35 AM, Hans Leidekker wrote:
@@ -1495,7 +1492,7 @@ static DWORD WINAPI connection_collector(void *arg) LeaveCriticalSection(&connection_pool_cs); } while(remaining_connections);
- FreeLibraryAndExitThread( winhttp_instance, 0 ); + FreeLibrary( winhttp_instance );
If winhttp_instance is the last instance of winhttp.dll, FreeLibrary will return back to code that is has just unloaded. Jacek
November 23, 2018 7:07 AM, "Jacek Caban" <jacek(a)codeweavers.com> wrote:
Hi Hans,
On 11/23/18 11:35 AM, Hans Leidekker wrote:
@@ -1495,7 +1492,7 @@ static DWORD WINAPI connection_collector(void *arg) LeaveCriticalSection(&connection_pool_cs); } while(remaining_connections);
- FreeLibraryAndExitThread( winhttp_instance, 0 ); + FreeLibrary( winhttp_instance );
If winhttp_instance is the last instance of winhttp.dll, FreeLibrary will return back to code that is has just unloaded.
You want to use FreeLibraryWhenCallbackReturns() here.
Jacek
Chip
participants (3)
-
Chip Davis -
Hans Leidekker -
Jacek Caban