[gnome-desktop] GnomeDesktopThumbnail: Use GOnce for thread safety
- From: Colin Walters <walters src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-desktop] GnomeDesktopThumbnail: Use GOnce for thread safety
- Date: Wed, 25 May 2011 18:31:05 +0000 (UTC)
commit 8e1bc2df28cdecd044e79d4884ce6945b84c0d63
Author: Colin Walters <walters verbum org>
Date: Wed May 25 12:38:06 2011 -0400
GnomeDesktopThumbnail: Use GOnce for thread safety
In gnome-shell we got a crash likely caused by multiple threads racing
on initializing this hash table; see https://bugzilla.redhat.com/show_bug.cgi?id=688852
https://bugzilla.gnome.org/show_bug.cgi?id=651080
libgnome-desktop/gnome-desktop-thumbnail.c | 17 ++++++++++-------
1 files changed, 10 insertions(+), 7 deletions(-)
---
diff --git a/libgnome-desktop/gnome-desktop-thumbnail.c b/libgnome-desktop/gnome-desktop-thumbnail.c
index 99432b5..2b2fda9 100644
--- a/libgnome-desktop/gnome-desktop-thumbnail.c
+++ b/libgnome-desktop/gnome-desktop-thumbnail.c
@@ -927,16 +927,17 @@ static gboolean
mimetype_supported_by_gdk_pixbuf (const char *mime_type)
{
guint i;
- static GHashTable *formats_hash = NULL;
+ static gsize formats_hash = 0;
gchar *key;
gboolean result;
- if (!formats_hash) {
+ if (g_once_init_enter (&formats_hash)) {
GSList *formats, *list;
+ GHashTable *hash;
- formats_hash = g_hash_table_new_full (g_str_hash,
- (GEqualFunc) g_content_type_equals,
- g_free, NULL);
+ hash = g_hash_table_new_full (g_str_hash,
+ (GEqualFunc) g_content_type_equals,
+ g_free, NULL);
formats = gdk_pixbuf_get_formats ();
list = formats;
@@ -948,7 +949,7 @@ mimetype_supported_by_gdk_pixbuf (const char *mime_type)
mime_types = gdk_pixbuf_format_get_mime_types (format);
for (i = 0; mime_types[i] != NULL; i++)
- g_hash_table_insert (formats_hash,
+ g_hash_table_insert (hash,
(gpointer) g_content_type_from_mime_type (mime_types[i]),
GUINT_TO_POINTER (1));
@@ -956,10 +957,12 @@ mimetype_supported_by_gdk_pixbuf (const char *mime_type)
list = list->next;
}
g_slist_free (formats);
+
+ g_once_init_leave (&formats_hash, (gsize) hash);
}
key = g_content_type_from_mime_type (mime_type);
- if (g_hash_table_lookup (formats_hash, key))
+ if (g_hash_table_lookup ((void*)formats_hash, key))
result = TRUE;
else
result = FALSE;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]