[maemo-commits] [maemo-commits] r12906 - in projects/haf/trunk/glib: . glib
From: subversion at stage.maemo.org subversion at stage.maemo.orgDate: Mon Jul 30 16:33:08 EEST 2007
- Previous message: [maemo-commits] r12903 - in projects/haf/trunk/hildon-plugins-settings: . debian
- Next message: [maemo-commits] r12907 - projects/haf/trunk/posix-locales/debian
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Author: mitch Date: 2007-07-30 16:33:00 +0300 (Mon, 30 Jul 2007) New Revision: 12906 Modified: projects/haf/trunk/glib/ChangeLog projects/haf/trunk/glib/glib/glib.symbols projects/haf/trunk/glib/glib/gslice.c projects/haf/trunk/glib/glib/gslice.h Log: 2007-07-30 Michael Natterer <mitch at imendio.com> * glib/gslice.[ch]: replace with versions from upstream trunk, merging the following changes: Thu Jul 12 15:46:40 2007 Tim Janik <timj at imendio.com> * glib/gslice.c: migrate per-thread magazine caches from single-thread scenario to first thread using GSlice after g_thread_init(); based on a patch by Tor Lillqvist, fixes #331853. removed warning about g_thread_init() being called after other glib functions (in particular g_slice* calls), because GSlice can cope with this now and the rest of glib is believed to cope as well. 2007-06-13 Sven Neumann <sven at gimp.org> * glib/gslice.[ch] added g_slice_copy() and g_slice_dup() (#442029). * glib/glib.symbols: updated. Modified: projects/haf/trunk/glib/ChangeLog =================================================================== --- projects/haf/trunk/glib/ChangeLog 2007-07-30 13:32:12 UTC (rev 12905) +++ projects/haf/trunk/glib/ChangeLog 2007-07-30 13:33:00 UTC (rev 12906) @@ -1,3 +1,23 @@ +2007-07-30 Michael Natterer <mitch at imendio.com> + + * glib/gslice.[ch]: replace with versions from upstream trunk, + merging the following changes: + + Thu Jul 12 15:46:40 2007 Tim Janik <timj at imendio.com> + + * glib/gslice.c: migrate per-thread magazine caches from single-thread + scenario to first thread using GSlice after g_thread_init(); based on + a patch by Tor Lillqvist, fixes #331853. + removed warning about g_thread_init() being called after other glib + functions (in particular g_slice* calls), because GSlice can cope + with this now and the rest of glib is believed to cope as well. + + 2007-06-13 Sven Neumann <sven at gimp.org> + + * glib/gslice.[ch] added g_slice_copy() and g_slice_dup() (#442029). + + * glib/glib.symbols: updated. + 2007-06-21 Fernando Herrera <fernando.herrera-de-las-heras at nokia.com> * m4macros/glib-2.0.m4: Revert last upstream change and use Modified: projects/haf/trunk/glib/glib/glib.symbols =================================================================== --- projects/haf/trunk/glib/glib/glib.symbols 2007-07-30 13:32:12 UTC (rev 12905) +++ projects/haf/trunk/glib/glib/glib.symbols 2007-07-30 13:33:00 UTC (rev 12906) @@ -679,6 +679,7 @@ #if IN_FILE(__G_SLICE_C__) g_slice_alloc G_GNUC_MALLOC g_slice_alloc0 G_GNUC_MALLOC +g_slice_copy G_GNUC_MALLOC g_slice_free1 g_slice_free_chain_with_offset g_slice_set_config Modified: projects/haf/trunk/glib/glib/gslice.c =================================================================== --- projects/haf/trunk/glib/glib/gslice.c 2007-07-30 13:32:12 UTC (rev 12905) +++ projects/haf/trunk/glib/glib/gslice.c 2007-07-30 13:33:00 UTC (rev 12906) @@ -372,20 +372,14 @@ _g_slice_thread_init_nomessage (void) { /* we may not use g_error() or friends here */ - if (sys_page_size) + if (!sys_page_size) + g_slice_init_nomessage(); + else { - const char *pname; - - /* mem_error ("g_thread_init() must be called before GSlice is used, memory corrupted..."); */ - fputs ("\n***MEMORY-WARNING***: ", stderr); - pname = g_get_prgname(); - fprintf (stderr, "%s[%u]: GSlice: ", pname ? pname : "", getpid()); - fputs ("g_thread_init() must be called before all other GLib functions; " - "memory corruption due to late invocation of g_thread_init() has been detected; " - "this program is likely to crash, leak or unexpectedly abort soon...\n", stderr); + /* g_slice_init_nomessage() has been called already, probably due + * to a g_slice_alloc1() before g_thread_init(). + */ } - if (!sys_page_size) - g_slice_init_nomessage(); private_thread_memory = g_private_new (private_thread_memory_cleanup); allocator->magazine_mutex = g_mutex_new(); allocator->slab_mutex = g_mutex_new(); @@ -429,11 +423,38 @@ ThreadMemory *tmem = g_private_get (private_thread_memory); if (G_UNLIKELY (!tmem)) { - const guint n_magazines = MAX_SLAB_INDEX (allocator); - tmem = g_malloc0 (sizeof (ThreadMemory) + sizeof (Magazine) * 2 * n_magazines); - tmem->magazine1 = (Magazine*) (tmem + 1); - tmem->magazine2 = &tmem->magazine1[n_magazines]; + static ThreadMemory *single_thread_memory = NULL; /* remember single-thread info for multi-threaded case */ + if (single_thread_memory && g_thread_supported ()) + { + g_mutex_lock (allocator->slab_mutex); + if (single_thread_memory) + { + /* GSlice has been used before g_thread_init(), and now + * we are running threaded. to cope with it, use the saved + * thread memory structure from when we weren't threaded. + */ + tmem = single_thread_memory; + single_thread_memory = NULL; /* slab_mutex protected when multi-threaded */ + } + g_mutex_unlock (allocator->slab_mutex); + } + if (!tmem) + { + const guint n_magazines = MAX_SLAB_INDEX (allocator); + tmem = g_malloc0 (sizeof (ThreadMemory) + sizeof (Magazine) * 2 * n_magazines); + tmem->magazine1 = (Magazine*) (tmem + 1); + tmem->magazine2 = &tmem->magazine1[n_magazines]; + } + /* g_private_get/g_private_set works in the single-threaded xor the multi- + * threaded case. but not *across* g_thread_init(), after multi-thread + * initialization it returns NULL for previously set single-thread data. + */ g_private_set (private_thread_memory, tmem); + /* save single-thread thread memory structure, in case we need to + * pick it up again after multi-thread initialization happened. + */ + if (!single_thread_memory && !g_thread_supported ()) + single_thread_memory = tmem; /* no slab_mutex created yet */ } return tmem; } @@ -815,6 +836,16 @@ return mem; } +gpointer +g_slice_copy (gsize mem_size, + gpointer mem_block) +{ + gpointer mem = g_slice_alloc (mem_size); + if (mem) + memcpy (mem, mem_block, mem_size); + return mem; +} + void g_slice_free1 (gsize mem_size, gpointer mem_block) Modified: projects/haf/trunk/glib/glib/gslice.h =================================================================== --- projects/haf/trunk/glib/glib/gslice.h 2007-07-30 13:32:12 UTC (rev 12905) +++ projects/haf/trunk/glib/glib/gslice.h 2007-07-30 13:33:00 UTC (rev 12906) @@ -31,6 +31,8 @@ */ gpointer g_slice_alloc (gsize block_size) G_GNUC_MALLOC; gpointer g_slice_alloc0 (gsize block_size) G_GNUC_MALLOC; +gpointer g_slice_copy (gsize block_size, + gpointer mem_block) G_GNUC_MALLOC; void g_slice_free1 (gsize block_size, gpointer mem_block); void g_slice_free_chain_with_offset (gsize block_size, @@ -38,8 +40,11 @@ gsize next_offset); #define g_slice_new(type) ((type*) g_slice_alloc (sizeof (type))) #define g_slice_new0(type) ((type*) g_slice_alloc0 (sizeof (type))) -/* g_slice_free (MemoryBlockType, +/* MemoryBlockType * + * g_slice_dup (MemoryBlockType, * MemoryBlockType *mem_block); + * g_slice_free (MemoryBlockType, + * MemoryBlockType *mem_block); * g_slice_free_chain (MemoryBlockType, * MemoryBlockType *first_chain_block, * memory_block_next_field); @@ -48,6 +53,8 @@ */ /* we go through extra hoops to ensure type safety */ +#define g_slice_dup(type, mem) \ + (1 ? g_slice_copy (sizeof (type), (mem)) : (type*) ((type*) 0 == (mem))) #define g_slice_free(type, mem) do { \ if (1) g_slice_free1 (sizeof (type), (mem)); \ else (void) ((type*) 0 == (mem)); \
- Previous message: [maemo-commits] r12903 - in projects/haf/trunk/hildon-plugins-settings: . debian
- Next message: [maemo-commits] r12907 - projects/haf/trunk/posix-locales/debian
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]