Skip to content
Permalink
Browse files
winhttp: HACK: Reuse threadpool for Monster Hunter Rise.
CW-Bug-Id: #19484
  • Loading branch information
Paul Gofman authored and gofman committed Jan 7, 2022
1 parent 94285ec commit 40f9cbafbf1d7d5cfecf6d765e440ff03ce2376d
Showing with 67 additions and 4 deletions.
  1. +6 −0 dlls/winhttp/main.c
  2. +60 −4 dlls/winhttp/request.c
  3. +1 −0 dlls/winhttp/winhttp_private.h
@@ -42,9 +42,15 @@ BOOL WINAPI DllMain(HINSTANCE hInstDLL, DWORD fdwReason, LPVOID lpv)
switch(fdwReason)
{
case DLL_PROCESS_ATTACH:
{
char str[64];

winhttp_instance = hInstDLL;
DisableThreadLibraryCalls(hInstDLL);
if ((reuse_threadpool = GetEnvironmentVariableA( "SteamGameId", str, sizeof(str)) && !strcmp(str, "1446780" )))
ERR( "HACK: setting reuse_threadpool.\n" );
break;
}
case DLL_PROCESS_DETACH:
if (lpv) break;
netconn_unload();
@@ -43,6 +43,24 @@ WINE_DEFAULT_DEBUG_CHANNEL(winhttp);

#define DEFAULT_KEEP_ALIVE_TIMEOUT 30000

BOOL reuse_threadpool;

static struct
{
TP_POOL *pool;
LONG ref;
}
thread_pool_cache;

static CRITICAL_SECTION thread_pool_cache_cs;
static CRITICAL_SECTION_DEBUG thread_pool_cache_debug =
{
0, 0, &thread_pool_cache_cs,
{ &thread_pool_cache_debug.ProcessLocksList, &thread_pool_cache_debug.ProcessLocksList },
0, 0, { (DWORD_PTR)(__FILE__ ": thread_pool_cache_cs") }
};
static CRITICAL_SECTION thread_pool_cache_cs = { &thread_pool_cache_debug, -1, 0, 0, 0, 0 };

static const WCHAR *attribute_table[] =
{
L"Mime-Version", /* WINHTTP_QUERY_MIME_VERSION = 0 */
@@ -122,13 +140,37 @@ static const WCHAR *attribute_table[] =
NULL /* WINHTTP_QUERY_PASSPORT_CONFIG = 78 */
};

static TP_POOL *create_thread_pool(void)
{
TP_POOL *pool;

if (!(pool = CreateThreadpool( NULL ))) return NULL;
SetThreadpoolThreadMinimum( pool, 1 );
SetThreadpoolThreadMaximum( pool, 1 );

return pool;
}

static DWORD start_queue( struct queue *queue )
{
if (queue->pool) return ERROR_SUCCESS;

if (!(queue->pool = CreateThreadpool( NULL ))) return GetLastError();
SetThreadpoolThreadMinimum( queue->pool, 1 );
SetThreadpoolThreadMaximum( queue->pool, 1 );
if (reuse_threadpool)
{
EnterCriticalSection( &thread_pool_cache_cs );
if (!thread_pool_cache.pool)
{
assert( !thread_pool_cache.ref );
thread_pool_cache.pool = create_thread_pool();
}
++thread_pool_cache.ref;
queue->pool = thread_pool_cache.pool;
LeaveCriticalSection( &thread_pool_cache_cs );
}
else
{
if (!(queue->pool = create_thread_pool())) return GetLastError();
}

memset( &queue->env, 0, sizeof(queue->env) );
queue->env.Version = 1;
@@ -141,7 +183,21 @@ static DWORD start_queue( struct queue *queue )
void stop_queue( struct queue *queue )
{
if (!queue->pool) return;
CloseThreadpool( queue->pool );
if (reuse_threadpool)
{
EnterCriticalSection( &thread_pool_cache_cs );
assert(thread_pool_cache.ref);
if (!--thread_pool_cache.ref)
{
CloseThreadpool( thread_pool_cache.pool );
thread_pool_cache.pool = NULL;
}
LeaveCriticalSection( &thread_pool_cache_cs );
}
else
{
CloseThreadpool( queue->pool );
}
queue->pool = NULL;
TRACE("stopped %p\n", queue);
}
@@ -403,5 +403,6 @@ static inline char *strdupWA_sized( const WCHAR *src, DWORD size )
}

extern HINSTANCE winhttp_instance DECLSPEC_HIDDEN;
extern BOOL reuse_threadpool DECLSPEC_HIDDEN;

#endif /* _WINE_WINHTTP_PRIVATE_H_ */

0 comments on commit 40f9cba

Please sign in to comment.