From 8e91cf9eb98da826abc1384418b5e9a4401048b8 Mon Sep 17 00:00:00 2001 From: Sebastian Wilhelmi Date: Fri, 14 Feb 2003 15:08:46 +0000 Subject: [PATCH] Fixes for #101264 and #99372: 2003-02-14 Sebastian Wilhelmi Fixes for #101264 and #99372: * glib/gconvert.h, glib/gmain.c, glib/gmem.c, glib/gmessages.c, glib/grand.c: Include gthreadinit.h and rename the thread initialization functions a bit and let them start with _, so that later we can stop exporting them. * glib/gmem.c, glib/gmessages.c: Move the g_private_new() calls to new functions. They have to be called after setting g_threads_got_initialized to TRUE (see #101264). * glib/gthread.c: Include gthreadinit.h. Renamed g_mutex_init() to g_thread_init_glib(). Call the thread initialization functions (which are not allowed to call g_private_new), then set g_threads_got_initialized to TRUE, then call the other thread initialization functions (which must not call anything but g_private_new()). * glib/gthreadinit.h: New private header to cleanly declare all thread initialization functions. * gthread/gthread-impl.c: Include gthreadinit.h. In g_thread_init() just call g_thread_init_glib(), which in turn calls the other functions (see #99372). * glib/Makefile.am: Added gthreadinit.h. --- ChangeLog | 29 +++++++++++++++++++++++++++++ ChangeLog.pre-2-10 | 29 +++++++++++++++++++++++++++++ ChangeLog.pre-2-12 | 29 +++++++++++++++++++++++++++++ ChangeLog.pre-2-4 | 29 +++++++++++++++++++++++++++++ ChangeLog.pre-2-6 | 29 +++++++++++++++++++++++++++++ ChangeLog.pre-2-8 | 29 +++++++++++++++++++++++++++++ glib/Makefile.am | 1 + glib/gconvert.c | 3 ++- glib/gmain.c | 3 ++- glib/gmem.c | 15 ++++++++++++--- glib/gmessages.c | 11 +++++++++-- glib/grand.c | 4 ++-- glib/gthread.c | 32 +++++++++++++++++++++----------- glib/gthreadinit.h | 42 ++++++++++++++++++++++++++++++++++++++++++ gthread/gthread-impl.c | 23 ++--------------------- 15 files changed, 267 insertions(+), 41 deletions(-) create mode 100644 glib/gthreadinit.h diff --git a/ChangeLog b/ChangeLog index a946c1cf3..da4d62fcd 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,32 @@ +2003-02-14 Sebastian Wilhelmi + + Fixes for #101264 and #99372: + + * glib/gconvert.h, glib/gmain.c, glib/gmem.c, glib/gmessages.c, + glib/grand.c: Include gthreadinit.h and rename the thread + initialization functions a bit and let them start with _, so that + later we can stop exporting them. + + * glib/gmem.c, glib/gmessages.c: Move the g_private_new() calls to + new functions. They have to be called after setting + g_threads_got_initialized to TRUE (see #101264). + + * glib/gthread.c: Include gthreadinit.h. Renamed g_mutex_init() to + g_thread_init_glib(). Call the thread initialization functions + (which are not allowed to call g_private_new), then set + g_threads_got_initialized to TRUE, then call the other thread + initialization functions (which must not call anything but + g_private_new()). + + * glib/gthreadinit.h: New private header to cleanly declare all + thread initialization functions. + + * gthread/gthread-impl.c: Include gthreadinit.h. In + g_thread_init() just call g_thread_init_glib(), which in turn calls the + other functions (see #99372). + + * glib/Makefile.am: Added gthreadinit.h. + 2003-02-12 Sebastian Wilhelmi * configure.in: Make GLib recognize Tru64Unix thread system. (#103020) diff --git a/ChangeLog.pre-2-10 b/ChangeLog.pre-2-10 index a946c1cf3..da4d62fcd 100644 --- a/ChangeLog.pre-2-10 +++ b/ChangeLog.pre-2-10 @@ -1,3 +1,32 @@ +2003-02-14 Sebastian Wilhelmi + + Fixes for #101264 and #99372: + + * glib/gconvert.h, glib/gmain.c, glib/gmem.c, glib/gmessages.c, + glib/grand.c: Include gthreadinit.h and rename the thread + initialization functions a bit and let them start with _, so that + later we can stop exporting them. + + * glib/gmem.c, glib/gmessages.c: Move the g_private_new() calls to + new functions. They have to be called after setting + g_threads_got_initialized to TRUE (see #101264). + + * glib/gthread.c: Include gthreadinit.h. Renamed g_mutex_init() to + g_thread_init_glib(). Call the thread initialization functions + (which are not allowed to call g_private_new), then set + g_threads_got_initialized to TRUE, then call the other thread + initialization functions (which must not call anything but + g_private_new()). + + * glib/gthreadinit.h: New private header to cleanly declare all + thread initialization functions. + + * gthread/gthread-impl.c: Include gthreadinit.h. In + g_thread_init() just call g_thread_init_glib(), which in turn calls the + other functions (see #99372). + + * glib/Makefile.am: Added gthreadinit.h. + 2003-02-12 Sebastian Wilhelmi * configure.in: Make GLib recognize Tru64Unix thread system. (#103020) diff --git a/ChangeLog.pre-2-12 b/ChangeLog.pre-2-12 index a946c1cf3..da4d62fcd 100644 --- a/ChangeLog.pre-2-12 +++ b/ChangeLog.pre-2-12 @@ -1,3 +1,32 @@ +2003-02-14 Sebastian Wilhelmi + + Fixes for #101264 and #99372: + + * glib/gconvert.h, glib/gmain.c, glib/gmem.c, glib/gmessages.c, + glib/grand.c: Include gthreadinit.h and rename the thread + initialization functions a bit and let them start with _, so that + later we can stop exporting them. + + * glib/gmem.c, glib/gmessages.c: Move the g_private_new() calls to + new functions. They have to be called after setting + g_threads_got_initialized to TRUE (see #101264). + + * glib/gthread.c: Include gthreadinit.h. Renamed g_mutex_init() to + g_thread_init_glib(). Call the thread initialization functions + (which are not allowed to call g_private_new), then set + g_threads_got_initialized to TRUE, then call the other thread + initialization functions (which must not call anything but + g_private_new()). + + * glib/gthreadinit.h: New private header to cleanly declare all + thread initialization functions. + + * gthread/gthread-impl.c: Include gthreadinit.h. In + g_thread_init() just call g_thread_init_glib(), which in turn calls the + other functions (see #99372). + + * glib/Makefile.am: Added gthreadinit.h. + 2003-02-12 Sebastian Wilhelmi * configure.in: Make GLib recognize Tru64Unix thread system. (#103020) diff --git a/ChangeLog.pre-2-4 b/ChangeLog.pre-2-4 index a946c1cf3..da4d62fcd 100644 --- a/ChangeLog.pre-2-4 +++ b/ChangeLog.pre-2-4 @@ -1,3 +1,32 @@ +2003-02-14 Sebastian Wilhelmi + + Fixes for #101264 and #99372: + + * glib/gconvert.h, glib/gmain.c, glib/gmem.c, glib/gmessages.c, + glib/grand.c: Include gthreadinit.h and rename the thread + initialization functions a bit and let them start with _, so that + later we can stop exporting them. + + * glib/gmem.c, glib/gmessages.c: Move the g_private_new() calls to + new functions. They have to be called after setting + g_threads_got_initialized to TRUE (see #101264). + + * glib/gthread.c: Include gthreadinit.h. Renamed g_mutex_init() to + g_thread_init_glib(). Call the thread initialization functions + (which are not allowed to call g_private_new), then set + g_threads_got_initialized to TRUE, then call the other thread + initialization functions (which must not call anything but + g_private_new()). + + * glib/gthreadinit.h: New private header to cleanly declare all + thread initialization functions. + + * gthread/gthread-impl.c: Include gthreadinit.h. In + g_thread_init() just call g_thread_init_glib(), which in turn calls the + other functions (see #99372). + + * glib/Makefile.am: Added gthreadinit.h. + 2003-02-12 Sebastian Wilhelmi * configure.in: Make GLib recognize Tru64Unix thread system. (#103020) diff --git a/ChangeLog.pre-2-6 b/ChangeLog.pre-2-6 index a946c1cf3..da4d62fcd 100644 --- a/ChangeLog.pre-2-6 +++ b/ChangeLog.pre-2-6 @@ -1,3 +1,32 @@ +2003-02-14 Sebastian Wilhelmi + + Fixes for #101264 and #99372: + + * glib/gconvert.h, glib/gmain.c, glib/gmem.c, glib/gmessages.c, + glib/grand.c: Include gthreadinit.h and rename the thread + initialization functions a bit and let them start with _, so that + later we can stop exporting them. + + * glib/gmem.c, glib/gmessages.c: Move the g_private_new() calls to + new functions. They have to be called after setting + g_threads_got_initialized to TRUE (see #101264). + + * glib/gthread.c: Include gthreadinit.h. Renamed g_mutex_init() to + g_thread_init_glib(). Call the thread initialization functions + (which are not allowed to call g_private_new), then set + g_threads_got_initialized to TRUE, then call the other thread + initialization functions (which must not call anything but + g_private_new()). + + * glib/gthreadinit.h: New private header to cleanly declare all + thread initialization functions. + + * gthread/gthread-impl.c: Include gthreadinit.h. In + g_thread_init() just call g_thread_init_glib(), which in turn calls the + other functions (see #99372). + + * glib/Makefile.am: Added gthreadinit.h. + 2003-02-12 Sebastian Wilhelmi * configure.in: Make GLib recognize Tru64Unix thread system. (#103020) diff --git a/ChangeLog.pre-2-8 b/ChangeLog.pre-2-8 index a946c1cf3..da4d62fcd 100644 --- a/ChangeLog.pre-2-8 +++ b/ChangeLog.pre-2-8 @@ -1,3 +1,32 @@ +2003-02-14 Sebastian Wilhelmi + + Fixes for #101264 and #99372: + + * glib/gconvert.h, glib/gmain.c, glib/gmem.c, glib/gmessages.c, + glib/grand.c: Include gthreadinit.h and rename the thread + initialization functions a bit and let them start with _, so that + later we can stop exporting them. + + * glib/gmem.c, glib/gmessages.c: Move the g_private_new() calls to + new functions. They have to be called after setting + g_threads_got_initialized to TRUE (see #101264). + + * glib/gthread.c: Include gthreadinit.h. Renamed g_mutex_init() to + g_thread_init_glib(). Call the thread initialization functions + (which are not allowed to call g_private_new), then set + g_threads_got_initialized to TRUE, then call the other thread + initialization functions (which must not call anything but + g_private_new()). + + * glib/gthreadinit.h: New private header to cleanly declare all + thread initialization functions. + + * gthread/gthread-impl.c: Include gthreadinit.h. In + g_thread_init() just call g_thread_init_glib(), which in turn calls the + other functions (see #99372). + + * glib/Makefile.am: Added gthreadinit.h. + 2003-02-12 Sebastian Wilhelmi * configure.in: Make GLib recognize Tru64Unix thread system. (#103020) diff --git a/glib/Makefile.am b/glib/Makefile.am index 447584eed..559b70ba2 100644 --- a/glib/Makefile.am +++ b/glib/Makefile.am @@ -77,6 +77,7 @@ libglib_2_0_la_SOURCES = \ gstrfuncs.c \ gstring.c \ gthread.c \ + gthreadinit.h \ gthreadpool.c \ gtimer.c \ gtree.c \ diff --git a/glib/gconvert.c b/glib/gconvert.c index 03939f39d..4e7b9dcfd 100644 --- a/glib/gconvert.c +++ b/glib/gconvert.c @@ -30,6 +30,7 @@ #include "glib.h" #include "gprintfint.h" +#include "gthreadinit.h" #ifdef G_PLATFORM_WIN32 #define STRICT @@ -1222,7 +1223,7 @@ have_broken_filenames (void) * initialize some static data in a threadsafe way. */ void -g_convert_init (void) +_g_convert_thread_init (void) { #ifndef G_PLATFORM_WIN32 (void)have_broken_filenames (); diff --git a/glib/gmain.c b/glib/gmain.c index c8d0011df..92bd020ea 100644 --- a/glib/gmain.c +++ b/glib/gmain.c @@ -37,6 +37,7 @@ /* #define G_MAIN_POLL_DEBUG */ #include "glib.h" +#include "gthreadinit.h" #include #include #ifdef HAVE_SYS_TIME_H @@ -623,7 +624,7 @@ g_main_context_init_pipe (GMainContext *context) } void -g_main_thread_init () +_g_main_thread_init () { GSList *curr = main_contexts_without_pipe; while (curr) diff --git a/glib/gmem.c b/glib/gmem.c index 22445a864..6f564f2ff 100644 --- a/glib/gmem.c +++ b/glib/gmem.c @@ -35,7 +35,7 @@ #include #include "glib.h" - +#include "gthreadinit.h" /* notes on macros: * having DISABLE_MEM_POOLS defined, disables mem_chunks alltogether, their @@ -1253,13 +1253,22 @@ g_allocator_free (GAllocator *allocator) } void -g_mem_init (void) +_g_mem_thread_init (void) { #ifndef DISABLE_MEM_POOLS mem_chunks_lock = g_mutex_new (); #endif #ifndef G_DISABLE_CHECKS - mem_chunk_recursion = g_private_new (NULL); g_profile_mutex = g_mutex_new (); #endif } + +void +_g_mem_thread_private_init (void) +{ +#ifndef G_DISABLE_CHECKS + g_assert (mem_chunk_recursion == NULL); + mem_chunk_recursion = g_private_new (NULL); +#endif +} + diff --git a/glib/gmessages.c b/glib/gmessages.c index 4743d4536..4f0064c71 100644 --- a/glib/gmessages.c +++ b/glib/gmessages.c @@ -44,6 +44,7 @@ #include "glib.h" #include "gdebug.h" #include "gprintfint.h" +#include "gthreadinit.h" #ifdef G_OS_WIN32 #include @@ -929,14 +930,20 @@ g_printf_string_upper_bound (const gchar *format, } void -g_messages_init (void) +_g_messages_thread_init (void) { g_messages_lock = g_mutex_new (); - g_log_depth = g_private_new (NULL); g_messages_prefixed_init (); _g_debug_init (); } +void +_g_messages_thread_private_init (void) +{ + g_assert (g_log_depth == NULL); + g_log_depth = g_private_new (NULL); +} + gboolean _g_debug_initialized = FALSE; guint _g_debug_flags = 0; diff --git a/glib/grand.c b/glib/grand.c index 1cbb898ee..ef28b829e 100644 --- a/glib/grand.c +++ b/glib/grand.c @@ -43,7 +43,7 @@ #include #include "glib.h" - +#include "gthreadinit.h" G_LOCK_DEFINE_STATIC (global_random); static GRand* global_random = NULL; @@ -93,7 +93,7 @@ get_random_version (void) * initialize some static data in a threadsafe way. */ void -g_rand_init (void) +_g_rand_thread_init (void) { (void)get_random_version (); } diff --git a/glib/gthread.c b/glib/gthread.c index 34d168127..2c65d9564 100644 --- a/glib/gthread.c +++ b/glib/gthread.c @@ -48,7 +48,7 @@ #include #include "glib.h" - +#include "gthreadinit.h" #if GLIB_SIZEOF_SYSTEM_THREAD == SIZEOF_VOID_P # define g_system_thread_equal_simple(thread1, thread2) \ @@ -158,22 +158,22 @@ G_LOCK_DEFINE_STATIC (g_thread); /* This must be called only once, before any threads are created. * It will only be called from g_thread_init() in -lgthread. */ -void -g_mutex_init (void) +void +g_thread_init_glib (void) { - GRealThread* main_thread; - /* We let the main thread (the one that calls g_thread_init) inherit - * the data, that it set before calling g_thread_init + * the static_private data set before calling g_thread_init */ - main_thread = (GRealThread*) g_thread_self (); - - g_thread_specific_private = g_private_new (g_thread_cleanup); - G_THREAD_UF (private_set, (g_thread_specific_private, main_thread)); - G_THREAD_UF (thread_self, (&main_thread->system_thread)); + GRealThread* main_thread = (GRealThread*) g_thread_self (); g_mutex_protect_static_mutex_allocation = g_mutex_new (); + _g_convert_thread_init (); + _g_rand_thread_init (); + _g_main_thread_init (); + _g_mem_thread_init (); + _g_messages_thread_init (); + #ifdef G_THREAD_USE_PID_SURROGATE priority_map[G_THREAD_PRIORITY_NORMAL] = getpriority (PRIO_PROCESS, (getpid ())); @@ -184,6 +184,16 @@ g_mutex_init (void) priority_map[G_THREAD_PRIORITY_URGENT] = MAX (-20, priority_map[G_THREAD_PRIORITY_NORMAL] - 15); #endif /* G_THREAD_USE_PID_SURROGATE */ + + g_threads_got_initialized = TRUE; + + g_thread_specific_private = g_private_new (g_thread_cleanup); + g_private_set (g_thread_specific_private, main_thread); + G_THREAD_UF (thread_self, (&main_thread->system_thread)); + + _g_mem_thread_private_init (); + _g_messages_thread_private_init (); + } void diff --git a/glib/gthreadinit.h b/glib/gthreadinit.h new file mode 100644 index 000000000..c8a8e8b7c --- /dev/null +++ b/glib/gthreadinit.h @@ -0,0 +1,42 @@ +/* gthreadinit.h - GLib internal thread initialization functions + * + * Copyright (C) 2003 Sebastian Wilhelmi + * + * The Gnome Library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2 of the + * License, or (at your option) any later version. + * + * The Gnome Library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with the Gnome Library; see the file COPYING.LIB. If not, + * write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#ifndef __G_THREADINIT_H__ +#define __G_THREADINIT_H__ + +G_BEGIN_DECLS + +/* Is called from gthread/gthread-impl.c */ +void g_thread_init_glib (void); + +/* Are called from glib/gthread.c. May not contain g_private_new calls */ +void _g_mem_thread_init (void); +void _g_messages_thread_init (void); +void _g_convert_thread_init (void); +void _g_rand_thread_init (void); +void _g_main_thread_init (void); + +/* Are called from glib/gthread.c. Must only contain g_private_new calls */ +void _g_mem_thread_private_init (void); +void _g_messages_thread_private_init (void); + +G_END_DECLS + +#endif /* __G_THREADINIT_H__ */ diff --git a/gthread/gthread-impl.c b/gthread/gthread-impl.c index 3825e40d4..901c3b430 100644 --- a/gthread/gthread-impl.c +++ b/gthread/gthread-impl.c @@ -36,6 +36,7 @@ #endif #include +#include #ifdef G_THREADS_ENABLED @@ -336,9 +337,6 @@ g_thread_init (GThreadFunctions* init) g_thread_functions_for_glib_use = *init; - /* It is important, that g_threads_got_initialized is not set before the - * thread initialization functions of the different modules are called - */ supported = (init->mutex_new && init->mutex_lock && init->mutex_trylock && @@ -376,24 +374,7 @@ g_thread_init (GThreadFunctions* init) g_thread_priority_map [G_THREAD_PRIORITY_HIGH] = PRIORITY_HIGH_VALUE; g_thread_priority_map [G_THREAD_PRIORITY_URGENT] = PRIORITY_URGENT_VALUE; - /* now call the thread initialization functions of the different - * glib modules. order does matter, g_mutex_init MUST come first. - */ - g_mutex_init (); - g_mem_init (); - g_messages_init (); - g_convert_init (); - g_rand_init (); - - /* now we can set g_threads_got_initialized and thus enable - * all the thread functions - */ - g_threads_got_initialized = TRUE; - - /* This has to come after g_threads_got_initialized is set - * since it uses a private variable created by g_mem_init() - */ - g_main_thread_init (); + g_thread_init_glib (); } #else /* !G_THREADS_ENABLED */