make certain that com.dll remains resident for its daemon threads even if the
user explicitly uloads it (from a labView DLL)
This commit is contained in:
@@ -94,6 +94,76 @@ static const int osdRealtimePriorityList [osdRealtimePriorityStateCount] =
|
||||
6 // allowed on >= W2k, but no #define supplied
|
||||
};
|
||||
|
||||
#if !defined(EPICS_DLL_NO)
|
||||
BOOL WINAPI DllMain (
|
||||
HANDLE hModule, DWORD dwReason, LPVOID lpReserved )
|
||||
{
|
||||
static DWORD dllHandleIndex;
|
||||
HMODULE dllHandle;
|
||||
BOOL success = TRUE;
|
||||
|
||||
switch ( dwReason )
|
||||
{
|
||||
case DLL_PROCESS_ATTACH:
|
||||
dllHandleIndex = TlsAlloc ();
|
||||
if ( dllHandleIndex == TLS_OUT_OF_INDEXES ) {
|
||||
success = FALSE;
|
||||
}
|
||||
break;
|
||||
|
||||
case DLL_PROCESS_DETACH:
|
||||
success = TlsFree ( dllHandleIndex );
|
||||
break;
|
||||
|
||||
case DLL_THREAD_ATTACH:
|
||||
/*
|
||||
* Dont allow user's explicitly calling FreeLibrary for Com.dll to yank
|
||||
* the carpet out from under EPICS threads that are still using Com.dll
|
||||
*/
|
||||
#if _WIN32_WINNT >= 0x0501
|
||||
/*
|
||||
* Only in WXP
|
||||
* Thats a shame becaus ethis is probably much faster
|
||||
*/
|
||||
success = GetModuleHandleEx (
|
||||
GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS,
|
||||
( LPCTSTR ) DllMain, & dllHandle );
|
||||
#else
|
||||
{
|
||||
char name[256];
|
||||
DWORD nChar = GetModuleFileName (
|
||||
hModule, name, sizeof ( name ) );
|
||||
if ( nChar && nChar < sizeof ( name ) ) {
|
||||
dllHandle = LoadLibrary ( name );
|
||||
if ( ! dllHandle ) {
|
||||
success = FALSE;
|
||||
}
|
||||
}
|
||||
else {
|
||||
success = FALSE;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
if ( success ) {
|
||||
success = TlsSetValue ( dllHandleIndex, dllHandle );
|
||||
}
|
||||
break;
|
||||
case DLL_THREAD_DETACH:
|
||||
/*
|
||||
* Thread is exiting, release Com.dll. I am assuming that windows is
|
||||
* smart enough to postpone the unload until this function returns.
|
||||
*/
|
||||
dllHandle = TlsGetValue ( dllHandleIndex );
|
||||
if ( dllHandle ) {
|
||||
success = FreeLibrary ( dllHandle );
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
return success;
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
* fetchWin32ThreadGlobal ()
|
||||
* Search for "Synchronization and Multiprocessor Issues" in ms doc
|
||||
@@ -520,6 +590,7 @@ epicsShareFunc epicsThreadId epicsShareAPI epicsThreadCreate (const char *pName,
|
||||
if ( ! pGbl ) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
pParmWIN32 = epicsThreadParmCreate ( pName );
|
||||
if ( pParmWIN32 == 0 ) {
|
||||
return ( epicsThreadId ) pParmWIN32;
|
||||
|
||||
Reference in New Issue
Block a user