From f0b6797aad1cb843a8f8192995e0d9d3ca6c3d95 Mon Sep 17 00:00:00 2001 From: Art Yerkes Date: Wed, 23 Sep 2009 00:45:19 +0000 Subject: [PATCH] Allocate a TLS slot once at process join and treat TlsIndex as an alias to it. svn path=/trunk/; revision=43120 --- reactos/dll/win32/ws2_32_new/inc/ws2_32p.h | 2 +- reactos/dll/win32/ws2_32_new/src/dllmain.c | 14 +++++++++----- reactos/dll/win32/ws2_32_new/src/dthread.c | 22 ++-------------------- 3 files changed, 12 insertions(+), 26 deletions(-) diff --git a/reactos/dll/win32/ws2_32_new/inc/ws2_32p.h b/reactos/dll/win32/ws2_32_new/inc/ws2_32p.h index a2828850e3d..39983492531 100644 --- a/reactos/dll/win32/ws2_32_new/inc/ws2_32p.h +++ b/reactos/dll/win32/ws2_32_new/inc/ws2_32p.h @@ -251,9 +251,9 @@ typedef BOOL extern HINSTANCE WsDllHandle; extern HANDLE WsSockHeap; extern PWAH_HANDLE_TABLE WsSockHandleTable; -extern DWORD TlsIndex; extern PWSPROCESS CurrentWsProcess; extern DWORD GlobalTlsIndex; +#define TlsIndex GlobalTlsIndex extern BOOLEAN WsAsyncThreadInitialized; extern PWS_SOCK_POST_ROUTINE WsSockPostRoutine; diff --git a/reactos/dll/win32/ws2_32_new/src/dllmain.c b/reactos/dll/win32/ws2_32_new/src/dllmain.c index 9c6d7ce22f2..3e20e224c67 100644 --- a/reactos/dll/win32/ws2_32_new/src/dllmain.c +++ b/reactos/dll/win32/ws2_32_new/src/dllmain.c @@ -19,7 +19,7 @@ HANDLE WsSockHeap; HINSTANCE WsDllHandle; -DWORD GlobalTlsIndex; +DWORD GlobalTlsIndex = TLS_OUT_OF_INDEXES; /* FUNCTIONS *****************************************************************/ @@ -35,7 +35,6 @@ DllMain(HANDLE hModule, switch (dwReason) { case DLL_PROCESS_ATTACH: - /* Save DLL Handle */ WsDllHandle = hModule; @@ -43,8 +42,14 @@ DllMain(HANDLE hModule, WsSockHeap = GetProcessHeap(); /* TLS Allocation */ - GlobalTlsIndex = TlsAlloc(); - if (GlobalTlsIndex == TLS_OUT_OF_INDEXES) return FALSE; + if (GlobalTlsIndex == TLS_OUT_OF_INDEXES) + { + GlobalTlsIndex = TlsAlloc(); + if (GlobalTlsIndex == TLS_OUT_OF_INDEXES) + { + return FALSE; + } + } /* Initialize some critical sections */ WsCreateStartupSynchronization(); @@ -61,7 +66,6 @@ DllMain(HANDLE hModule, break; case DLL_PROCESS_DETACH: - /* Make sure we were initialized */ if (!WsDllHandle) break; diff --git a/reactos/dll/win32/ws2_32_new/src/dthread.c b/reactos/dll/win32/ws2_32_new/src/dthread.c index 8349552abf7..dfec705c92c 100644 --- a/reactos/dll/win32/ws2_32_new/src/dthread.c +++ b/reactos/dll/win32/ws2_32_new/src/dthread.c @@ -9,10 +9,6 @@ /* INCLUDES ******************************************************************/ #include "ws2_32.h" -/* DATA **********************************************************************/ - -DWORD TlsIndex; - /* FUNCTIONS *****************************************************************/ DWORD @@ -156,16 +152,7 @@ WsThreadStartup(VOID) INT ErrorCode = WSASYSCALLFAILURE; /* Check if we have a valid TLS */ - if (TlsIndex == TLS_OUT_OF_INDEXES) - { - /* Set the global one */ - if ((TlsIndex = GlobalTlsIndex) != TLS_OUT_OF_INDEXES) - { - /* Success! */ - ErrorCode = ERROR_SUCCESS; - } - } - else + if (TlsIndex != TLS_OUT_OF_INDEXES) { /* TLS was already OK */ ErrorCode = ERROR_SUCCESS; @@ -179,12 +166,6 @@ VOID WSAAPI WsThreadCleanup(VOID) { - /* Check if we have a valid TLS */ - if (TlsIndex != TLS_OUT_OF_INDEXES) - { - /* We do, invalidate it */ - TlsIndex = TLS_OUT_OF_INDEXES; - } } DWORD @@ -250,6 +231,7 @@ WsThreadDestroyCurrentThread(VOID) { /* Delete it */ WsThreadDelete(Thread); + TlsSetValue(TlsIndex, 0); } } }