Refactor glib/glib-init.c to isolate init/deinit steps in isolated functions

This commit is contained in:
Loic Le Page 2022-01-20 16:24:44 +01:00
parent 4fdbfcc9b7
commit 2ff2c9eb5b

View File

@ -342,12 +342,36 @@ glib_init (void)
#ifdef G_PLATFORM_WIN32
HMODULE glib_dll = NULL;
static void
glib_win32_init (void)
{
g_crash_handler_win32_init ();
#ifdef THREADS_WIN32
g_thread_win32_init ();
#endif
g_clock_win32_init ();
glib_init ();
/* must go after glib_init */
g_console_win32_init ();
}
static void
glib_win32_deinit (gboolean detach_thread)
{
#ifdef THREADS_WIN32
if (detach_thread)
g_thread_win32_process_detach ();
#endif
g_crash_handler_win32_deinit ();
}
BOOL WINAPI DllMain (HINSTANCE hinstDLL,
DWORD fdwReason,
LPVOID lpvReserved);
HMODULE glib_dll;
BOOL WINAPI
DllMain (HINSTANCE hinstDLL,
DWORD fdwReason,
@ -357,14 +381,7 @@ DllMain (HINSTANCE hinstDLL,
{
case DLL_PROCESS_ATTACH:
glib_dll = hinstDLL;
g_crash_handler_win32_init ();
g_clock_win32_init ();
#ifdef THREADS_WIN32
g_thread_win32_init ();
#endif
glib_init ();
/* must go after glib_init */
g_console_win32_init ();
glib_win32_init ();
break;
case DLL_THREAD_DETACH:
@ -374,11 +391,7 @@ DllMain (HINSTANCE hinstDLL,
break;
case DLL_PROCESS_DETACH:
#ifdef THREADS_WIN32
if (lpvReserved == NULL)
g_thread_win32_process_detach ();
#endif
g_crash_handler_win32_deinit ();
glib_win32_deinit (lpvReserved == NULL);
break;
default:
@ -389,7 +402,7 @@ DllMain (HINSTANCE hinstDLL,
return TRUE;
}
#elif defined (G_HAS_CONSTRUCTORS)
#elif defined(G_HAS_CONSTRUCTORS) /* && !G_PLATFORM_WIN32 */
#ifdef G_DEFINE_CONSTRUCTOR_NEEDS_PRAGMA
#pragma G_DEFINE_CONSTRUCTOR_PRAGMA_ARGS(glib_init_ctor)
@ -402,6 +415,6 @@ glib_init_ctor (void)
glib_init ();
}
#else
#else /* !G_PLATFORM_WIN32 && !G_HAS_CONSTRUCTORS */
# error Your platform/compiler is missing constructor support
#endif
#endif /* G_PLATFORM_WIN32 */