imm32: Lazily allocated thread-local data.

This commit is contained in:
Rob Shearman 2009-02-24 14:52:57 +00:00 committed by Alexandre Julliard
parent f970db947a
commit e926c62c43
1 changed files with 10 additions and 15 deletions

View File

@ -220,19 +220,15 @@ static DWORD convert_candidatelist_AtoW(
static IMMThreadData* IMM_GetThreadData(void) static IMMThreadData* IMM_GetThreadData(void)
{ {
return TlsGetValue(tlsIndex); IMMThreadData* data = TlsGetValue(tlsIndex);
} if (!data)
{
static BOOL IMM_InitThreadData(void) data = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
{ sizeof(IMMThreadData));
IMMThreadData* data = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, TlsSetValue(tlsIndex,data);
sizeof(IMMThreadData)); TRACE("Thread Data Created\n");
if (!data) return FALSE; }
return data;
TlsSetValue(tlsIndex,data);
TRACE("Thread Data Created\n");
return TRUE;
} }
static void IMM_FreeThreadData(void) static void IMM_FreeThreadData(void)
@ -384,11 +380,10 @@ BOOL WINAPI DllMain(HINSTANCE hInstDLL, DWORD fdwReason, LPVOID lpReserved)
case DLL_PROCESS_ATTACH: case DLL_PROCESS_ATTACH:
IMM_RegisterMessages(); IMM_RegisterMessages();
tlsIndex = TlsAlloc(); tlsIndex = TlsAlloc();
if (tlsIndex == TLS_OUT_OF_INDEXES || !IMM_InitThreadData()) if (tlsIndex == TLS_OUT_OF_INDEXES)
return FALSE; return FALSE;
break; break;
case DLL_THREAD_ATTACH: case DLL_THREAD_ATTACH:
IMM_InitThreadData();
break; break;
case DLL_THREAD_DETACH: case DLL_THREAD_DETACH:
IMM_FreeThreadData(); IMM_FreeThreadData();