Module: wine Branch: master Commit: 02c89e5c6f7cf34bdaaa8e83f755c6373bf7dfa2 URL: http://source.winehq.org/git/wine.git/?a=commit;h=02c89e5c6f7cf34bdaaa8e83f7...
Author: Rob Shearman rob@codeweavers.com Date: Thu Jan 4 18:26:31 2007 +0000
wininet: Remove the custom thread pool implementation and use QueueUserWorkItem instead.
---
dlls/wininet/internet.c | 182 +++++------------------------------------------ dlls/wininet/internet.h | 3 - 2 files changed, 18 insertions(+), 167 deletions(-)
diff --git a/dlls/wininet/internet.c b/dlls/wininet/internet.c index 6a155c5..cef4526 100644 --- a/dlls/wininet/internet.c +++ b/dlls/wininet/internet.c @@ -70,8 +70,6 @@
WINE_DEFAULT_DEBUG_CHANNEL(wininet);
-#define MAX_IDLE_WORKER 1000*60*1 -#define MAX_WORKER_THREADS 10 #define RESPONSE_TIMEOUT 30
typedef struct @@ -83,18 +81,8 @@ typedef struct static VOID INTERNET_CloseHandle(LPWININETHANDLEHEADER hdr); HINTERNET WINAPI INTERNET_InternetOpenUrlW(LPWININETAPPINFOW hIC, LPCWSTR lpszUrl, LPCWSTR lpszHeaders, DWORD dwHeadersLength, DWORD dwFlags, DWORD dwContext); -static VOID INTERNET_ExecuteWork(void);
static DWORD g_dwTlsErrIndex = TLS_OUT_OF_INDEXES; -static LONG dwNumThreads; -static LONG dwNumIdleThreads; -static LONG dwNumJobs; -static HANDLE hEventArray[2]; -#define hQuitEvent hEventArray[0] -#define hWorkEvent hEventArray[1] -static CRITICAL_SECTION csQueue; -static LPWORKREQUEST lpHeadWorkQueue; -static LPWORKREQUEST lpWorkQueueTail; static HMODULE WININET_hModule;
#define HANDLE_CHUNK_SIZE 0x10 @@ -246,16 +234,8 @@ BOOL WINAPI DllMain (HINSTANCE hinstDLL, if (g_dwTlsErrIndex == TLS_OUT_OF_INDEXES) return FALSE;
- hQuitEvent = CreateEventW(0, TRUE, FALSE, NULL); - hWorkEvent = CreateEventW(0, FALSE, FALSE, NULL); - InitializeCriticalSection(&csQueue); - URLCacheContainers_CreateDefaults();
- dwNumThreads = 0; - dwNumIdleThreads = 0; - dwNumJobs = 0; - WININET_hModule = (HMODULE)hinstDLL;
case DLL_THREAD_ATTACH: @@ -278,12 +258,6 @@ BOOL WINAPI DllMain (HINSTANCE hinstDLL, HeapFree(GetProcessHeap(), 0, TlsGetValue(g_dwTlsErrIndex)); TlsFree(g_dwTlsErrIndex); } - - SetEvent(hQuitEvent); - - CloseHandle(hQuitEvent); - CloseHandle(hWorkEvent); - DeleteCriticalSection(&csQueue); break; }
@@ -3084,107 +3058,18 @@ DWORD INTERNET_GetLastError(void) */ static DWORD CALLBACK INTERNET_WorkerThreadFunc(LPVOID lpvParam) { - DWORD dwWaitRes; - - while (1) - { - if(dwNumJobs > 0) { - INTERNET_ExecuteWork(); - continue; - } - dwWaitRes = WaitForMultipleObjects(2, hEventArray, FALSE, MAX_IDLE_WORKER); - - if (dwWaitRes == WAIT_OBJECT_0 + 1) - INTERNET_ExecuteWork(); - else - break; - - InterlockedIncrement(&dwNumIdleThreads); - } - - InterlockedDecrement(&dwNumIdleThreads); - InterlockedDecrement(&dwNumThreads); - TRACE("Worker thread exiting\n"); - return TRUE; -} - - -/*********************************************************************** - * INTERNET_InsertWorkRequest (internal) - * - * Insert work request into queue - * - * RETURNS - * - */ -static BOOL INTERNET_InsertWorkRequest(LPWORKREQUEST lpWorkRequest) -{ - BOOL bSuccess = FALSE; - LPWORKREQUEST lpNewRequest; - - TRACE("\n"); - - lpNewRequest = HeapAlloc(GetProcessHeap(), 0, sizeof(WORKREQUEST)); - if (lpNewRequest) - { - memcpy(lpNewRequest, lpWorkRequest, sizeof(WORKREQUEST)); - lpNewRequest->prev = NULL; - - EnterCriticalSection(&csQueue); - - lpNewRequest->next = lpWorkQueueTail; - if (lpWorkQueueTail) - lpWorkQueueTail->prev = lpNewRequest; - lpWorkQueueTail = lpNewRequest; - if (!lpHeadWorkQueue) - lpHeadWorkQueue = lpWorkQueueTail; - - LeaveCriticalSection(&csQueue); - - bSuccess = TRUE; - InterlockedIncrement(&dwNumJobs); - } - - return bSuccess; -} - - -/*********************************************************************** - * INTERNET_GetWorkRequest (internal) - * - * Retrieves work request from queue - * - * RETURNS - * - */ -static BOOL INTERNET_GetWorkRequest(LPWORKREQUEST lpWorkRequest) -{ - BOOL bSuccess = FALSE; - LPWORKREQUEST lpRequest = NULL; + LPWORKREQUEST lpRequest = lpvParam; + WORKREQUEST workRequest;
TRACE("\n");
- EnterCriticalSection(&csQueue); - - if (lpHeadWorkQueue) - { - lpRequest = lpHeadWorkQueue; - lpHeadWorkQueue = lpHeadWorkQueue->prev; - if (lpRequest == lpWorkQueueTail) - lpWorkQueueTail = lpHeadWorkQueue; - } - - LeaveCriticalSection(&csQueue); + memcpy(&workRequest, lpRequest, sizeof(WORKREQUEST)); + HeapFree(GetProcessHeap(), 0, lpRequest);
- if (lpRequest) - { - memcpy(lpWorkRequest, lpRequest, sizeof(WORKREQUEST)); - HeapFree(GetProcessHeap(), 0, lpRequest); - bSuccess = TRUE; - InterlockedDecrement(&dwNumJobs); - } + workRequest.asyncproc(&workRequest);
- return bSuccess; + WININET_Release( workRequest.hdr ); + return TRUE; }
@@ -3198,60 +3083,29 @@ static BOOL INTERNET_GetWorkRequest(LPWO */ BOOL INTERNET_AsyncCall(LPWORKREQUEST lpWorkRequest) { - HANDLE hThread; - DWORD dwTID; - BOOL bSuccess = FALSE; + BOOL bSuccess; + LPWORKREQUEST lpNewRequest;
TRACE("\n");
- if (InterlockedDecrement(&dwNumIdleThreads) < 0) - { - InterlockedIncrement(&dwNumIdleThreads); + lpNewRequest = HeapAlloc(GetProcessHeap(), 0, sizeof(WORKREQUEST)); + if (!lpNewRequest) + return FALSE;
- if (InterlockedIncrement(&dwNumThreads) > MAX_WORKER_THREADS || - !(hThread = CreateThread(NULL, 0, - INTERNET_WorkerThreadFunc, NULL, 0, &dwTID))) - { - InterlockedDecrement(&dwNumThreads); - INTERNET_SetLastError(ERROR_INTERNET_ASYNC_THREAD_FAILED); - goto lerror; - } + memcpy(lpNewRequest, lpWorkRequest, sizeof(WORKREQUEST));
- TRACE("Created new thread\n"); + bSuccess = QueueUserWorkItem(INTERNET_WorkerThreadFunc, lpNewRequest, WT_EXECUTELONGFUNCTION); + if (!bSuccess) + { + HeapFree(GetProcessHeap(), 0, lpNewRequest); + INTERNET_SetLastError(ERROR_INTERNET_ASYNC_THREAD_FAILED); }
- bSuccess = TRUE; - INTERNET_InsertWorkRequest(lpWorkRequest); - SetEvent(hWorkEvent); - -lerror: - return bSuccess; }
/*********************************************************************** - * INTERNET_ExecuteWork (internal) - * - * RETURNS - * - */ -static VOID INTERNET_ExecuteWork(void) -{ - WORKREQUEST workRequest; - - TRACE("\n"); - - if (!INTERNET_GetWorkRequest(&workRequest)) - return; - - workRequest.asyncproc(&workRequest); - - WININET_Release( workRequest.hdr ); -} - - -/*********************************************************************** * INTERNET_GetResponseBuffer (internal) * * RETURNS diff --git a/dlls/wininet/internet.h b/dlls/wininet/internet.h index 4015ee0..1524139 100644 --- a/dlls/wininet/internet.h +++ b/dlls/wininet/internet.h @@ -374,9 +374,6 @@ typedef struct WORKREQ struct WORKREQ_INTERNETREADFILEEXA InternetReadFileExA; } u;
- struct WORKREQ *next; - struct WORKREQ *prev; - } WORKREQUEST, *LPWORKREQUEST;
HINTERNET WININET_AllocHandle( LPWININETHANDLEHEADER info );