/* glplib02.c (TLS communication) */ /* (reserved for copyright notice) */ #include #include "glplib.h" /* multi-threaded 32-bit Windows DLL */ static DWORD dwTlsIndex; BOOL APIENTRY DllMain ( HINSTANCE hinstDLL, /* DLL module handle */ DWORD fdwReason, /* reason called */ LPVOID lpvReserved /* reserved */ ) { switch (fdwReason) { /* the DLL is loading due to process initialization or a call to LoadLibrary */ case DLL_PROCESS_ATTACH: /* allocate a TLS index */ dwTlsIndex = TlsAlloc(); if (dwTlsIndex == 0xFFFFFFFF) return FALSE; /* initialize the index for first thread */ TlsSetValue(dwTlsIndex, NULL); /* initialize GLPK library environment */ lib_init_env(); break; /* the attached process creates a new thread */ case DLL_THREAD_ATTACH: /* initialize the TLS index for this thread */ TlsSetValue(dwTlsIndex, NULL); /* initialize GLPK library environment */ lib_init_env(); break; /* the thread of the attached process terminates */ case DLL_THREAD_DETACH: /* free GLPK library environment */ lib_free_env(); break; /* the DLL is unloading due to process termination or call to FreeLibrary */ case DLL_PROCESS_DETACH: /* free GLPK library environment */ lib_free_env(); /* release the TLS index */ TlsFree(dwTlsIndex); break; default: break; } return TRUE; } void lib_set_ptr(void *ptr) { TlsSetValue(dwTlsIndex, ptr); return; } void *lib_get_ptr(void) { void *ptr; ptr = TlsGetValue(dwTlsIndex); return ptr; } /* eof */