[goobox] removed use of g_mutex_new



commit 7b0552c819a6c9a1399ab21957f63ee841319513
Author: Paolo Bacchilega <paobac src gnome org>
Date:   Tue Dec 4 15:44:21 2012 +0100

    removed use of g_mutex_new

 src/gnome-desktop-thumbnail.c |  124 ++++++++++++++++++++---------------------
 src/goo-player.c              |   10 ++--
 2 files changed, 65 insertions(+), 69 deletions(-)
---
diff --git a/src/gnome-desktop-thumbnail.c b/src/gnome-desktop-thumbnail.c
index 2b2fda9..cfc8f08 100644
--- a/src/gnome-desktop-thumbnail.c
+++ b/src/gnome-desktop-thumbnail.c
@@ -49,7 +49,7 @@
 struct _GnomeDesktopThumbnailFactoryPrivate {
   GnomeDesktopThumbnailSize size;
 
-  GMutex *lock;
+  GMutex  lock;
 
   GList *thumbnailers;
   GHashTable *mime_types_map;
@@ -253,21 +253,21 @@ get_thumbnailers_dirs (void)
 }
 
 static void
-size_prepared_cb (GdkPixbufLoader *loader, 
+size_prepared_cb (GdkPixbufLoader *loader,
 		  int              width,
 		  int              height,
 		  gpointer         data)
 {
   SizePrepareContext *info = data;
-  
+
   g_return_if_fail (width > 0 && height > 0);
-  
+
   info->input_width = width;
   info->input_height = height;
-  
+
   if (width < info->width && height < info->height) return;
-  
-  if (info->preserve_aspect_ratio && 
+
+  if (info->preserve_aspect_ratio &&
       (info->width > 0 || info->height > 0)) {
     if (info->width < 0)
       {
@@ -293,7 +293,7 @@ size_prepared_cb (GdkPixbufLoader *loader,
     if (info->height > 0)
       height = info->height;
   }
-  
+
   gdk_pixbuf_loader_set_size (loader, width, height);
 }
 
@@ -307,7 +307,7 @@ _gdk_pixbuf_new_from_uri_at_scale (const char *uri,
     char buffer[LOAD_BUFFER_SIZE];
     gsize bytes_read;
     GdkPixbufLoader *loader;
-    GdkPixbuf *pixbuf;	
+    GdkPixbuf *pixbuf;
     GdkPixbufAnimation *animation;
     GdkPixbufAnimationIter *iter;
     gboolean has_frame;
@@ -356,7 +356,7 @@ _gdk_pixbuf_new_from_uri_at_scale (const char *uri,
         info.width = width;
         info.height = height;
 	info.input_width = info.input_height = 0;
-        info.preserve_aspect_ratio = preserve_aspect_ratio;        
+        info.preserve_aspect_ratio = preserve_aspect_ratio;
         g_signal_connect (loader, "size-prepared", G_CALLBACK (size_prepared_cb), &info);
     }
 
@@ -428,7 +428,7 @@ gnome_desktop_thumbnail_factory_finalize (GObject *object)
 {
   GnomeDesktopThumbnailFactory *factory;
   GnomeDesktopThumbnailFactoryPrivate *priv;
-  
+
   factory = GNOME_DESKTOP_THUMBNAIL_FACTORY (object);
 
   priv = factory->priv;
@@ -451,11 +451,7 @@ gnome_desktop_thumbnail_factory_finalize (GObject *object)
       priv->monitors = NULL;
     }
 
-  if (priv->lock)
-    {
-      g_mutex_free (priv->lock);
-      priv->lock = NULL;
-    }
+  g_mutex_clear (&priv->lock);
 
   if (priv->disabled_types)
     {
@@ -540,7 +536,7 @@ update_or_create_thumbnailer (GnomeDesktopThumbnailFactory *factory,
   Thumbnailer *thumb;
   gboolean found = FALSE;
 
-  g_mutex_lock (priv->lock);
+  g_mutex_lock (&priv->lock);
 
   for (l = priv->thumbnailers; l && !found; l = g_list_next (l))
     {
@@ -568,7 +564,7 @@ update_or_create_thumbnailer (GnomeDesktopThumbnailFactory *factory,
         gnome_desktop_thumbnail_factory_add_thumbnailer (factory, thumb);
     }
 
-  g_mutex_unlock (priv->lock);
+  g_mutex_unlock (&priv->lock);
 }
 
 static void
@@ -579,7 +575,7 @@ remove_thumbnailer (GnomeDesktopThumbnailFactory *factory,
   GList *l;
   Thumbnailer *thumb;
 
-  g_mutex_lock (priv->lock);
+  g_mutex_lock (&priv->lock);
 
   for (l = priv->thumbnailers; l; l = g_list_next (l))
     {
@@ -597,7 +593,7 @@ remove_thumbnailer (GnomeDesktopThumbnailFactory *factory,
         }
     }
 
-  g_mutex_unlock (priv->lock);
+  g_mutex_unlock (&priv->lock);
 }
 
 static void
@@ -699,7 +695,7 @@ external_thumbnailers_disabled_all_changed_cb (GSettings                    *set
 {
   GnomeDesktopThumbnailFactoryPrivate *priv = factory->priv;
 
-  g_mutex_lock (priv->lock);
+  g_mutex_lock (&priv->lock);
 
   priv->disabled = g_settings_get_boolean (priv->settings, "disable-all");
   if (priv->disabled)
@@ -713,7 +709,7 @@ external_thumbnailers_disabled_all_changed_cb (GSettings                    *set
       gnome_desktop_thumbnail_factory_load_thumbnailers (factory);
     }
 
-  g_mutex_unlock (priv->lock);
+  g_mutex_unlock (&priv->lock);
 }
 
 static void
@@ -723,33 +719,33 @@ external_thumbnailers_disabled_changed_cb (GSettings                    *setting
 {
   GnomeDesktopThumbnailFactoryPrivate *priv = factory->priv;
 
-  g_mutex_lock (priv->lock);
+  g_mutex_lock (&priv->lock);
 
   if (priv->disabled)
     return;
   g_strfreev (priv->disabled_types);
   priv->disabled_types = g_settings_get_strv (priv->settings, "disable");
 
-  g_mutex_unlock (priv->lock);
+  g_mutex_unlock (&priv->lock);
 }
 
 static void
 gnome_desktop_thumbnail_factory_init (GnomeDesktopThumbnailFactory *factory)
 {
   GnomeDesktopThumbnailFactoryPrivate *priv;
-  
+
   factory->priv = GNOME_DESKTOP_THUMBNAIL_FACTORY_GET_PRIVATE (factory);
 
   priv = factory->priv;
 
   priv->size = GNOME_DESKTOP_THUMBNAIL_SIZE_NORMAL;
-  
+
   priv->mime_types_map = g_hash_table_new_full (g_str_hash,
                                                 g_str_equal,
                                                 (GDestroyNotify)g_free,
                                                 (GDestroyNotify)thumbnailer_unref);
-  
-  priv->lock = g_mutex_new ();
+
+  g_mutex_init (&priv->lock);
 
   priv->settings = g_settings_new ("org.gnome.desktop.thumbnailers");
   priv->disabled = g_settings_get_boolean (priv->settings, "disable-all");
@@ -772,7 +768,7 @@ gnome_desktop_thumbnail_factory_class_init (GnomeDesktopThumbnailFactoryClass *c
   GObjectClass *gobject_class;
 
   gobject_class = G_OBJECT_CLASS (class);
-	
+
   gobject_class->finalize = gnome_desktop_thumbnail_factory_finalize;
 
   g_type_class_add_private (class, sizeof (GnomeDesktopThumbnailFactoryPrivate));
@@ -785,7 +781,7 @@ gnome_desktop_thumbnail_factory_class_init (GnomeDesktopThumbnailFactoryClass *c
  * Creates a new #GnomeDesktopThumbnailFactory.
  *
  * This function must be called on the main thread.
- * 
+ *
  * Return value: a new #GnomeDesktopThumbnailFactory
  *
  * Since: 2.2
@@ -794,11 +790,11 @@ GnomeDesktopThumbnailFactory *
 gnome_desktop_thumbnail_factory_new (GnomeDesktopThumbnailSize size)
 {
   GnomeDesktopThumbnailFactory *factory;
-  
+
   factory = g_object_new (GNOME_DESKTOP_TYPE_THUMBNAIL_FACTORY, NULL);
-  
+
   factory->priv->size = size;
-  
+
   return factory;
 }
 
@@ -840,7 +836,7 @@ gnome_desktop_thumbnail_factory_lookup (GnomeDesktopThumbnailFactory *factory,
   g_assert (digest_len == 16);
 
   file = g_strconcat (g_checksum_get_string (checksum), ".png", NULL);
-  
+
   path = g_build_filename (g_get_home_dir (),
 			   ".thumbnails",
 			   (priv->size == GNOME_DESKTOP_THUMBNAIL_SIZE_NORMAL)?"normal":"large",
@@ -951,7 +947,7 @@ mimetype_supported_by_gdk_pixbuf (const char *mime_type)
                         for (i = 0; mime_types[i] != NULL; i++)
                                 g_hash_table_insert (hash,
                                                      (gpointer) g_content_type_from_mime_type (mime_types[i]),
-                                                     GUINT_TO_POINTER (1));	
+                                                     GUINT_TO_POINTER (1));
 
                         g_strfreev (mime_types);
                         list = list->next;
@@ -1000,11 +996,11 @@ gnome_desktop_thumbnail_factory_can_thumbnail (GnomeDesktopThumbnailFactory *fac
       strncmp (uri, "file:/", 6) == 0 &&
       strstr (uri, "/.thumbnails/") != NULL)
     return FALSE;
-  
+
   if (!mime_type)
     return FALSE;
 
-  g_mutex_lock (factory->priv->lock);
+  g_mutex_lock (&factory->priv->lock);
   if (!gnome_desktop_thumbnail_factory_is_disabled (factory, mime_type))
     {
       Thumbnailer *thumb;
@@ -1012,7 +1008,7 @@ gnome_desktop_thumbnail_factory_can_thumbnail (GnomeDesktopThumbnailFactory *fac
       thumb = g_hash_table_lookup (factory->priv->mime_types_map, mime_type);
       have_script = thumbnailer_try_exec (thumb);
     }
-  g_mutex_unlock (factory->priv->lock);
+  g_mutex_unlock (&factory->priv->lock);
 
   if (have_script || mimetype_supported_by_gdk_pixbuf (mime_type))
     {
@@ -1020,13 +1016,13 @@ gnome_desktop_thumbnail_factory_can_thumbnail (GnomeDesktopThumbnailFactory *fac
                                                                           uri,
                                                                           mtime);
     }
-  
+
   return FALSE;
 }
 
 static char *
 expand_thumbnailing_script (const char *script,
-			    const int   size, 
+			    const int   size,
 			    const char *inuri,
 			    const char *outfile)
 {
@@ -1036,7 +1032,7 @@ expand_thumbnailing_script (const char *script,
   gboolean got_in;
 
   str = g_string_new (NULL);
-  
+
   got_in = FALSE;
   last = script;
   while ((p = strchr (last, '%')) != NULL)
@@ -1127,7 +1123,7 @@ gnome_desktop_thumbnail_factory_generate_thumbnail (GnomeDesktopThumbnailFactory
   g_return_val_if_fail (mime_type != NULL, NULL);
 
   /* Doesn't access any volatile fields in factory, so it's threadsafe */
-  
+
   size = 128;
   if (factory->priv->size == GNOME_DESKTOP_THUMBNAIL_SIZE_LARGE)
     size = 256;
@@ -1135,7 +1131,7 @@ gnome_desktop_thumbnail_factory_generate_thumbnail (GnomeDesktopThumbnailFactory
   pixbuf = NULL;
 
   script = NULL;
-  g_mutex_lock (factory->priv->lock);
+  g_mutex_lock (&factory->priv->lock);
   if (!gnome_desktop_thumbnail_factory_is_disabled (factory, mime_type))
     {
       Thumbnailer *thumb;
@@ -1144,8 +1140,8 @@ gnome_desktop_thumbnail_factory_generate_thumbnail (GnomeDesktopThumbnailFactory
       if (thumb)
         script = g_strdup (thumb->command);
     }
-  g_mutex_unlock (factory->priv->lock);
-  
+  g_mutex_unlock (&factory->priv->lock);
+
   if (script)
     {
       int fd;
@@ -1186,7 +1182,7 @@ gnome_desktop_thumbnail_factory_generate_thumbnail (GnomeDesktopThumbnailFactory
                                                                 "gnome-original-height"));
         }
     }
-      
+
   if (pixbuf == NULL)
     return NULL;
 
@@ -1199,7 +1195,7 @@ gnome_desktop_thumbnail_factory_generate_thumbnail (GnomeDesktopThumbnailFactory
 
   width = gdk_pixbuf_get_width (pixbuf);
   height = gdk_pixbuf_get_height (pixbuf);
-  
+
   if (width > size || height > size)
     {
       const gchar *orig_width, *orig_height;
@@ -1218,11 +1214,11 @@ gnome_desktop_thumbnail_factory_generate_thumbnail (GnomeDesktopThumbnailFactory
       if (orig_height != NULL) {
 	      gdk_pixbuf_set_option (scaled, "tEXt::Thumb::Image::Height", orig_height);
       }
-      
+
       g_object_unref (pixbuf);
       pixbuf = scaled;
     }
-  
+
   if (original_width > 0) {
 	  g_snprintf (dimension, sizeof (dimension), "%i", original_width);
 	  gdk_pixbuf_set_option (pixbuf, "tEXt::Thumb::Image::Width", dimension);
@@ -1264,7 +1260,7 @@ make_thumbnail_dirs (GnomeDesktopThumbnailFactory *factory)
 
   g_free (thumbnail_dir);
   g_free (image_dir);
-  
+
   return res;
 }
 
@@ -1308,7 +1304,7 @@ make_thumbnail_fail_dirs (GnomeDesktopThumbnailFactory *factory)
   g_free (thumbnail_dir);
   g_free (fail_dir);
   g_free (app_dir);
-  
+
   return res;
 }
 
@@ -1316,9 +1312,9 @@ make_thumbnail_fail_dirs (GnomeDesktopThumbnailFactory *factory)
 /**
  * gnome_desktop_thumbnail_factory_save_thumbnail:
  * @factory: a #GnomeDesktopThumbnailFactory
- * @thumbnail: the thumbnail as a pixbuf 
+ * @thumbnail: the thumbnail as a pixbuf
  * @uri: the uri of a file
- * @original_mtime: the modification time of the original file 
+ * @original_mtime: the modification time of the original file
  *
  * Saves @thumbnail at the right place. If the save fails a
  * failed thumbnail is written.
@@ -1381,12 +1377,12 @@ gnome_desktop_thumbnail_factory_save_thumbnail (GnomeDesktopThumbnailFactory *fa
       return;
     }
   close (tmp_fd);
-  
+
   g_snprintf (mtime_str, 21, "%ld",  original_mtime);
   width = gdk_pixbuf_get_option (thumbnail, "tEXt::Thumb::Image::Width");
   height = gdk_pixbuf_get_option (thumbnail, "tEXt::Thumb::Image::Height");
 
-  if (width != NULL && height != NULL) 
+  if (width != NULL && height != NULL)
     saved_ok  = gdk_pixbuf_save (thumbnail,
 				 tmp_path,
 				 "png", NULL,
@@ -1404,7 +1400,7 @@ gnome_desktop_thumbnail_factory_save_thumbnail (GnomeDesktopThumbnailFactory *fa
 				 "tEXt::Thumb::MTime", mtime_str,
 				 "tEXt::Software", "GNOME::ThumbnailFactory",
 				 NULL);
-    
+
 
   if (saved_ok)
     {
@@ -1483,12 +1479,12 @@ gnome_desktop_thumbnail_factory_create_failed_thumbnail (GnomeDesktopThumbnailFa
       return;
     }
   close (tmp_fd);
-  
+
   g_snprintf (mtime_str, 21, "%ld",  mtime);
   pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, TRUE, 8, 1, 1);
   saved_ok  = gdk_pixbuf_save (pixbuf,
 			       tmp_path,
-			       "png", NULL, 
+			       "png", NULL,
 			       "tEXt::Thumb::URI", uri,
 			       "tEXt::Thumb::MTime", mtime_str,
 			       "tEXt::Software", "GNOME::ThumbnailFactory",
@@ -1546,13 +1542,13 @@ gnome_desktop_thumbnail_path_for_uri (const char         *uri,
   md5 = gnome_desktop_thumbnail_md5 (uri);
   file = g_strconcat (md5, ".png", NULL);
   g_free (md5);
-  
+
   path = g_build_filename (g_get_home_dir (),
 			   ".thumbnails",
 			   (size == GNOME_DESKTOP_THUMBNAIL_SIZE_NORMAL)?"normal":"large",
 			   file,
 			   NULL);
-    
+
   g_free (file);
 
   return path;
@@ -1575,7 +1571,7 @@ gnome_desktop_thumbnail_has_uri (GdkPixbuf          *pixbuf,
 				 const char         *uri)
 {
   const char *thumb_uri;
-  
+
   thumb_uri = gdk_pixbuf_get_option (pixbuf, "tEXt::Thumb::URI");
   if (!thumb_uri)
     return FALSE;
@@ -1603,19 +1599,19 @@ gnome_desktop_thumbnail_is_valid (GdkPixbuf          *pixbuf,
 {
   const char *thumb_uri, *thumb_mtime_str;
   time_t thumb_mtime;
-  
+
   thumb_uri = gdk_pixbuf_get_option (pixbuf, "tEXt::Thumb::URI");
   if (!thumb_uri)
     return FALSE;
   if (strcmp (uri, thumb_uri) != 0)
     return FALSE;
-  
+
   thumb_mtime_str = gdk_pixbuf_get_option (pixbuf, "tEXt::Thumb::MTime");
   if (!thumb_mtime_str)
     return FALSE;
   thumb_mtime = atol (thumb_mtime_str);
   if (mtime != thumb_mtime)
     return FALSE;
-  
+
   return TRUE;
 }
diff --git a/src/goo-player.c b/src/goo-player.c
index 23d03fd..2f6a266 100644
--- a/src/goo-player.c
+++ b/src/goo-player.c
@@ -66,7 +66,7 @@ struct _GooPlayerPrivate {
 	guint            update_state_id;
 	guint            update_progress_id;
 
-	GMutex          *yes_or_no;
+	GMutex           data_mutex;
 	gboolean         exiting;
 	GCancellable    *cancellable;
 	GList           *albums;
@@ -336,7 +336,7 @@ goo_player_init (GooPlayer *self)
 	self->priv->action = GOO_PLAYER_ACTION_NONE;
 	self->priv->is_busy = FALSE;
 	self->priv->hibernate = FALSE;
-	self->priv->yes_or_no = g_mutex_new ();
+	g_mutex_init (&self->priv->data_mutex);
 	self->priv->exiting = FALSE,
 	self->priv->discid = NULL;
 	self->priv->album = album_info_new ();
@@ -358,9 +358,9 @@ goo_player_finalize (GObject *object)
 
 	self = GOO_PLAYER (object);
 
-	g_mutex_lock (self->priv->yes_or_no);
+	g_mutex_lock (&self->priv->data_mutex);
 	self->priv->exiting = TRUE;
-        g_mutex_unlock (self->priv->yes_or_no);
+        g_mutex_unlock (&self->priv->data_mutex);
 
         brasero_drive_unlock (self->priv->drive);
         if (self->priv->medium_added_event != 0)
@@ -375,7 +375,7 @@ goo_player_finalize (GObject *object)
 	}
 
 	destroy_pipeline (self, FALSE);
-	g_mutex_free (self->priv->yes_or_no);
+	g_mutex_clear (&self->priv->data_mutex);
 	destroy_pipeline (self, FALSE);
 	g_free (self->priv->discid);
 	album_info_unref (self->priv->album);



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]