/* global vars */
-/* Do not assume it have the free value -1 set, any value can be in here */
-DWORD OPENGL32_tls = -1U;
+/* Do not assume it have the free value MAXDWORD set, any value can be in here */
+DWORD OPENGL32_tls = MAXDWORD;
GLPROCESSDATA OPENGL32_processdata;
static BOOL
-OPENGL32_ThreadAttach()
+OPENGL32_ThreadAttach( void )
{
GLTHREADDATA* lpData = NULL;
PROC *dispatchTable = NULL;
static void
-OPENGL32_ThreadDetach()
+OPENGL32_ThreadDetach( void )
{
GLTHREADDATA* lpData = NULL;
- PROC *dispatchTable = NULL;
+ TEB* teb = NtCurrentTeb();
rosglMakeCurrent( NULL, NULL );
lpData = NULL;
}
- dispatchTable = NtCurrentTeb()->glTable;
- if (dispatchTable != NULL)
+ if (teb->glTable != NULL)
{
- if (!HeapFree( GetProcessHeap(), 0, dispatchTable ))
+ if (!HeapFree( GetProcessHeap(), 0, teb->glTable ))
+ {
DBGPRINT( "Warning: HeapFree() on dispatch table failed (%d)",
GetLastError() );
+ }
+ /* NULL-ify it. Even if something went wrong, it's not a good idea to keep it non NULL */
+ teb->glTable = NULL;
}
}
static BOOL
-OPENGL32_ProcessAttach()
+OPENGL32_ProcessAttach( void )
{
SECURITY_ATTRIBUTES attrib = { sizeof (SECURITY_ATTRIBUTES), /* nLength */
NULL, /* lpSecurityDescriptor */
TRUE /* bInheritHandle */ };
OPENGL32_tls = TlsAlloc();
- if (-1U == OPENGL32_tls)
+ if (OPENGL32_tls == MAXDWORD)
return FALSE;
memset( &OPENGL32_processdata, 0, sizeof (OPENGL32_processdata) );
static void
-OPENGL32_ProcessDetach()
+OPENGL32_ProcessDetach( void )
{
GLDRIVERDATA *icd, *icd2;
GLDCDATA *dcdata, *dcdata2;
CloseHandle( OPENGL32_processdata.dcdata_mutex );
/* free TLS */
- if (OPENGL32_tls != -1U)
+ if (OPENGL32_tls != MAXDWORD)
TlsFree(OPENGL32_tls);
}
{
if (!_wcsicmp( driver, icd->driver_name )) /* found */
{
- icd->refcount++;
-
/* release mutex */
if (!ReleaseMutex( OPENGL32_processdata.driver_mutex ))
DBGPRINT( "Error: ReleaseMutex() failed (%d)", GetLastError() );
/* not found - try to load */
icd = OPENGL32_LoadDriver( driver );
- if (icd != NULL)
- icd->refcount = 1;
/* release mutex */
if (!ReleaseMutex( OPENGL32_processdata.driver_mutex ))
return FALSE; /* FIXME: do we have to expect such an error and handle it? */
}
- if (--icd->refcount == 0)
+ if (icd->refcount == 0)
ret = OPENGL32_UnloadDriver( icd );
/* release mutex */