[evolution/webkit: 138/182] Use a single mutex located in EMPartClass



commit be650bb0bc0195e63ac22bb29302dfc24231ca02
Author: Dan VrÃtil <dvratil redhat com>
Date:   Wed Feb 8 12:33:49 2012 +0100

    Use a single mutex located in EMPartClass

 em-format/em-part.c                  |  136 ++++++++++++++++++++-------------
 em-format/em-part.h                  |    8 ++-
 mail/em-format-html-display-parts.c  |  133 +++++++++++++++------------------
 plugins/audio-inline/em-part-audio.c |   70 ++++++++---------
 plugins/audio-inline/em-part-audio.h |    3 +-
 5 files changed, 182 insertions(+), 168 deletions(-)
---
diff --git a/em-format/em-part.c b/em-format/em-part.c
index 26c4c4b..c2ede26 100644
--- a/em-format/em-part.c
+++ b/em-format/em-part.c
@@ -41,8 +41,6 @@ struct _EMPartPrivate {
 	CamelCipherValidity *validity_parent;
 
 	gboolean is_attachment;
-
-	GMutex *mutex;
 };
 
 static void
@@ -50,7 +48,7 @@ em_part_finalize (GObject *object)
 {
 	EMPartPrivate *priv = EM_PART (object)->priv;
 
-	g_mutex_lock (priv->mutex);
+	em_part_mutex_lock (EM_PART (object));
 
 	if (priv->cid) {
 		g_free (priv->cid);
@@ -87,8 +85,21 @@ em_part_finalize (GObject *object)
 		priv->validity_parent = NULL;
 	}
 
-	g_mutex_unlock (priv->mutex);
-	g_mutex_free (priv->mutex);
+	em_part_mutex_unlock (EM_PART (object));
+}
+
+static void
+em_part_dispose (GObject *object)
+{
+	EMPartClass *klass;
+
+	klass = EM_PART_GET_CLASS (EM_PART (object));
+
+	/* Make sure the mutex is unlocked */
+	g_mutex_lock (klass->mutex);
+	g_mutex_unlock (klass->mutex);
+
+	g_mutex_free (klass->mutex);
 }
 
 static void
@@ -96,9 +107,12 @@ em_part_class_init (EMPartClass *klass)
 {
 	GObjectClass *object_class;
 
+	klass->mutex = g_mutex_new ();
+
 	g_type_class_add_private (klass, sizeof (EMPartPrivate));
 
 	object_class = G_OBJECT_CLASS (klass);
+	object_class->dispose = em_part_dispose;
 	object_class->finalize = em_part_finalize;
 
 }
@@ -109,7 +123,6 @@ em_part_init (EMPart *emp)
 	emp->priv = G_TYPE_INSTANCE_GET_PRIVATE (emp,
 			EM_TYPE_PART, EMPartPrivate);
 
-	emp->priv->mutex = g_mutex_new ();
 	emp->priv->cid = NULL;
 	emp->priv->formatter = NULL;
 	emp->priv->is_attachment = FALSE;
@@ -166,7 +179,7 @@ em_part_set_formatter (EMPart *emp,
 	g_return_if_fail (EM_IS_PART (emp));
 	g_return_if_fail (EM_IS_FORMAT (emf));
 
-	g_mutex_lock (emp->priv->mutex);
+	em_part_mutex_lock (emp);
 
 	g_object_ref (emf);
 
@@ -175,7 +188,7 @@ em_part_set_formatter (EMPart *emp,
 
 	emp->priv->formatter = emf;
 
-	g_mutex_unlock (emp->priv->mutex);
+	em_part_mutex_unlock (emp);
 }
 
 /**
@@ -192,12 +205,12 @@ em_part_get_formatter (EMPart *emp)
 
 	g_return_val_if_fail (EM_IS_PART (emp), NULL);
 
-	g_mutex_lock (emp->priv->mutex);
+	em_part_mutex_lock (emp);
 
 	if (emp->priv->formatter)
 		formatter = g_object_ref (emp->priv->formatter);
 
-	g_mutex_unlock (emp->priv->mutex);
+	em_part_mutex_unlock (emp);
 
 	return formatter;
 }
@@ -216,7 +229,7 @@ em_part_set_mime_part (EMPart *emp,
 	g_return_if_fail (EM_IS_PART (emp));
 	g_return_if_fail ((part == NULL) || CAMEL_IS_MIME_PART (part));
 
-	g_mutex_lock (emp->priv->mutex);
+	em_part_mutex_lock (emp);
 
 	if (part)
 		g_object_ref (part);
@@ -226,7 +239,7 @@ em_part_set_mime_part (EMPart *emp,
 
 	emp->priv->part = part;
 
-	g_mutex_unlock (emp->priv->mutex);
+	em_part_mutex_unlock (emp);
 }
 
 /**
@@ -243,12 +256,12 @@ em_part_get_mime_part (EMPart *emp)
 
 	g_return_val_if_fail (EM_IS_PART (emp), NULL);
 
-	g_mutex_lock (emp->priv->mutex);
+	em_part_mutex_lock (emp);
 
 	if (emp->priv->part)
 		part = g_object_ref (emp->priv->part);
 
-	g_mutex_unlock (emp->priv->mutex);
+	em_part_mutex_unlock (emp);
 
 	return part;
 }
@@ -265,9 +278,9 @@ em_part_set_write_func (EMPart *emp,
 {
 	g_return_if_fail (EM_IS_PART (emp));
 
-	g_mutex_lock (emp->priv->mutex);
+	em_part_mutex_lock (emp);
 	emp->priv->write_func = write_func;
-	g_mutex_unlock (emp->priv->mutex);
+	em_part_mutex_unlock (emp);
 }
 
 EMPartWriteFunc
@@ -277,9 +290,9 @@ em_part_get_write_func (EMPart *emp)
 
 	g_return_val_if_fail (EM_IS_PART (emp), NULL);
 
-	g_mutex_lock (emp->priv->mutex);
+	em_part_mutex_lock (emp);
 	write_func = emp->priv->write_func;
-	g_mutex_unlock (emp->priv->mutex);
+	em_part_mutex_unlock (emp);
 
 	return write_func;
 }
@@ -296,9 +309,9 @@ em_part_set_widget_func (EMPart *emp,
 {
 	g_return_if_fail (EM_IS_PART (emp));
 
-	g_mutex_lock (emp->priv->mutex);
+	em_part_mutex_lock (emp);
 	emp->priv->widget_func = widget_func;
-	g_mutex_unlock (emp->priv->mutex);
+	em_part_mutex_unlock (emp);
 }
 
 EMPartWidgetFunc
@@ -308,9 +321,9 @@ em_part_get_widget_func (EMPart *emp)
 
 	g_return_val_if_fail (EM_IS_PART (emp), NULL);
 
-	g_mutex_lock (emp->priv->mutex);
+	em_part_mutex_lock (emp);
 	widget_func = emp->priv->widget_func;
-	g_mutex_unlock (emp->priv->mutex);
+	em_part_mutex_unlock (emp);
 
 	return widget_func;
 }
@@ -322,14 +335,14 @@ em_part_set_uri (EMPart *emp,
 	g_return_if_fail (EM_IS_PART (emp));
 	g_return_if_fail (uri && *uri);
 
-	g_mutex_lock (emp->priv->mutex);
+	em_part_mutex_lock (emp);
 
 	if (emp->priv->uri)
 		g_free (emp->priv->uri);
 
 	emp->priv->uri = g_strdup (uri);
 
-	g_mutex_unlock (emp->priv->mutex);
+	em_part_mutex_unlock (emp);
 }
 
 gchar *
@@ -339,12 +352,12 @@ em_part_get_uri (EMPart *emp)
 
 	g_return_val_if_fail (EM_IS_PART (emp), NULL);
 
-	g_mutex_lock (emp->priv->mutex);
+	em_part_mutex_lock (emp);
 
 	if (emp->priv->uri)
 		uri = g_strdup (emp->priv->uri);
 
-	g_mutex_unlock (emp->priv->mutex);
+	em_part_mutex_unlock (emp);
 
 	return uri;
 }
@@ -361,7 +374,7 @@ em_part_set_cid (EMPart *emp,
 {
 	g_return_if_fail (EM_IS_PART (emp));
 
-	g_mutex_lock (emp->priv->mutex);
+	em_part_mutex_lock (emp);
 
 	if (emp->priv->cid)
 		g_free (emp->priv->cid);
@@ -371,7 +384,7 @@ em_part_set_cid (EMPart *emp,
 	else
 		emp->priv->cid = NULL;
 
-	g_mutex_unlock (emp->priv->mutex);
+	em_part_mutex_unlock (emp);
 }
 
 gchar *
@@ -381,12 +394,12 @@ em_part_get_cid (EMPart *emp)
 
 	g_return_val_if_fail (EM_IS_PART (emp), NULL);
 
-	g_mutex_lock (emp->priv->mutex);
+	em_part_mutex_lock (emp);
 
 	if (cid)
 		cid = g_strdup (emp->priv->cid);
 
-	g_mutex_unlock (emp->priv->mutex);
+	em_part_mutex_unlock (emp);
 
 	return cid;
 }
@@ -398,14 +411,14 @@ em_part_set_mime_type (EMPart *emp,
 	g_return_if_fail (EM_IS_PART (emp));
 	g_return_if_fail (mime_type && *mime_type);
 
-	g_mutex_lock (emp->priv->mutex);
+	em_part_mutex_lock (emp);
 
 	if (emp->priv->mime_type)
 		g_free (emp->priv->mime_type);
 
 	emp->priv->mime_type = g_strdup (mime_type);
 
-	g_mutex_unlock (emp->priv->mutex);
+	em_part_mutex_unlock (emp);
 }
 
 gchar *
@@ -415,12 +428,12 @@ em_part_get_mime_type (EMPart *emp)
 
 	g_return_val_if_fail (EM_IS_PART (emp), NULL);
 
-	g_mutex_lock (emp->priv->mutex);
+	em_part_mutex_lock (emp);
 
 	if (mime_type)
 		mime_type = g_strdup (emp->priv->mime_type);
 
-	g_mutex_unlock (emp->priv->mutex);
+	em_part_mutex_unlock (emp);
 
 	return mime_type;
 }
@@ -433,9 +446,9 @@ em_part_set_validity_type (EMPart *emp,
 {
 	g_return_if_fail (EM_IS_PART (emp));
 
-	g_mutex_lock (emp->priv->mutex);
+	em_part_mutex_lock (emp);
 	emp->priv->validity_type = validity_type;
-	g_mutex_unlock (emp->priv->mutex);
+	em_part_mutex_unlock (emp);
 }
 
 guint32
@@ -445,9 +458,9 @@ em_part_get_validity_type (EMPart *emp)
 
 	g_return_val_if_fail (EM_IS_PART (emp), 0);
 
-	g_mutex_lock (emp->priv->mutex);
+	em_part_mutex_lock (emp);
 	validity_type = emp->priv->validity_type;
-	g_mutex_unlock (emp->priv->mutex);
+	em_part_mutex_unlock (emp);
 
 	return validity_type;
 }
@@ -464,7 +477,7 @@ em_part_set_validity (EMPart *emp,
 {
 	g_return_if_fail (EM_IS_PART (emp));
 
-	g_mutex_lock (emp->priv->mutex);
+	em_part_mutex_lock (emp);
 
 	if (emp->priv->validity)
 		camel_cipher_validity_free (emp->priv->validity);
@@ -474,7 +487,7 @@ em_part_set_validity (EMPart *emp,
 	else
 		emp->priv->validity = NULL;
 
-	g_mutex_unlock (emp->priv->mutex);
+	em_part_mutex_unlock (emp);
 }
 
 /**
@@ -491,12 +504,12 @@ em_part_get_validity (EMPart *emp)
 
 	g_return_val_if_fail (EM_IS_PART (emp), NULL);
 
-	g_mutex_lock (emp->priv->mutex);
+	em_part_mutex_lock (emp);
 
 	if (emp->priv->validity)
 		validity = camel_cipher_validity_clone (emp->priv->validity);
 
-	g_mutex_unlock (emp->priv->mutex);
+	em_part_mutex_unlock (emp);
 
 	return validity;
 }
@@ -513,7 +526,7 @@ em_part_set_validity_parent (EMPart *emp,
 {
 	g_return_if_fail (EM_IS_PART (emp));
 
-	g_mutex_lock (emp->priv->mutex);
+	em_part_mutex_lock (emp);
 
 	if (emp->priv->validity_parent)
 		camel_cipher_validity_free (emp->priv->validity_parent);
@@ -523,7 +536,7 @@ em_part_set_validity_parent (EMPart *emp,
 	else
 		emp->priv->validity_parent = NULL;
 
-	g_mutex_unlock (emp->priv->mutex);
+	em_part_mutex_unlock (emp);
 }
 
 /**
@@ -540,12 +553,12 @@ em_part_get_validity_parent (EMPart *emp)
 
 	g_return_val_if_fail (EM_IS_PART (emp), NULL);
 
-	g_mutex_lock (emp->priv->mutex);
+	em_part_mutex_lock (emp);
 
 	if (emp->priv->validity_parent)
 		validity = camel_cipher_validity_clone (emp->priv->validity_parent);
 
-	g_mutex_unlock (emp->priv->mutex);
+	em_part_mutex_unlock (emp);
 
 	return validity;
 }
@@ -556,9 +569,9 @@ em_part_set_is_attachment (EMPart *emp,
 {
 	g_return_if_fail (EM_IS_PART (emp));
 
-	g_mutex_lock (emp->priv->mutex);
+	em_part_mutex_lock (emp);
 	emp->priv->is_attachment = is_attachment;
-	g_mutex_unlock (emp->priv->mutex);
+	em_part_mutex_unlock (emp);
 }
 
 gboolean
@@ -568,9 +581,9 @@ em_part_get_is_attachment (EMPart *emp)
 
 	g_return_val_if_fail (EM_IS_PART (emp), FALSE);
 
-	g_mutex_lock (emp->priv->mutex);
+	em_part_mutex_lock (emp);
 	is_attachment = emp->priv->is_attachment;
-	g_mutex_unlock (emp->priv->mutex);
+	em_part_mutex_unlock (emp);
 
 	return is_attachment;
 }
@@ -596,10 +609,10 @@ em_part_get_widget (EMPart *emp,
 
 	g_return_val_if_fail (EM_IS_PART (emp), NULL);
 
-	g_mutex_lock (emp->priv->mutex);
+	em_part_mutex_lock (emp);
 	widget_func = emp->priv->widget_func;
 	formatter = g_object_ref (emp->priv->formatter);
-	g_mutex_unlock (emp->priv->mutex);
+	em_part_mutex_unlock (emp);
 
 	if (!widget_func)
 		return NULL;
@@ -635,14 +648,14 @@ em_part_write (EMPart *emp,
 	g_return_if_fail (EM_IS_PART (emp));
 	g_return_if_fail (CAMEL_IS_STREAM (stream));
 
-	g_mutex_lock (emp->priv->mutex);
+	em_part_mutex_lock (emp);
 	write_func = emp->priv->write_func;
 	formatter = g_object_ref (emp->priv->formatter);
 
 	if (emp->priv->mime_type)
 		mime_type = g_strdup (emp->priv->mime_type);
 
-	g_mutex_unlock (emp->priv->mutex);
+	em_part_mutex_unlock (emp);
 
 	g_object_ref (emp);
 
@@ -676,3 +689,18 @@ em_part_write (EMPart *emp,
 	if (mime_type)
 		g_free (mime_type);
 }
+
+void
+em_part_mutex_lock (EMPart *emp)
+{
+        g_return_if_fail (EM_IS_PART (emp));
+
+        g_mutex_lock (EM_PART_GET_CLASS (emp)->mutex);
+}
+
+void em_part_mutex_unlock (EMPart *emp)
+{
+        g_return_if_fail (EM_IS_PART (emp));
+
+        g_mutex_unlock (EM_PART_GET_CLASS (emp)->mutex);
+}
diff --git a/em-format/em-part.h b/em-format/em-part.h
index 2b20be5..1dcf527 100644
--- a/em-format/em-part.h
+++ b/em-format/em-part.h
@@ -20,7 +20,7 @@
 #include <camel/camel.h>
 #include <glib-object.h>
 
-#include <em-format.h>
+#include <em-format/em-format.h>
 
 /* Standard GObject macros */
 #define EM_TYPE_PART \
@@ -66,6 +66,7 @@ struct _EMPart {
 struct _EMPartClass {
         GObjectClass parent_class;
 
+        GMutex *mutex;
 };
 
 EMPart*			em_part_new      	(EMFormat *emf,
@@ -135,6 +136,11 @@ void                    em_part_write		(EMPart *emp,
                                                  EMFormatWriterInfo *info,
                                                  GCancellable *cancellable);
 
+void                    em_part_mutex_lock	(EMPart *emp);
+
+void                    em_part_mutex_unlock    (EMPart *emp);
+
+
 G_END_DECLS
 
 #endif /* EM_PART_H */
\ No newline at end of file
diff --git a/mail/em-format-html-display-parts.c b/mail/em-format-html-display-parts.c
index d7c7965..9c24650 100644
--- a/mail/em-format-html-display-parts.c
+++ b/mail/em-format-html-display-parts.c
@@ -20,8 +20,6 @@
 
 struct _EMPartAttachmentBarPrivate {
 	EAttachmentStore *store;
-	
-	GMutex *mutex;
 };
 
 G_DEFINE_TYPE (EMPartAttachmentBar, em_part_attachment_bar, EM_TYPE_PART);
@@ -32,15 +30,14 @@ em_part_attachment_bar_finalize (GObject *object)
 	EMPartAttachmentBarPrivate *priv =
 		EM_PART_ATTACHMENT_BAR (object)->priv;
 
-	g_mutex_lock (priv->mutex);
+	em_part_mutex_lock (EM_PART (object));
 
 	if (priv->store) {
 		g_object_unref (priv->store);
 		priv->store = NULL;
 	}
 
-	g_mutex_unlock (priv->mutex);
-	g_mutex_free (priv->mutex);
+	em_part_mutex_unlock (EM_PART (object));
 }
 
 static void
@@ -63,8 +60,6 @@ em_part_attachment_bar_init (EMPartAttachmentBar *empab)
 			EM_TYPE_PART_ATTACHMENT_BAR, EMPartAttachmentBarPrivate);
 
 	empab->priv->store = NULL;
-
-	empab->priv->mutex = g_mutex_new ();
 }
 
 EMPart*
@@ -95,7 +90,7 @@ em_part_attachment_bar_set_store (EMPartAttachmentBar *empab,
 	g_return_if_fail (EM_IS_PART_ATTACHMENT_BAR (empab));
 	g_return_if_fail ((store == NULL) || E_IS_ATTACHMENT_STORE (store));
 
-	g_mutex_lock (empab->priv->mutex);
+	em_part_mutex_lock ((EMPart *) empab);
 
 	if (store)
 		g_object_ref (store);
@@ -105,7 +100,7 @@ em_part_attachment_bar_set_store (EMPartAttachmentBar *empab,
 
 	empab->priv->store = store;
 
-	g_mutex_unlock (empab->priv->mutex);
+	em_part_mutex_unlock ((EMPart *) empab);
 }
 
 
@@ -116,10 +111,10 @@ em_part_attachment_bar_get_store (EMPartAttachmentBar *empab)
 
 	g_return_val_if_fail (EM_IS_PART_ATTACHMENT_BAR (empab), NULL);
 
-	g_mutex_lock (empab->priv->mutex);
+	em_part_mutex_lock ((EMPart *) empab);
 	if (empab->priv->store)
 		store = g_object_ref (empab->priv->store);
-	g_mutex_unlock (empab->priv->mutex);
+	em_part_mutex_unlock ((EMPart *) empab);
 
 	return store;
 }
@@ -142,8 +137,6 @@ struct _EMPartAttachmentPrivate {
 	CamelStream *mstream;
 
 	const EMFormatHandler *handler;
-
-	GMutex *mutex;
 };
 
 G_DEFINE_TYPE (EMPartAttachment, em_part_attachment, EM_TYPE_PART);
@@ -153,7 +146,7 @@ em_part_attachment_finalize (GObject *object)
 {
 	EMPartAttachmentPrivate *priv = EM_PART_ATTACHMENT (object)->priv;
 
-	g_mutex_lock (priv->mutex);
+	em_part_mutex_lock (EM_PART (object));
 
 	if (priv->attachment) {
 		g_object_unref (priv->attachment);
@@ -190,8 +183,7 @@ em_part_attachment_finalize (GObject *object)
 		priv->view_part_id = NULL;
 	}
 
-	g_mutex_unlock (priv->mutex);
-	g_mutex_free (priv->mutex);
+	em_part_mutex_unlock (EM_PART (object));
 }
 
 static void
@@ -220,8 +212,6 @@ em_part_attachment_init (EMPartAttachment *empa)
 	empa->priv->snoop_mime_type = NULL;
 	empa->priv->view_part_id = NULL;
 	empa->priv->handler = NULL;
-	
-	empa->priv->mutex = g_mutex_new ();	
 }
 
 EMPart*
@@ -251,7 +241,7 @@ em_part_attachment_set_snoop_mime_type (EMPartAttachment *empa,
 {
 	g_return_if_fail (EM_IS_PART_ATTACHMENT (empa));
 
-	g_mutex_lock (empa->priv->mutex);
+	em_part_mutex_lock ((EMPart *) empa);
 
 	if (empa->priv->snoop_mime_type)
 		g_free (empa->priv->snoop_mime_type);
@@ -261,7 +251,7 @@ em_part_attachment_set_snoop_mime_type (EMPartAttachment *empa,
 	else
 		empa->priv->snoop_mime_type = NULL;
 
-	g_mutex_unlock (empa->priv->mutex);
+	em_part_mutex_unlock ((EMPart *) empa);
 }
 
 gchar*
@@ -271,10 +261,10 @@ em_part_attachment_get_snoop_mime_part (EMPartAttachment *empa)
 
 	g_return_val_if_fail (EM_IS_PART_ATTACHMENT (empa), NULL);
 
-	g_mutex_lock (empa->priv->mutex);
+	em_part_mutex_lock ((EMPart *) empa);
 	if (empa->priv->snoop_mime_type)
 		mime_type = g_strdup (empa->priv->snoop_mime_type);
-	g_mutex_unlock (empa->priv->mutex);
+	em_part_mutex_unlock ((EMPart *) empa);
 
 	return mime_type;
 }
@@ -286,7 +276,7 @@ em_part_attachment_set_forward_widget (EMPartAttachment *empa,
 	g_return_if_fail (EM_IS_PART_ATTACHMENT (empa));
 	g_return_if_fail ((forward == NULL) || GTK_IS_WIDGET (forward));
 
-	g_mutex_lock (empa->priv->mutex);
+	em_part_mutex_lock ((EMPart *) empa);
 	
 	if (forward)
 		g_object_ref (forward);
@@ -299,7 +289,7 @@ em_part_attachment_set_forward_widget (EMPartAttachment *empa,
 	else
 		empa->priv->forward = NULL;
 
-	g_mutex_unlock (empa->priv->mutex);
+	em_part_mutex_unlock ((EMPart *) empa);
 }
 
 GtkWidget*
@@ -309,10 +299,10 @@ em_part_attachment_get_forward_widget (EMPartAttachment *empa)
 
 	g_return_val_if_fail (EM_IS_PART_ATTACHMENT (empa), NULL);
 
-	g_mutex_lock (empa->priv->mutex);
+	em_part_mutex_lock ((EMPart *) empa);
 	if (empa->priv->down)
 		widget = g_object_ref (empa->priv->down);
-	g_mutex_unlock (empa->priv->mutex);
+	em_part_mutex_unlock ((EMPart *) empa);
 
 	return widget;
 }
@@ -325,7 +315,7 @@ em_part_attachment_set_down_widget (EMPartAttachment *empa,
 	g_return_if_fail (EM_IS_PART_ATTACHMENT (empa));
 	g_return_if_fail ((down == NULL) || GTK_IS_WIDGET (down));
 
-	g_mutex_lock (empa->priv->mutex);
+	em_part_mutex_lock ((EMPart *) empa);
 
 	if (down)
 		g_object_ref (down);
@@ -338,7 +328,7 @@ em_part_attachment_set_down_widget (EMPartAttachment *empa,
 	else
 		empa->priv->down = NULL;
 
-	g_mutex_unlock (empa->priv->mutex);
+	em_part_mutex_unlock ((EMPart *) empa);
 }
 
 GtkWidget*
@@ -348,10 +338,10 @@ em_part_attachment_get_down_widget (EMPartAttachment *empa)
 
 	g_return_val_if_fail (EM_IS_PART_ATTACHMENT (empa), NULL);
 
-	g_mutex_lock (empa->priv->mutex);
+	em_part_mutex_lock ((EMPart *) empa);
 	if (empa->priv->down)
 		widget = g_object_ref (empa->priv->down);
-	g_mutex_unlock (empa->priv->mutex);
+	em_part_mutex_unlock ((EMPart *) empa);
 
 	return widget;
 }
@@ -362,9 +352,9 @@ em_part_attachment_set_is_shown (EMPartAttachment *empa,
 {
 	g_return_if_fail (EM_IS_PART_ATTACHMENT (empa));
 
-	g_mutex_lock (empa->priv->mutex);
+	em_part_mutex_lock ((EMPart *) empa);
 	empa->priv->shown = is_shown;
-	g_mutex_unlock (empa->priv->mutex);
+	em_part_mutex_unlock ((EMPart *) empa);
 }
 
 gboolean
@@ -374,9 +364,9 @@ em_part_attachment_get_is_shown (EMPartAttachment *empa)
 
 	g_return_val_if_fail (EM_IS_PART_ATTACHMENT (empa), FALSE);
 
-	g_mutex_lock (empa->priv->mutex);
+	em_part_mutex_lock ((EMPart *) empa);
 	is_shown = empa->priv->shown;
-	g_mutex_unlock (empa->priv->mutex);
+	em_part_mutex_unlock ((EMPart *) empa);
 
 	return is_shown;
 }
@@ -391,7 +381,7 @@ em_part_attachment_set_attachment (EMPartAttachment *empa,
 	if (attachment)
 		g_object_ref (attachment);
 
-	g_mutex_lock (empa->priv->mutex);
+	em_part_mutex_lock ((EMPart *) empa);
 
 	if (empa->priv->attachment)
 		g_object_unref (empa->priv->attachment);
@@ -401,7 +391,7 @@ em_part_attachment_set_attachment (EMPartAttachment *empa,
 	else
 		empa->priv->attachment = NULL;
 
-	g_mutex_unlock (empa->priv->mutex);
+	em_part_mutex_unlock ((EMPart *) empa);
 }
 
 EAttachment*
@@ -411,10 +401,10 @@ em_part_attachment_get_attachment (EMPartAttachment *empa)
 
 	g_return_val_if_fail (EM_IS_PART_ATTACHMENT (empa), NULL);
 
-	g_mutex_lock (empa->priv->mutex);
-	if (empa->priv->mutex)
+	em_part_mutex_lock ((EMPart *) empa);
+	if (empa->priv->attachment)
 		attachment = g_object_ref (empa->priv->attachment);
-	g_mutex_unlock (empa->priv->mutex);
+	em_part_mutex_unlock ((EMPart *) empa);
 
 	return attachment;
 }
@@ -425,7 +415,7 @@ em_part_attachment_set_view_part_id (EMPartAttachment *empa,
 {
 	g_return_if_fail (EM_IS_PART_ATTACHMENT (empa));
 
-	g_mutex_lock (empa->priv->mutex);
+	em_part_mutex_lock ((EMPart *) empa);
 
 	if (empa->priv->view_part_id)
 		g_free (empa->priv->view_part_id);
@@ -435,7 +425,7 @@ em_part_attachment_set_view_part_id (EMPartAttachment *empa,
 	else
 		empa->priv->view_part_id = NULL;
 
-	g_mutex_unlock (empa->priv->mutex);
+	em_part_mutex_unlock ((EMPart *) empa);
 }
 
 gchar*
@@ -445,10 +435,10 @@ em_part_attachment_get_view_part_id (EMPartAttachment *empa)
 
 	g_return_val_if_fail (EM_IS_PART_ATTACHMENT (empa), NULL);
 	
-	g_mutex_lock (empa->priv->mutex);
+	em_part_mutex_lock ((EMPart *) empa);
 	if (empa->priv->view_part_id)
 		view_part_id = g_strdup (view_part_id);
-	g_mutex_unlock (empa->priv->mutex);
+	em_part_mutex_unlock ((EMPart *) empa);
 
 	return view_part_id;	
 }
@@ -459,7 +449,7 @@ em_part_attachment_set_description (EMPartAttachment *empa,
 {
 	g_return_if_fail (EM_IS_PART_ATTACHMENT (empa));
 
-	g_mutex_lock (empa->priv->mutex);
+	em_part_mutex_lock ((EMPart *) empa);
 
 	if (empa->priv->description)
 		g_free (empa->priv->description);
@@ -469,7 +459,7 @@ em_part_attachment_set_description (EMPartAttachment *empa,
 	else
 		empa->priv->description = NULL;
 
-	g_mutex_unlock (empa->priv->mutex);
+	em_part_mutex_unlock ((EMPart *) empa);
 }
 
 gchar*
@@ -479,10 +469,10 @@ em_part_attachment_get_description (EMPartAttachment *empa)
 
 	g_return_val_if_fail (EM_IS_PART_ATTACHMENT (empa), NULL);
 
-	g_mutex_lock (empa->priv->mutex);
+	em_part_mutex_lock ((EMPart *) empa);
 	if (empa->priv->description)
 		description = g_strdup (empa->priv->description);
-	g_mutex_unlock (empa->priv->mutex);
+	em_part_mutex_unlock ((EMPart *) empa);
 
 	return description;
 }
@@ -494,7 +484,7 @@ em_part_attachment_set_mstream (EMPartAttachment *empa,
 	g_return_if_fail (EM_IS_PART_ATTACHMENT (empa));
 	g_return_if_fail ((mstream == NULL) || CAMEL_IS_STREAM (mstream));
 
-	g_mutex_lock (empa->priv->mutex);
+	em_part_mutex_lock ((EMPart *) empa);
 	if (mstream)
 		g_object_ref (mstream);
 
@@ -503,7 +493,7 @@ em_part_attachment_set_mstream (EMPartAttachment *empa,
 
 	empa->priv->mstream = mstream;
 		
-	g_mutex_unlock (empa->priv->mutex);
+	em_part_mutex_unlock ((EMPart *) empa);
 }
 
 CamelStream*
@@ -513,10 +503,10 @@ em_part_attachment_get_mstream (EMPartAttachment *empa)
 
 	g_return_val_if_fail (EM_IS_PART_ATTACHMENT (empa), NULL);
 
-	g_mutex_lock (empa->priv->mutex);
+	em_part_mutex_lock ((EMPart *) empa);
 	if (empa->priv->mstream)
 		stream = g_object_ref (empa->priv->mstream);
-	g_mutex_unlock (empa->priv->mutex);
+	em_part_mutex_unlock ((EMPart *) empa);
 
 	return stream;
 }
@@ -527,9 +517,9 @@ em_part_attachment_set_handler (EMPartAttachment *empa,
 {
 	g_return_if_fail (EM_IS_PART_ATTACHMENT (empa));
 
-	g_mutex_lock (empa->priv->mutex);
+	em_part_mutex_lock ((EMPart *) empa);
 	empa->priv->handler = handler;
-	g_mutex_unlock (empa->priv->mutex);
+	em_part_mutex_unlock ((EMPart *) empa);
 }
 
 const EMFormatHandler*
@@ -539,9 +529,9 @@ em_part_attachment_get_handler (EMPartAttachment *empa)
 
 	g_return_val_if_fail (EM_IS_PART_ATTACHMENT (empa), NULL);
 
-	g_mutex_lock (empa->priv->mutex);
+	em_part_mutex_lock ((EMPart *) empa);
 	handler = empa->priv->handler;
-	g_mutex_unlock (empa->priv->mutex);
+	em_part_mutex_unlock ((EMPart *) empa);
 
 	return handler;
 }
@@ -554,8 +544,6 @@ struct _EMPartSMIMEPrivate {
 	gchar *description;
 	gint signature;
 	GtkWidget *widget;
-
-	GMutex *mutex;
 };
 
 G_DEFINE_TYPE (EMPartSMIME, em_part_smime, EM_TYPE_PART);
@@ -566,7 +554,7 @@ em_part_smime_finalize (GObject *object)
 {
 	EMPartSMIMEPrivate *priv = EM_PART_SMIME (object)->priv;
 	
-	g_mutex_lock (priv->mutex);
+	em_part_mutex_lock (EM_PART (object));
 	
 	if (priv->description) {
 		g_free (priv->description);
@@ -578,8 +566,7 @@ em_part_smime_finalize (GObject *object)
 		priv->widget = NULL;
 	}
 	
-	g_mutex_unlock (priv->mutex);
-	g_mutex_free (priv->mutex);
+	em_part_mutex_lock (EM_PART (object));
 }
 
 static void
@@ -602,8 +589,6 @@ em_part_smime_init (EMPartSMIME *emps)
 	emps->priv->description = NULL;
 	emps->priv->signature = 0;
 	emps->priv->widget = NULL;
-	
-	emps->priv->mutex = g_mutex_new ();	
 }
 
 EMPart*
@@ -633,7 +618,7 @@ em_part_smime_set_description (EMPartSMIME *emps,
 {
 	g_return_if_fail (EM_IS_PART_SMIME (emps));
 
-	g_mutex_lock (emps->priv->mutex);
+	em_part_mutex_lock ((EMPart *) emps);
 
 	if (emps->priv->description)
 		g_free (emps->priv->description);
@@ -643,7 +628,7 @@ em_part_smime_set_description (EMPartSMIME *emps,
 	else
 		emps->priv->description = NULL;
 
-	g_mutex_unlock (emps->priv->mutex);
+	em_part_mutex_unlock ((EMPart *) emps);
 }
 
 gchar*
@@ -653,10 +638,10 @@ em_part_smime_get_description (EMPartSMIME *emps)
 
 	g_return_val_if_fail (EM_IS_PART_SMIME (emps), NULL);
 
-	g_mutex_lock (emps->priv->mutex);
+	em_part_mutex_lock ((EMPart *) emps);
 	if (emps->priv->description)
 		description = g_strdup (emps->priv->description);
-	g_mutex_unlock (emps->priv->mutex);
+	em_part_mutex_unlock ((EMPart *) emps);
 
 	return description;
 }
@@ -667,9 +652,9 @@ em_part_smime_set_signature (EMPartSMIME *emps,
 {
 	g_return_if_fail (EM_IS_PART_SMIME (emps));
 
-	g_mutex_lock (emps->priv->mutex);
+	em_part_mutex_lock ((EMPart *) emps);
 	emps->priv->signature = signature;
-	g_mutex_unlock (emps->priv->mutex);
+	em_part_mutex_unlock ((EMPart *) emps);
 }
 
 gint
@@ -679,9 +664,9 @@ em_part_smime_get_signature (EMPartSMIME *emps)
 
 	g_return_val_if_fail (EM_IS_PART_SMIME (emps), 0);
 
-	g_mutex_lock (emps->priv->mutex);
+	em_part_mutex_lock ((EMPart *) emps);
 	signature = emps->priv->signature;
-	g_mutex_unlock (emps->priv->mutex);
+	em_part_mutex_unlock ((EMPart *) emps);
 
 	return signature;
 }
@@ -696,14 +681,14 @@ em_part_smime_set_widget (EMPartSMIME *emps,
 	if (widget)
 		g_object_ref (widget);
 
-	g_mutex_lock (emps->priv->mutex);
+	em_part_mutex_lock ((EMPart *) emps);
 
 	if (emps->priv->widget)
 		g_object_unref (emps->priv->widget);
 
 	emps->priv->widget = widget;
 
-	g_mutex_unlock (emps->priv->mutex);
+	em_part_mutex_unlock ((EMPart *) emps);
 }
 
 GtkWidget*
@@ -713,10 +698,10 @@ em_part_smime_get_widget (EMPartSMIME *emps)
 
 	g_return_val_if_fail (EM_IS_PART_SMIME (emps), NULL);
 
-	g_mutex_lock (emps->priv->mutex);
+	em_part_mutex_lock ((EMPart *) emps);
 	if (emps->priv->widget)
 		widget = g_object_ref (emps->priv->widget);
-	g_mutex_unlock (emps->priv->mutex);
+	em_part_mutex_unlock ((EMPart *) emps);
 
 	return widget;
 }
diff --git a/plugins/audio-inline/em-part-audio.c b/plugins/audio-inline/em-part-audio.c
index 749cd83..2b2c4a2 100644
--- a/plugins/audio-inline/em-part-audio.c
+++ b/plugins/audio-inline/em-part-audio.c
@@ -34,8 +34,6 @@ struct _EMPartAudioPrivate {
 	GtkWidget *play_button;
 	GtkWidget *pause_button;
 	GtkWidget *stop_button;
-
-	GMutex *mutex;
 };
 
 static void
@@ -43,7 +41,7 @@ em_part_audio_finalize (GObject *object)
 {
 	EMPartAudioPrivate *priv = EM_PART_AUDIO (object)->priv;
 
-	g_mutex_lock (priv->mutex);
+	em_part_mutex_lock (EM_PART (object));
 
 	if (priv->filename) {
 		g_free (priv->filename);
@@ -70,8 +68,7 @@ em_part_audio_finalize (GObject *object)
 		priv->stop_button = NULL;
 	}
 
-	g_mutex_unlock (priv->mutex);
-	g_mutex_free (priv->mutex);
+	em_part_mutex_unlock (EM_PART (object));
 }
 
 static void
@@ -91,7 +88,6 @@ em_part_audio_init (EMPartAudio *empa)
 	empa->priv = G_TYPE_INSTANCE_GET_PRIVATE (empa,
 			EM_TYPE_PART_AUDIO, EMPartAudioPrivate);
 	
-	empa->priv->mutex = g_mutex_new ();
 	empa->priv->filename = NULL;
 	empa->priv->pause_button = NULL;
 	empa->priv->play_button = NULL;
@@ -105,7 +101,7 @@ EMPart *
 em_part_audio_new (EMFormat *emf,
 		   CamelMimePart *part,
 		   const gchar *uri,
-		   EMPartWidgetFunc widget_func)
+		   EMPartWriteFunc write_func)
 {
 	EMPart *emp;
 	
@@ -118,8 +114,8 @@ em_part_audio_new (EMFormat *emf,
 	em_part_set_formatter (emp, emf);
 	em_part_set_uri (emp, uri);
 	
-	if (widget_func)
-		em_part_set_widget_func (emp, widget_func);
+	if (write_func)
+		em_part_set_write_func (emp, write_func);
 	
 	return emp;
 }
@@ -130,7 +126,7 @@ em_part_audio_set_filename (EMPartAudio *empa,
 {
 	g_return_if_fail (EM_IS_PART_AUDIO (empa));
 
-	g_mutex_lock (empa->priv->mutex);
+	em_part_mutex_lock ((EMPart *) empa);
 	if (empa->priv->filename)
 		g_free (empa->priv->filename);
 
@@ -139,7 +135,7 @@ em_part_audio_set_filename (EMPartAudio *empa,
 	else
 		empa->priv->filename = NULL;
 
-	g_mutex_unlock (empa->priv->mutex);
+	em_part_mutex_unlock ((EMPart *) empa);
 }
 
 gchar*
@@ -149,10 +145,10 @@ em_part_audio_get_filename (EMPartAudio *empa)
 
 	g_return_val_if_fail (EM_IS_PART_AUDIO (empa), NULL);
 
-	g_mutex_lock (empa->priv->mutex);
+	em_part_mutex_lock ((EMPart *) empa);
 	if (empa->priv->filename)
 		filename = g_strdup (empa->priv->filename);
-	g_mutex_unlock (empa->priv->mutex);
+	em_part_mutex_unlock ((EMPart *) empa);
 
 	return filename;
 }
@@ -163,7 +159,7 @@ void em_part_audio_set_playbin (EMPartAudio *empa,
 	g_return_if_fail (EM_IS_PART_AUDIO (empa));
 	g_return_if_fail (playbin == NULL || GST_IS_ELEMENT (playbin));
 
-	g_mutex_lock (empa->priv->mutex);
+	em_part_mutex_lock ((EMPart *) empa);
 
 	if (playbin)
 		g_object_ref (playbin);
@@ -173,7 +169,7 @@ void em_part_audio_set_playbin (EMPartAudio *empa,
 
 	empa->priv->playbin = playbin;
 
-	g_mutex_unlock (empa->priv->mutex);
+	em_part_mutex_unlock ((EMPart *) empa);
 }
 
 GstElement*
@@ -183,10 +179,10 @@ em_part_audio_get_playbin (EMPartAudio *empa)
 
 	g_return_val_if_fail (EM_IS_PART_AUDIO (empa), NULL);
 
-	g_mutex_lock (empa->priv->mutex);
+	em_part_mutex_lock ((EMPart *) empa);
 	if (empa->priv->playbin)
 		element = g_object_ref (empa->priv->playbin);
-	g_mutex_unlock (empa->priv->mutex);
+	em_part_mutex_unlock ((EMPart *) empa);
 
 	return element;	
 }
@@ -196,9 +192,9 @@ void em_part_audio_set_bus_id (EMPartAudio *empa,
 {
 	g_return_if_fail (EM_IS_PART_AUDIO (empa));
 
-	g_mutex_lock (empa->priv->mutex);
+	em_part_mutex_lock ((EMPart *) empa);
 	empa->priv->bus_id = bus_id;
-	g_mutex_unlock (empa->priv->mutex);
+	em_part_mutex_unlock ((EMPart *) empa);
 }
 
 gulong
@@ -208,9 +204,9 @@ em_part_audio_get_bus_id (EMPartAudio *empa)
 
 	g_return_val_if_fail (EM_IS_PART_AUDIO (empa), 0);
 
-	g_mutex_lock (empa->priv->mutex);
+	em_part_mutex_lock ((EMPart *) empa);
 	bus_id = empa->priv->bus_id;
-	g_mutex_unlock (empa->priv->mutex);
+	em_part_mutex_unlock ((EMPart *) empa);
 
 	return bus_id;
 }
@@ -221,9 +217,9 @@ em_part_audio_set_target_state (EMPartAudio *empa,
 {
 	g_return_if_fail (EM_IS_PART_AUDIO (empa));
 
-	g_mutex_lock (empa->priv->mutex);
+	em_part_mutex_lock ((EMPart *) empa);
 	empa->priv->target_state = state;
-	g_mutex_unlock (empa->priv->mutex);
+	em_part_mutex_unlock ((EMPart *) empa);
 }
 
 GstState
@@ -233,9 +229,9 @@ em_part_audio_get_target_state (EMPartAudio *empa)
 
 	g_return_val_if_fail (EM_IS_PART_AUDIO (empa), GST_STATE_NULL);
 
-	g_mutex_lock (empa->priv->mutex);
+	em_part_mutex_lock ((EMPart *) empa);
 	state = empa->priv->target_state;
-	g_mutex_unlock (empa->priv->mutex);
+	em_part_mutex_unlock ((EMPart *) empa);
 
 	return state;	
 }
@@ -247,7 +243,7 @@ em_part_audio_set_play_button (EMPartAudio *empa,
 	g_return_if_fail (EM_IS_PART_AUDIO (empa));
 	g_return_if_fail (button == NULL || GTK_IS_WIDGET (button));
 
-	g_mutex_lock (empa->priv->mutex);
+	em_part_mutex_lock ((EMPart *) empa);
 
 	if (button)
 		g_object_ref (button);
@@ -257,7 +253,7 @@ em_part_audio_set_play_button (EMPartAudio *empa,
 
 	empa->priv->play_button = button;
 
-	g_mutex_unlock (empa->priv->mutex);
+	em_part_mutex_unlock ((EMPart *) empa);
 }
 
 GtkWidget*
@@ -267,10 +263,10 @@ em_part_audio_get_play_button (EMPartAudio *empa)
 
 	g_return_val_if_fail (EM_IS_PART_AUDIO (empa), NULL);
 
-	g_mutex_lock (empa->priv->mutex);
+	em_part_mutex_lock ((EMPart *) empa);
 	if (empa->priv->play_button)
 		widget = g_object_ref (empa->priv->play_button);
-	g_mutex_unlock (empa->priv->mutex);
+	em_part_mutex_unlock ((EMPart *) empa);
 
 	return widget;
 }
@@ -282,7 +278,7 @@ em_part_audio_set_pause_button (EMPartAudio *empa,
 	g_return_if_fail (EM_IS_PART_AUDIO (empa));
 	g_return_if_fail (button == NULL || GTK_IS_WIDGET (button));
 
-	g_mutex_lock (empa->priv->mutex);
+	em_part_mutex_lock ((EMPart *) empa);
 
 	if (button)
 		g_object_ref (button);
@@ -292,7 +288,7 @@ em_part_audio_set_pause_button (EMPartAudio *empa,
 
 	empa->priv->pause_button = button;
 
-	g_mutex_unlock (empa->priv->mutex);
+	em_part_mutex_unlock ((EMPart *) empa);
 }
 
 GtkWidget*
@@ -302,10 +298,10 @@ em_part_audio_get_pause_button (EMPartAudio *empa)
 
 	g_return_val_if_fail (EM_IS_PART_AUDIO (empa), NULL);
 
-	g_mutex_lock (empa->priv->mutex);
+	em_part_mutex_lock ((EMPart *) empa);
 	if (empa->priv->pause_button)
 		widget = g_object_ref (empa->priv->pause_button);
-	g_mutex_unlock (empa->priv->mutex);
+	em_part_mutex_unlock ((EMPart *) empa);
 
 	return widget;
 }
@@ -317,7 +313,7 @@ em_part_audio_set_stop_button (EMPartAudio *empa,
 	g_return_if_fail (EM_IS_PART_AUDIO (empa));
 	g_return_if_fail (button == NULL || GTK_IS_WIDGET (button));
 
-	g_mutex_lock (empa->priv->mutex);
+	em_part_mutex_lock ((EMPart *) empa);
 
 	if (button)
 		g_object_ref (button);
@@ -327,7 +323,7 @@ em_part_audio_set_stop_button (EMPartAudio *empa,
 
 	empa->priv->stop_button = button;
 
-	g_mutex_unlock (empa->priv->mutex);
+	em_part_mutex_unlock ((EMPart *) empa);
 }
 
 GtkWidget*
@@ -337,10 +333,10 @@ em_part_audio_get_stop_button (EMPartAudio *empa)
 
 	g_return_val_if_fail (EM_IS_PART_AUDIO (empa), NULL);
 
-	g_mutex_lock (empa->priv->mutex);
+	em_part_mutex_lock ((EMPart *) empa);
 	if (empa->priv->stop_button)
 		widget = g_object_ref (empa->priv->stop_button);
-	g_mutex_unlock (empa->priv->stop_button);
+	em_part_mutex_unlock ((EMPart *) empa);
 
 	return widget;
 }
diff --git a/plugins/audio-inline/em-part-audio.h b/plugins/audio-inline/em-part-audio.h
index e8d7853..ff51678 100644
--- a/plugins/audio-inline/em-part-audio.h
+++ b/plugins/audio-inline/em-part-audio.h
@@ -53,8 +53,7 @@ struct _EMPartAudio {
 };
 
 struct _EMPartAudioClass {
-	GObjectClass parent_class;
-	
+	EMPartClass parent_class;
 };
 
 EMPart*			em_part_audio_new      	(EMFormat *emf,



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