3 * @copy 2012 MinGW.org project
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice (including the next
13 * paragraph) shall be included in all copies or substantial portions of the
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
25 /* FIXME - Is this still used by GCC? */
28 * Created by Mumit Khan <khan@nanotech.wisc.edu>
30 * Do the thread-support DLL initialization.
32 * This file is used iff the following conditions are met:
33 * - gcc uses -mthreads option
34 * - user code uses C++ exceptions
36 * The sole job of the Mingw thread support DLL (MingwThr) is to catch
37 * all the dying threads and clean up the data allocated in the TLSs
38 * for exception contexts during C++ EH. Posix threads have key dtors,
39 * but win32 TLS keys do not, hence the magic. Without this, there's at
40 * least `24 * sizeof (void*)' bytes leaks for each catch/throw in each
43 * See mthr.c for all the magic.
46 #define WIN32_LEAN_AND_MEAN
48 #undef WIN32_LEAN_AND_MEAN
52 *----------------------------------------------------------------------
56 * This routine is called by the Mingw32, Cygwin32 or VC++ C run
57 * time library init code, or the Borland DllEntryPoint routine. It
58 * is responsible for initializing various dynamically loaded
62 * TRUE on sucess, FALSE on failure.
66 *----------------------------------------------------------------------
69 DllMain (HINSTANCE hDllHandle /* Library instance handle. */,
70 DWORD reason /* Reason this function is being called. */,
71 LPVOID reserved /* Not used. */)
74 extern CRITICAL_SECTION __mingwthr_cs;
75 extern void __mingwthr_run_key_dtors( void );
78 printf ("%s: reason %d\n", __FUNCTION__, reason );
83 case DLL_PROCESS_ATTACH:
84 InitializeCriticalSection (&__mingwthr_cs);
87 case DLL_PROCESS_DETACH:
88 __mingwthr_run_key_dtors();
89 DeleteCriticalSection (&__mingwthr_cs);
92 case DLL_THREAD_ATTACH:
95 case DLL_THREAD_DETACH:
96 __mingwthr_run_key_dtors();