From 3b4ce828245be692017fd1fb498952e3c4238074 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Fri, 22 Aug 2008 07:20:04 +0000 Subject: [PATCH] Use atomic reference counting. 2008-08-22 Behdad Esfahbod * pango/fonts.c (pango_font_metrics_ref), (pango_font_metrics_unref): * pango/pango-attributes.c (pango_attr_list_ref), (pango_attr_list_unref): * pango/pango-coverage.c (pango_coverage_ref), (pango_coverage_unref): * pango/pango-layout.c (pango_layout_line_ref), (pango_layout_line_unref): * pango/pangowin32-fontcache.c (cache_entry_unref), (pango_win32_font_cache_loadw): * pango/pangox-fontcache.c (cache_entry_unref), (pango_x_font_cache_load): Use atomic reference counting. Pango may not be thread safe yet, but fixing it little by little is easier than doing all in one round. svn path=/trunk/; revision=2705 --- ChangeLog | 19 +++++++++++++++++++ pango/fonts.c | 6 ++---- pango/pango-attributes.c | 5 ++--- pango/pango-coverage.c | 6 ++---- pango/pango-layout.c | 5 ++--- pango/pangowin32-fontcache.c | 7 +++---- pango/pangox-fontcache.c | 7 +++---- 7 files changed, 33 insertions(+), 22 deletions(-) diff --git a/ChangeLog b/ChangeLog index 4f9b5d3..888477c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,24 @@ 2008-08-22 Behdad Esfahbod + * pango/fonts.c (pango_font_metrics_ref), + (pango_font_metrics_unref): + * pango/pango-attributes.c (pango_attr_list_ref), + (pango_attr_list_unref): + * pango/pango-coverage.c (pango_coverage_ref), + (pango_coverage_unref): + * pango/pango-layout.c (pango_layout_line_ref), + (pango_layout_line_unref): + * pango/pangowin32-fontcache.c (cache_entry_unref), + (pango_win32_font_cache_loadw): + * pango/pangox-fontcache.c (cache_entry_unref), + (pango_x_font_cache_load): + Use atomic reference counting. + + Pango may not be thread safe yet, but fixing it little by little + is easier than doing all in one round. + +2008-08-22 Behdad Esfahbod + Bug 143542 – PangoFT2Fontmap leak * pango/fonts.c: diff --git a/pango/fonts.c b/pango/fonts.c index 2f99703..066c54c 100644 --- a/pango/fonts.c +++ b/pango/fonts.c @@ -1489,7 +1489,7 @@ pango_font_metrics_ref (PangoFontMetrics *metrics) if (metrics == NULL) return NULL; - metrics->ref_count++; + g_atomic_int_inc (&metrics->ref_count); return metrics; } @@ -1510,9 +1510,7 @@ pango_font_metrics_unref (PangoFontMetrics *metrics) g_return_if_fail (metrics->ref_count > 0 ); - metrics->ref_count--; - - if (metrics->ref_count == 0) + if (g_atomic_int_dec_and_test (&metrics->ref_count)) g_slice_free (PangoFontMetrics, metrics); } diff --git a/pango/pango-attributes.c b/pango/pango-attributes.c index 3a0be40..5e5e585 100644 --- a/pango/pango-attributes.c +++ b/pango/pango-attributes.c @@ -1131,7 +1131,7 @@ pango_attr_list_ref (PangoAttrList *list) if (list == NULL) return NULL; - list->ref_count++; + g_atomic_int_inc (&list->ref_count); return list; } @@ -1154,8 +1154,7 @@ pango_attr_list_unref (PangoAttrList *list) g_return_if_fail (list->ref_count > 0); - list->ref_count--; - if (list->ref_count == 0) + if (g_atomic_int_dec_and_test (&list->ref_count)) { tmp_list = list->attributes; while (tmp_list) diff --git a/pango/pango-coverage.c b/pango/pango-coverage.c index f22431b..77559d0 100644 --- a/pango/pango-coverage.c +++ b/pango/pango-coverage.c @@ -122,7 +122,7 @@ pango_coverage_ref (PangoCoverage *coverage) { g_return_val_if_fail (coverage != NULL, NULL); - coverage->ref_count++; + g_atomic_int_inc (&coverage->ref_count); return coverage; } @@ -142,9 +142,7 @@ pango_coverage_unref (PangoCoverage *coverage) g_return_if_fail (coverage != NULL); g_return_if_fail (coverage->ref_count > 0); - coverage->ref_count--; - - if (coverage->ref_count == 0) + if (g_atomic_int_dec_and_test (&coverage->ref_count)) { for (i=0; in_blocks; i++) g_free (coverage->blocks[i].data); diff --git a/pango/pango-layout.c b/pango/pango-layout.c index 262b403..f4c307d 100644 --- a/pango/pango-layout.c +++ b/pango/pango-layout.c @@ -3878,7 +3878,7 @@ pango_layout_line_ref (PangoLayoutLine *line) if (line == NULL) return NULL; - private->ref_count++; + g_atomic_int_inc (&private->ref_count); return line; } @@ -3901,8 +3901,7 @@ pango_layout_line_unref (PangoLayoutLine *line) g_return_if_fail (private->ref_count > 0); - private->ref_count--; - if (private->ref_count == 0) + if (g_atomic_int_dec_and_test (&private->ref_count)) { g_slist_foreach (line->runs, (GFunc)free_run, GINT_TO_POINTER (1)); g_slist_free (line->runs); diff --git a/pango/pangowin32-fontcache.c b/pango/pangowin32-fontcache.c index b6934d4..577e3b8 100644 --- a/pango/pangowin32-fontcache.c +++ b/pango/pangowin32-fontcache.c @@ -160,8 +160,7 @@ static void cache_entry_unref (PangoWin32FontCache *cache, CacheEntry *entry) { - entry->ref_count--; - if (entry->ref_count == 0) + if (g_atomic_int_dec_and_test (&entry->ref_count)) { PING (("removing cache entry %p", entry->hfont)); @@ -233,7 +232,7 @@ pango_win32_font_cache_loadw (PangoWin32FontCache *cache, if (entry) { - entry->ref_count++; + g_atomic_int_inc (entry->ref_count); PING (("increased refcount for cache entry %p: %d", entry->hfont, entry->ref_count)); } else @@ -384,7 +383,7 @@ pango_win32_font_cache_loadw (PangoWin32FontCache *cache, } else { - entry->ref_count++; + g_atomic_int_inc (entry->ref_count); /* Insert into the mru list */ diff --git a/pango/pangox-fontcache.c b/pango/pangox-fontcache.c index a56fe73..c1177b8 100644 --- a/pango/pangox-fontcache.c +++ b/pango/pangox-fontcache.c @@ -118,8 +118,7 @@ pango_x_font_cache_new (Display *display) static void cache_entry_unref (PangoXFontCache *cache, CacheEntry *entry) { - entry->ref_count--; - if (entry->ref_count == 0) + if (g_atomic_int_dec_and_test (&entry->ref_count)) { g_hash_table_remove (cache->forward, entry->xlfd); g_hash_table_remove (cache->back, entry->fs); @@ -154,7 +153,7 @@ pango_x_font_cache_load (PangoXFontCache *cache, if (entry) { - entry->ref_count++; + g_atomic_int_inc (&entry->ref_count); } else { @@ -200,7 +199,7 @@ pango_x_font_cache_load (PangoXFontCache *cache, } else { - entry->ref_count++; + g_atomic_int_inc (&entry->ref_count); /* Insert into the mru list */ -- 2.7.4