1
by brian
clean slate |
1 |
/* Copyright (C) 2000-2004 MySQL AB
|
2 |
||
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.
|
|
6 |
||
7 |
There are special exceptions to the terms and conditions of the GPL as it
|
|
8 |
is applied to this software. View the full text of the exception in file
|
|
9 |
EXCEPTIONS-CLIENT in the directory of this software distribution.
|
|
10 |
||
11 |
This program is distributed in the hope that it will be useful,
|
|
12 |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
13 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
14 |
GNU General Public License for more details.
|
|
15 |
||
16 |
You should have received a copy of the GNU General Public License
|
|
17 |
along with this program; if not, write to the Free Software
|
|
18 |
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
|
|
19 |
||
20 |
/*
|
|
21 |
** Handling initialization of the dll library
|
|
22 |
*/
|
|
23 |
||
24 |
#include <my_global.h> |
|
25 |
#include <my_sys.h> |
|
26 |
#include <my_pthread.h> |
|
27 |
||
28 |
static my_bool libmysql_inited=0; |
|
29 |
||
30 |
void libmysql_init(void) |
|
31 |
{
|
|
32 |
if (libmysql_inited) |
|
33 |
return; |
|
34 |
libmysql_inited=1; |
|
35 |
my_init(); |
|
36 |
{
|
|
37 |
DBUG_ENTER("libmysql_init"); |
|
38 |
#ifdef LOG_ALL
|
|
39 |
DBUG_PUSH("d:t:S:O,c::\\tmp\\libmysql.log"); |
|
40 |
#else
|
|
41 |
if (getenv("LIBMYSQL_LOG") != NULL) |
|
42 |
DBUG_PUSH(getenv("LIBMYSQL_LOG")); |
|
43 |
#endif
|
|
44 |
DBUG_VOID_RETURN; |
|
45 |
}
|
|
46 |
}
|
|
47 |
||
48 |
#ifdef __WIN__
|
|
49 |
||
50 |
static int inited=0,threads=0; |
|
51 |
HINSTANCE NEAR s_hModule; /* Saved module handle */ |
|
52 |
DWORD main_thread; |
|
53 |
||
54 |
BOOL APIENTRY LibMain(HANDLE hInst,DWORD ul_reason_being_called, |
|
55 |
LPVOID lpReserved) |
|
56 |
{
|
|
57 |
switch (ul_reason_being_called) { |
|
58 |
case DLL_PROCESS_ATTACH: /* case of libentry call in win 3.x */ |
|
59 |
if (!inited++) |
|
60 |
{
|
|
61 |
s_hModule=hInst; |
|
62 |
libmysql_init(); |
|
63 |
main_thread=GetCurrentThreadId(); |
|
64 |
}
|
|
65 |
break; |
|
66 |
case DLL_THREAD_ATTACH: |
|
67 |
threads++; |
|
68 |
my_thread_init(); |
|
69 |
break; |
|
70 |
case DLL_PROCESS_DETACH: /* case of wep call in win 3.x */ |
|
71 |
if (!--inited) /* Safety */ |
|
72 |
{
|
|
73 |
/* my_thread_init() */ /* This may give extra safety */ |
|
74 |
my_end(0); |
|
75 |
}
|
|
76 |
break; |
|
77 |
case DLL_THREAD_DETACH: |
|
78 |
/* Main thread will free by my_end() */
|
|
79 |
threads--; |
|
80 |
if (main_thread != GetCurrentThreadId()) |
|
81 |
my_thread_end(); |
|
82 |
break; |
|
83 |
default: |
|
84 |
break; |
|
85 |
} /* switch */ |
|
86 |
||
87 |
return TRUE; |
|
88 |
||
89 |
UNREFERENCED_PARAMETER(lpReserved); |
|
90 |
} /* LibMain */ |
|
91 |
||
92 |
int __stdcall DllMain(HANDLE hInst,DWORD ul_reason_being_called,LPVOID lpReserved) |
|
93 |
{
|
|
94 |
return LibMain(hInst,ul_reason_being_called,lpReserved); |
|
95 |
}
|
|
96 |
||
97 |
#elif defined(WINDOWS)
|
|
98 |
||
99 |
/****************************************************************************
|
|
100 |
** This routine is called by LIBSTART.ASM at module load time. All it
|
|
101 |
** does in this sample is remember the DLL module handle. The module
|
|
102 |
** handle is needed if you want to do things like load stuff from the
|
|
103 |
** resource file (for instance string resources).
|
|
104 |
****************************************************************************/
|
|
105 |
||
106 |
int _export FAR PASCAL libmain(HANDLE hModule,short cbHeapSize, |
|
107 |
UCHAR FAR *lszCmdLine) |
|
108 |
{
|
|
109 |
s_hModule = hModule; |
|
110 |
libmysql_init(); |
|
111 |
return TRUE; |
|
112 |
}
|
|
113 |
||
114 |
#endif
|