gslice: remove single-threaded case
authorRyan Lortie <desrt@desrt.ca>
Thu, 22 Sep 2011 00:13:57 +0000 (20:13 -0400)
committerRyan Lortie <desrt@desrt.ca>
Thu, 22 Sep 2011 00:23:02 +0000 (20:23 -0400)
GPrivate always works, so use it normally at all times.

glib/gslice.c

index 05b4a5a..7ee43f0 100644 (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;
 }