Use thread-safe qdata API for caching
authorMatthias Clasen <mclasen@redhat.com>
Sat, 1 Sep 2012 14:32:21 +0000 (10:32 -0400)
committerMatthias Clasen <mclasen@redhat.com>
Sat, 1 Sep 2012 14:32:21 +0000 (10:32 -0400)
GLib gained a new API that allows to set qdata in a thread-safe
way. Use it here.

pango/pango-context.c
pango/pangocairo-context.c

index 2a100e9..2a1e44f 100644 (file)
@@ -594,15 +594,20 @@ get_shaper_font_cache (PangoFontset *fontset)
   if (G_UNLIKELY (!cache_quark))
     cache_quark = g_quark_from_static_string ("pango-shaper-font-cache");
 
+retry:
   cache = g_object_get_qdata (G_OBJECT (fontset), cache_quark);
-  if (!cache)
+  if (G_UNLIKELY (!cache))
     {
       cache = g_slice_new (ShaperFontCache);
       cache->hash = g_hash_table_new_full (g_direct_hash, NULL,
                                           NULL, (GDestroyNotify)shaper_font_element_destroy);
-
-      g_object_set_qdata_full (G_OBJECT (fontset), cache_quark,
-                              cache, (GDestroyNotify)shaper_font_cache_destroy);
+      if (!g_object_replace_qdata (G_OBJECT (fontset), cache_quark, NULL,
+                                   cache, (GDestroyNotify)shaper_font_cache_destroy,
+                                   NULL))
+        {
+          shaper_font_cache_destroy (cache);
+          goto retry;
+        }
     }
 
   return cache;
index 54cef06..65223b6 100644 (file)
@@ -68,6 +68,7 @@ get_context_info (PangoContext *context,
   if (G_UNLIKELY (!context_info_quark))
     context_info_quark = g_quark_from_static_string ("pango-cairo-context-info");
 
+retry:
   info = g_object_get_qdata (G_OBJECT (context), context_info_quark);
 
   if (G_UNLIKELY (!info) && create)
@@ -75,8 +76,13 @@ get_context_info (PangoContext *context,
       info = g_slice_new0 (PangoCairoContextInfo);
       info->dpi = -1.0;
 
-      g_object_set_qdata_full (G_OBJECT (context), context_info_quark,
-                              info, (GDestroyNotify)free_context_info);
+      if (!g_object_replace_qdata (G_OBJECT (context), context_info_quark, NULL,
+                                   info, (GDestroyNotify)free_context_info,
+                                   NULL))
+        {
+          free_context_info (info);
+          goto retry;
+        }
     }
 
   return info;