Index: ChangeLog =================================================================== --- ChangeLog (revision 960) +++ ChangeLog (working copy) @@ -5,6 +5,8 @@ Bugs fixed: * Allowed connections to be enlisted in distributed transactions, even though the driver doesn't support them. (Bug #32727) + * Disabled possible delay in environment handle cleanup in multithreaded + environments. (Bug #32366) ---- Index: driver/dll.c =================================================================== --- driver/dll.c (revision 960) +++ driver/dll.c (working copy) @@ -88,76 +88,74 @@ void myodbc_end() { - if (!--myodbc_inited) - { - my_free(decimal_point,MYF(0)); - my_free(default_locale,MYF(0)); - my_free(thousands_sep,MYF(0)); -#ifdef NOT_YET_USED - mysql_server_end(); -#endif + if (!--myodbc_inited) + { + my_free(decimal_point,MYF(0)); + my_free(default_locale,MYF(0)); + my_free(thousands_sep,MYF(0)); + + /* + This eliminates the delay when my_end() is called and other threads + have been initialized but not ended. + */ + my_thread_end_wait_time= 0; + #ifdef MY_DONT_FREE_DBUG - /* - Function my_end() was changed to deallocate DBUG memory by default, - a flag MY_DONT_FREE_DBUG was added to disable this new behaviour - */ - my_end(MY_DONT_FREE_DBUG); + /* + Function my_end() was changed to deallocate DBUG memory by default, + a flag MY_DONT_FREE_DBUG was added to disable this new behaviour + */ + my_end(MY_DONT_FREE_DBUG); #else - my_end(0); + my_end(0); #endif - } + } } + /* @type : myodbc3 internal @purpose : main entry point */ #ifdef _WIN32 -static int inited=0,threads=0; -static DWORD main_thread; -HINSTANCE NEAR s_hModule; /* Saved module handle */ -int APIENTRY LibMain(HANDLE hInst,DWORD ul_reason_being_called, +static int inited= 0; +int APIENTRY LibMain(HANDLE hInst, DWORD ul_reason_being_called, LPVOID lpReserved) { switch (ul_reason_being_called) { case DLL_PROCESS_ATTACH: /* case of libentry call in win 3.x */ - if (!inited++) - { - s_hModule=hInst; - myodbc_init(); - main_thread=GetCurrentThreadId(); - } - break; - case DLL_THREAD_ATTACH: - threads++; -#ifdef THREAD - my_thread_init(); -#endif + if (!inited++) + myodbc_init(); break; case DLL_PROCESS_DETACH: /* case of wep call in win 3.x */ if (!--inited) myodbc_end(); break; + + /* + We don't explicitly call my_thread_init() to avoid initialization in + threads that may not even make ODBC calls. my_thread_init() will be + called implicitly when mysys calls are made from the thread. + */ + case DLL_THREAD_ATTACH: + break; case DLL_THREAD_DETACH: #ifdef THREAD - /* Main thread will free by my_end() */ - threads--; - if (main_thread != GetCurrentThreadId()) - my_thread_end(); -#else - --threads; + my_thread_end(); #endif break; + default: break; - } /* switch */ + } return TRUE; UNREFERENCED_PARAMETER(lpReserved); -} /* LibMain */ +} + /* @type : myodbc3 internal @purpose : entry point for the DLL @@ -181,7 +179,6 @@ int _export FAR PASCAL libmain(HANDLE hModule,short cbHeapSize, SQLCHAR FAR *lszCmdLine) { - s_hModule = hModule; myodbc_init(); return TRUE; }