mySQL 5.0.11 sources for tomato
[tomato.git] / release / src / router / mysql / libmysql / dll.c
blobcfec985f0562d24e69cc6f5aead062622bc4afe6
1 /* Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License as published by
5 the Free Software Foundation.
7 There are special exceptions to the terms and conditions of the GPL as it
8 is applied to this software.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
20 ** Handling initialization of the dll library
23 #include <my_global.h>
24 #include <my_sys.h>
25 #include <my_pthread.h>
27 static my_bool libmysql_inited=0;
29 void libmysql_init(void)
31 if (libmysql_inited)
32 return;
33 libmysql_inited=1;
34 my_init();
36 DBUG_ENTER("libmysql_init");
37 #ifdef LOG_ALL
38 DBUG_PUSH("d:t:S:O,c::\\tmp\\libmysql.log");
39 #else
40 if (getenv("LIBMYSQL_LOG") != NULL)
41 DBUG_PUSH(getenv("LIBMYSQL_LOG"));
42 #endif
43 DBUG_VOID_RETURN;
47 #ifdef __WIN__
49 static int inited=0,threads=0;
50 HINSTANCE NEAR s_hModule; /* Saved module handle */
51 DWORD main_thread;
53 BOOL APIENTRY LibMain(HANDLE hInst,DWORD ul_reason_being_called,
54 LPVOID lpReserved)
56 switch (ul_reason_being_called) {
57 case DLL_PROCESS_ATTACH: /* case of libentry call in win 3.x */
58 if (!inited++)
60 s_hModule=hInst;
61 libmysql_init();
62 main_thread=GetCurrentThreadId();
64 break;
65 case DLL_THREAD_ATTACH:
66 threads++;
67 my_thread_init();
68 break;
69 case DLL_PROCESS_DETACH: /* case of wep call in win 3.x */
70 if (!--inited) /* Safety */
72 /* my_thread_init() */ /* This may give extra safety */
73 my_end(0);
75 break;
76 case DLL_THREAD_DETACH:
77 /* Main thread will free by my_end() */
78 threads--;
79 if (main_thread != GetCurrentThreadId())
80 my_thread_end();
81 break;
82 default:
83 break;
84 } /* switch */
86 return TRUE;
88 UNREFERENCED_PARAMETER(lpReserved);
89 } /* LibMain */
92 static BOOL do_libmain;
93 int __stdcall DllMain(HANDLE hInst,DWORD ul_reason_being_called,LPVOID lpReserved)
96 Unless environment variable LIBMYSQL_DLLINIT is set, do nothing.
97 The environment variable is checked once, during the first call to DllMain()
98 (in DLL_PROCESS_ATTACH hook).
100 if (ul_reason_being_called == DLL_PROCESS_ATTACH)
101 do_libmain = (getenv("LIBMYSQL_DLLINIT") != NULL);
102 if (do_libmain)
103 return LibMain(hInst,ul_reason_being_called,lpReserved);
104 return TRUE;
107 #elif defined(WINDOWS)
109 /****************************************************************************
110 ** This routine is called by LIBSTART.ASM at module load time. All it
111 ** does in this sample is remember the DLL module handle. The module
112 ** handle is needed if you want to do things like load stuff from the
113 ** resource file (for instance string resources).
114 ****************************************************************************/
116 int _export FAR PASCAL libmain(HANDLE hModule,short cbHeapSize,
117 UCHAR FAR *lszCmdLine)
119 s_hModule = hModule;
120 libmysql_init();
121 return TRUE;
124 #endif