gslice: remove single-threaded case

GPrivate always works, so use it normally at all times.
This commit is contained in:
Ryan Lortie 2011-09-21 20:13:57 -04:00
parent ca154c399b
commit af9e40dc5d

View File

@ -419,38 +419,11 @@ thread_memory_from_self (void)
ThreadMemory *tmem = g_private_get (&private_thread_memory);
if (G_UNLIKELY (!tmem))
{
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.
*/
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_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;
}