reactos/dll/opengl/opengl32/dllmain.c
Jérôme Gardou 6aaf217b10 [OPENGL32]
- Implement storing thread data into the TEB
CORE-14024
2017-11-21 08:22:31 +01:00

88 lines
2.4 KiB
C

/*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS
* FILE: dll/opengl/opengl32/dllmain.c
* PURPOSE: OpenGL32 DLL
*/
#include "opengl32.h"
#ifdef OPENGL32_USE_TLS
DWORD OglTlsIndex = 0xFFFFFFFF;
BOOL init_tls_data(void)
{
struct Opengl32_ThreadData* ThreadData;
ThreadData = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*ThreadData));
if(!ThreadData)
return FALSE;
TlsSetValue(OglTlsIndex, ThreadData);
ThreadData->glDispatchTable = &StubTable.glDispatchTable;
ThreadData->hglrc = NULL;
ThreadData->hdc = NULL;
ThreadData->dc_data = NULL;
return TRUE;
}
#endif
BOOL WINAPI
DllMain(HINSTANCE hInstance, DWORD Reason, LPVOID Reserved)
{
#ifdef OPENGL32_USE_TLS
struct Opengl32_ThreadData* ThreadData;
#endif
switch ( Reason )
{
case DLL_PROCESS_ATTACH:
#ifdef OPENGL32_USE_TLS
OglTlsIndex = TlsAlloc();
if(OglTlsIndex == TLS_OUT_OF_INDEXES)
return FALSE;
#endif
/* Initialize Context list */
InitializeListHead(&ContextListHead);
/* no break */
case DLL_THREAD_ATTACH:
#ifdef OPENGL32_USE_TLS
if (!init_tls_data())
return FALSE;
#endif // defined(OPENGL32_USE_TLS)
IntSetCurrentDispatchTable(&StubTable.glDispatchTable);
break;
case DLL_THREAD_DETACH:
/* Set NULL context for this thread */
wglMakeCurrent(NULL, NULL);
/* Clean up */
#ifdef OPENGL32_USE_TLS
ThreadData = TlsGetValue(OglTlsIndex);
if(ThreadData)
HeapFree(GetProcessHeap(), 0, ThreadData);
#else
NtCurrentTeb()->glTable = NULL;
#endif // defined(OPENGL32_USE_TLS)
break;
case DLL_PROCESS_DETACH:
/* Clean up */
if (!Reserved)
{
/* The process is not shutting down: release everything */
wglMakeCurrent(NULL, NULL);
IntDeleteAllContexts();
IntDeleteAllICDs();
#ifdef OPENGL32_USE_TLS
ThreadData = TlsGetValue(OglTlsIndex);
if(ThreadData)
HeapFree(GetProcessHeap(), 0, ThreadData);
#endif
}
#ifdef OPENGL32_USE_TLS
TlsFree(OglTlsIndex);
#endif
break;
}
return TRUE;
}