[glib/wip/mutexes: 23/58] gslice: move initialisation to glib-ctor
- From: Ryan Lortie <ryanl src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib/wip/mutexes: 23/58] gslice: move initialisation to glib-ctor
- Date: Mon, 19 Sep 2011 05:14:51 +0000 (UTC)
commit 233e66c195ae828f75ecff3738124041d7b1e586
Author: Ryan Lortie <desrt desrt ca>
Date: Sun Sep 18 02:17:17 2011 -0400
gslice: move initialisation to glib-ctor
glib/gslice.c | 28 +++++-----------------------
glib/gthread.c | 3 ---
glib/gthreadprivate.h | 1 -
3 files changed, 5 insertions(+), 27 deletions(-)
---
diff --git a/glib/gslice.c b/glib/gslice.c
index f552d45..05b4a5a 100644
--- a/glib/gslice.c
+++ b/glib/gslice.c
@@ -52,6 +52,7 @@
#include "gthread.h"
#include "gthreadprivate.h"
#include "glib_trace.h"
+#include "glib-ctor.h"
/* the GSlice allocator is split up into 4 layers, roughly modelled after the slab
* allocator and magazine extensions as outlined in:
@@ -297,8 +298,7 @@ slice_config_init (SliceConfig *config)
config->debug_blocks = TRUE;
}
-static void
-g_slice_init_nomessage (void)
+GLIB_CTOR (g_slice_init_nomessage)
{
/* we may not use g_error() or friends here */
mem_assert (sys_page_size == 0);
@@ -360,21 +360,18 @@ g_slice_init_nomessage (void)
/* at this point, g_mem_gc_friendly() should be initialized, this
* should have been accomplished by the above g_malloc/g_new calls
*/
+ g_private_init (&private_thread_memory, private_thread_memory_cleanup);
}
static inline guint
allocator_categorize (gsize aligned_chunk_size)
{
+ GLIB_ENSURE_CTOR (g_slice_init_nomessage);
+
/* speed up the likely path */
if (G_LIKELY (aligned_chunk_size && aligned_chunk_size <= allocator->max_slab_chunk_size_for_magazine_cache))
return 1; /* use magazine cache */
- /* the above will fail (max_slab_chunk_size_for_magazine_cache == 0) if the
- * allocator is still uninitialized, or if we are not configured to use the
- * magazine cache.
- */
- if (!sys_page_size)
- g_slice_init_nomessage ();
if (!allocator->config.always_malloc &&
aligned_chunk_size &&
aligned_chunk_size <= MAX_SLAB_CHUNK_SIZE (allocator))
@@ -386,21 +383,6 @@ allocator_categorize (gsize aligned_chunk_size)
return 0; /* use malloc() */
}
-void
-_g_slice_thread_init_nomessage (void)
-{
- /* we may not use g_error() or friends here */
- if (!sys_page_size)
- g_slice_init_nomessage();
- else
- {
- /* g_slice_init_nomessage() has been called already, probably due
- * to a g_slice_alloc1() before g_thread_init().
- */
- }
- g_private_init (&private_thread_memory, private_thread_memory_cleanup);
-}
-
static inline void
g_mutex_lock_a (GMutex *mutex,
guint *contention_counter)
diff --git a/glib/gthread.c b/glib/gthread.c
index 1040629..8b561ed 100644
--- a/glib/gthread.c
+++ b/glib/gthread.c
@@ -948,9 +948,6 @@ g_thread_init_glib (void)
g_private_set (&g_thread_specific_private, main_thread);
G_THREAD_UF (thread_self, (&main_thread->system_thread));
- /* complete memory system initialization, g_private_*() works now */
- _g_slice_thread_init_nomessage ();
-
/* accomplish log system initialization to enable messaging */
_g_messages_thread_init_nomessage ();
}
diff --git a/glib/gthreadprivate.h b/glib/gthreadprivate.h
index 05a91cf..981c01e 100644
--- a/glib/gthreadprivate.h
+++ b/glib/gthreadprivate.h
@@ -49,7 +49,6 @@ void g_thread_init_glib (void);
/* base initializers, may only use g_mutex_new(), g_cond_new() */
G_GNUC_INTERNAL void _g_mem_thread_init_noprivate_nomessage (void);
/* initializers that may also use g_private_new() */
-G_GNUC_INTERNAL void _g_slice_thread_init_nomessage (void);
G_GNUC_INTERNAL void _g_messages_thread_init_nomessage (void);
/* full fledged initializers */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]