From: unknown Date: Mon, 13 Feb 2012 16:34:08 +0000 (+0100) Subject: Fix twice call of xbt_preinit and xbt_postinit X-Git-Tag: exp_20120216~12 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/18faa5d6f39d6e2765762c8bc76502dd5c62a550?hp=13333d25e7025f0903f45d33581243f3643dbbe2;ds=sidebyside Fix twice call of xbt_preinit and xbt_postinit --- diff --git a/src/xbt/xbt_main.c b/src/xbt/xbt_main.c index d1b1d16fcb..36c5edfe4a 100644 --- a/src/xbt/xbt_main.c +++ b/src/xbt/xbt_main.c @@ -78,16 +78,23 @@ static void xbt_postexit(void) _XBT_GNUC_DESTRUCTOR; BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved); +/* Should not be necessary but for some reason, + * DllMain is called twice at attachment and + * at detachment.*/ +static int xbt_dll_process_is_dattached = 0; +static int xbt_dll_process_is_attached = 0; /* see also http://msdn.microsoft.com/en-us/library/ms682583%28VS.85%29.aspx */ /* and http://www.microsoft.com/whdc/driver/kernel/DLL_bestprac.mspx */ BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) { - if (fdwReason == DLL_PROCESS_ATTACH) { - xbt_preinit(); - } else if (fdwReason == DLL_PROCESS_DETACH) { - xbt_postexit(); + if (fdwReason == DLL_PROCESS_ATTACH + && xbt_dll_process_is_attached == 0) { + xbt_preinit(); + } else if (fdwReason == DLL_PROCESS_DETACH + && xbt_dll_process_is_dattached == 0) { + xbt_postexit(); } return 1; } @@ -97,6 +104,7 @@ BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, static void xbt_preinit(void) { + xbt_dll_process_is_attached = 1; #ifdef MMALLOC_WANT_OVERIDE_LEGACY mmalloc_preinit(); #endif @@ -143,6 +151,7 @@ static void xbt_preinit(void) static void xbt_postexit(void) { + xbt_dll_process_is_dattached = 1; xbt_trp_postexit(); xbt_datadesc_postexit();