mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-02-24 11:12:11 +01:00
gslice: remove single-threaded case
GPrivate always works, so use it normally at all times.
This commit is contained in:
parent
ca154c399b
commit
af9e40dc5d
@ -419,38 +419,11 @@ thread_memory_from_self (void)
|
|||||||
ThreadMemory *tmem = g_private_get (&private_thread_memory);
|
ThreadMemory *tmem = g_private_get (&private_thread_memory);
|
||||||
if (G_UNLIKELY (!tmem))
|
if (G_UNLIKELY (!tmem))
|
||||||
{
|
{
|
||||||
static ThreadMemory *single_thread_memory = NULL; /* remember single-thread info for multi-threaded case */
|
const guint n_magazines = MAX_SLAB_INDEX (allocator);
|
||||||
if (single_thread_memory && g_thread_supported ())
|
tmem = g_malloc0 (sizeof (ThreadMemory) + sizeof (Magazine) * 2 * n_magazines);
|
||||||
{
|
tmem->magazine1 = (Magazine*) (tmem + 1);
|
||||||
g_mutex_lock (&allocator->slab_mutex);
|
tmem->magazine2 = &tmem->magazine1[n_magazines];
|
||||||
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);
|
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;
|
return tmem;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user