Store the winsock per-thread data in NtCurrentTeb()->WinSockData

instead of using TlsAlloc.
This commit is contained in:
Alexandre Julliard 2005-05-14 11:09:21 +00:00
parent 55d449e476
commit 7e4af0f60b
2 changed files with 18 additions and 12 deletions

View File

@ -222,7 +222,6 @@ struct per_thread_data
int pe_len;
};
static DWORD tls_index = TLS_OUT_OF_INDEXES; /* TLS index for per-thread data */
static INT num_startup; /* reference counter */
static FARPROC blocking_hook = WSA_DefaultBlockingHook;
@ -405,19 +404,19 @@ static int _get_sock_error(SOCKET s, unsigned int bit)
static struct per_thread_data *get_per_thread_data(void)
{
struct per_thread_data * ptb = TlsGetValue( tls_index );
struct per_thread_data * ptb = NtCurrentTeb()->WinSockData;
/* lazy initialization */
if (!ptb)
{
ptb = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*ptb) );
TlsSetValue( tls_index, ptb );
NtCurrentTeb()->WinSockData = ptb;
}
return ptb;
}
static void free_per_thread_data(void)
{
struct per_thread_data * ptb = TlsGetValue( tls_index );
struct per_thread_data * ptb = NtCurrentTeb()->WinSockData;
if (!ptb) return;
@ -430,6 +429,7 @@ static void free_per_thread_data(void)
ptb->pe_buffer = NULL;
HeapFree( GetProcessHeap(), 0, ptb );
NtCurrentTeb()->WinSockData = NULL;
}
/***********************************************************************
@ -440,11 +440,9 @@ BOOL WINAPI DllMain(HINSTANCE hInstDLL, DWORD fdwReason, LPVOID fImpLoad)
TRACE("%p 0x%lx %p\n", hInstDLL, fdwReason, fImpLoad);
switch (fdwReason) {
case DLL_PROCESS_ATTACH:
tls_index = TlsAlloc();
break;
case DLL_PROCESS_DETACH:
free_per_thread_data();
TlsFree( tls_index );
num_startup = 0;
break;
case DLL_THREAD_DETACH:

View File

@ -110,12 +110,20 @@ typedef struct _TEB
PVOID DeallocationStack; /* -2- e0c Base of the stack */
LPVOID TlsSlots[64]; /* -2- e10 Thread local storage */
LIST_ENTRY TlsLinks; /* -2- f10 */
DWORD pad8[1]; /* --n f18 */
PVOID ReservedForNtRpc; /* -2- f1c used by rpcrt4 */
DWORD pad9[24]; /* --n f20 */
PVOID ReservedForOle; /* -2- f80 used by ole32 (IErrorInfo*) */
PVOID pad10[4]; /* --n f84 */
PVOID *TlsExpansionSlots; /* -2- f94 */
PVOID Vdm; /* f18 */
PVOID ReservedForNtRpc; /* f1c */
PVOID DbgSsReserved[2]; /* f20 */
ULONG HardErrorDisabled; /* f28 */
PVOID Instrumentation[16]; /* f2c */
PVOID WinSockData; /* f6c */
ULONG GdiBatchCount; /* f70 */
ULONG Spare2; /* f74 */
ULONG Spare3; /* f78 */
ULONG Spare4; /* f7c */
PVOID ReservedForOle; /* f80 */
ULONG WaitingOnLoaderLock; /* f84 */
PVOID Reserved5[3]; /* f88 */
PVOID *TlsExpansionSlots; /* f94 */
} TEB;
#endif /* WINE_TEB_DEFINED */