4 * Do the thread-support DLL initialization.
6 * This file is used iff the following conditions are met:
7 * - gcc uses -mthreads option
8 * - user code uses C++ exceptions
10 * The sole job of the Mingw thread support DLL (MingwThr) is to catch
11 * all the dying threads and clean up the data allocated in the TLSs
12 * for exception contexts during C++ EH. Posix threads have key dtors,
13 * but win32 TLS keys do not, hence the magic. Without this, there's at
14 * least `24 * sizeof (void*)' bytes leaks for each catch/throw in each
17 * See mthr.c for all the magic.
19 * Created by Mumit Khan <khan@nanotech.wisc.edu>
23 #define WIN32_LEAN_AND_MEAN
25 #undef WIN32_LEAN_AND_MEAN
28 BOOL APIENTRY DllMain (HANDLE hDllHandle, DWORD reason,
29 LPVOID reserved /* Not used. */ );
32 *----------------------------------------------------------------------
36 * This routine is called by the Mingw32, Cygwin32 or VC++ C run
37 * time library init code, or the Borland DllEntryPoint routine. It
38 * is responsible for initializing various dynamically loaded
42 * TRUE on sucess, FALSE on failure.
46 *----------------------------------------------------------------------
49 DllMain (HANDLE hDllHandle /* Library instance handle. */,
50 DWORD reason /* Reason this function is being called. */,
51 LPVOID reserved /* Not used. */)
54 extern CRITICAL_SECTION __mingwthr_cs;
55 extern void __mingwthr_run_key_dtors( void );
58 printf ("%s: reason %d\n", __FUNCTION__, reason );
63 case DLL_PROCESS_ATTACH:
64 InitializeCriticalSection (&__mingwthr_cs);
67 case DLL_PROCESS_DETACH:
68 __mingwthr_run_key_dtors();
69 DeleteCriticalSection (&__mingwthr_cs);
72 case DLL_THREAD_ATTACH:
75 case DLL_THREAD_DETACH:
76 __mingwthr_run_key_dtors();