gslice: move initialisation to glib-ctor

This commit is contained in:
Ryan Lortie 2011-09-18 02:17:17 -04:00
parent 8f74c927f6
commit ae4419610c
3 changed files with 5 additions and 27 deletions

View File

@ -52,6 +52,7 @@
#include "gthread.h" #include "gthread.h"
#include "gthreadprivate.h" #include "gthreadprivate.h"
#include "glib_trace.h" #include "glib_trace.h"
#include "glib-ctor.h"
/* the GSlice allocator is split up into 4 layers, roughly modelled after the slab /* the GSlice allocator is split up into 4 layers, roughly modelled after the slab
* allocator and magazine extensions as outlined in: * allocator and magazine extensions as outlined in:
@ -297,8 +298,7 @@ slice_config_init (SliceConfig *config)
config->debug_blocks = TRUE; config->debug_blocks = TRUE;
} }
static void GLIB_CTOR (g_slice_init_nomessage)
g_slice_init_nomessage (void)
{ {
/* we may not use g_error() or friends here */ /* we may not use g_error() or friends here */
mem_assert (sys_page_size == 0); 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 /* at this point, g_mem_gc_friendly() should be initialized, this
* should have been accomplished by the above g_malloc/g_new calls * 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 static inline guint
allocator_categorize (gsize aligned_chunk_size) allocator_categorize (gsize aligned_chunk_size)
{ {
GLIB_ENSURE_CTOR (g_slice_init_nomessage);
/* speed up the likely path */ /* speed up the likely path */
if (G_LIKELY (aligned_chunk_size && aligned_chunk_size <= allocator->max_slab_chunk_size_for_magazine_cache)) if (G_LIKELY (aligned_chunk_size && aligned_chunk_size <= allocator->max_slab_chunk_size_for_magazine_cache))
return 1; /* use 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 && if (!allocator->config.always_malloc &&
aligned_chunk_size && aligned_chunk_size &&
aligned_chunk_size <= MAX_SLAB_CHUNK_SIZE (allocator)) aligned_chunk_size <= MAX_SLAB_CHUNK_SIZE (allocator))
@ -386,21 +383,6 @@ allocator_categorize (gsize aligned_chunk_size)
return 0; /* use malloc() */ 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 static inline void
g_mutex_lock_a (GMutex *mutex, g_mutex_lock_a (GMutex *mutex,
guint *contention_counter) guint *contention_counter)

View File

@ -949,9 +949,6 @@ g_thread_init_glib (void)
g_private_set (&g_thread_specific_private, main_thread); g_private_set (&g_thread_specific_private, main_thread);
G_THREAD_UF (thread_self, (&main_thread->system_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 */ /* accomplish log system initialization to enable messaging */
_g_messages_thread_init_nomessage (); _g_messages_thread_init_nomessage ();
} }

View File

@ -49,7 +49,6 @@ void g_thread_init_glib (void);
/* base initializers, may only use g_mutex_new(), g_cond_new() */ /* base initializers, may only use g_mutex_new(), g_cond_new() */
G_GNUC_INTERNAL void _g_mem_thread_init_noprivate_nomessage (void); G_GNUC_INTERNAL void _g_mem_thread_init_noprivate_nomessage (void);
/* initializers that may also use g_private_new() */ /* 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); G_GNUC_INTERNAL void _g_messages_thread_init_nomessage (void);
/* full fledged initializers */ /* full fledged initializers */