[evolution-patches] report_writable e-book change



there were a few things wrong with the _report_writable handling in
libebook.

1) it used an idle handler, but didn't remove the handler in
e_book_dispose (this isn't so much of an issue, since a ref is held).
2) it created a closure when it didn't need to
3) it wasn't MT-safe.
Index: ChangeLog
===================================================================
RCS file: /cvs/gnome/evolution-data-server/addressbook/ChangeLog,v
retrieving revision 1.176
diff -u -r1.176 ChangeLog
--- ChangeLog	13 Jul 2004 19:56:43 -0000	1.176
+++ ChangeLog	15 Jul 2004 07:21:40 -0000
@@ -1,3 +1,15 @@
+2004-07-14  Chris Toshok  <toshok ximian com>
+
+	* libebook/e-book.c (e_book_idle_writable): simplify this a bit,
+	since we don't need to pass the writable state in a closure - we
+	can just get it from the book.  also wrap stuff up in a mutex
+	since we can get multiple report_writable calls from a backend.
+	(e_book_handle_response): make sure we only have 1 idle call at a
+	time going, and simplify the closure passing to be just the EBook.
+	same with the mutex juju.
+	(e_book_dispose): remove the writable idle callback if there is
+	one registered.
+
 2004-07-13  Chris Toshok  <toshok ximian com>
 
 	* libebook/e-book.c (e_book_get_self): only propagate the GError
Index: libebook/e-book.c
===================================================================
RCS file: /cvs/gnome/evolution-data-server/addressbook/libebook/e-book.c,v
retrieving revision 1.36
diff -u -r1.36 e-book.c
--- libebook/e-book.c	13 Jul 2004 19:56:43 -0000	1.36
+++ libebook/e-book.c	15 Jul 2004 07:21:41 -0000
@@ -129,6 +129,8 @@
 
 	gulong listener_signal;
 	gulong died_signal;
+
+	gint writable_idle_id;
 };
 
 
@@ -2498,22 +2500,21 @@
 	}
 }
 
-typedef struct
-{
-	EBook *book;
-	gboolean writable;
-}  EBookWritableData;
-
 static gboolean
 e_book_idle_writable (gpointer data)
 {
-	EBookWritableData *write_data = data;
-	
-	g_signal_emit (G_OBJECT (write_data->book), e_book_signals [WRITABLE_STATUS], 0, write_data->writable);
+	EBook *book = data;
+	gboolean writable;
+
+	g_mutex_lock (book->priv->mutex);
+	writable = book->priv->writable;
+	book->priv->writable_idle_id = 0;
+	g_mutex_unlock (book->priv->mutex);
+
+	g_signal_emit (G_OBJECT (book), e_book_signals [WRITABLE_STATUS], 0, writable);
+
+	g_object_unref (book);
 
-	g_object_unref (write_data->book);
-	g_free (write_data);
-	
 	return FALSE;
 }
 
@@ -2523,7 +2524,6 @@
 e_book_handle_response (EBookListener *listener, EBookListenerResponse *resp, EBook *book)
 {
 	EContact *contact;
-	EBookWritableData *write_data;
 
 	switch (resp->op) {
 	case CreateContactResponse:
@@ -2562,12 +2562,13 @@
 	case WritableStatusEvent: 
 		book->priv->writable = resp->writable;
 	
-		write_data = g_new0 (EBookWritableData, 1);
+		g_object_ref (book);
+
+		g_mutex_lock (book->priv->mutex);
+		if (book->priv->writable_idle_id == 0)
+			book->priv->writable_idle_id = g_idle_add (e_book_idle_writable, book);
+		g_mutex_unlock (book->priv->mutex);
 
-		write_data->book = g_object_ref (book);
-		write_data->writable = book->priv->writable;
-		
-		g_idle_add (e_book_idle_writable, write_data);
 		break;
 	default:
 		g_error ("EBook: Unknown response code %d!\n",
@@ -3401,6 +3402,9 @@
 		g_hash_table_destroy (book->priv->id_to_op);
 
 		g_mutex_free (book->priv->mutex);
+
+		if (book->priv->writable_idle_id)
+			g_source_remove (book->priv->writable_idle_id);
 
 		g_free (book->priv);
 		book->priv = NULL;


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