evolution r36171 - branches/mail-dbus-remoting/mail



Author: michael
Date: Thu Aug 28 17:05:25 2008
New Revision: 36171
URL: http://svn.gnome.org/viewvc/evolution?rev=36171&view=rev

Log:
work around horrific dbus threading inadequacy ...


Modified:
   branches/mail-dbus-remoting/mail/dbind.c
   branches/mail-dbus-remoting/mail/mail-dbus.c

Modified: branches/mail-dbus-remoting/mail/dbind.c
==============================================================================
--- branches/mail-dbus-remoting/mail/dbind.c	(original)
+++ branches/mail-dbus-remoting/mail/dbind.c	Thu Aug 28 17:05:25 2008
@@ -143,11 +143,18 @@
     return success;
 }
 
+/* urgh */
+static GMutex *mutex = NULL;
+static GCond *cond = NULL;
+static gboolean waiting = FALSE;
+
 static void set_reply (DBusPendingCall *pending, void *user_data)
 {
   void **replyptr = (void **)user_data;
 
   *replyptr = dbus_pending_call_steal_reply (pending);
+  //  fprintf (stderr, "L: %p set_reply - %p\n", g_thread_self(), replyptr);
+  g_cond_broadcast (cond);
 }
 
 static DBusMessage *
@@ -155,16 +162,36 @@
 {
   DBusPendingCall *pending;
   DBusMessage *reply = NULL;
+  gboolean terminate = FALSE;
 
+  /* urgh */
+  if (!mutex) {
+    mutex = g_mutex_new ();
+    cond = g_cond_new();
+  }
   if (!dbus_connection_send_with_reply (bus, message, &pending, timeout))
   {
     return NULL;
   }
   dbus_pending_call_set_notify (pending, set_reply, (void *)&reply, NULL);
-  while (!reply)
-  {
-    if (!dbus_connection_read_write_dispatch (bus, timeout)) return NULL;
+  g_mutex_lock (mutex);
+  //  fprintf (stderr, "L: %p send - %p (%s) [%d]\n", g_thread_self(), &reply, dbus_message_get_member (message), waiting);
+
+  /* DBus's connection_read_write_dispatch is deadly broken wrt. replies ... */
+  while (!reply && !terminate) {
+	gboolean do_poll = !waiting;
+	if (do_poll) {
+		waiting = TRUE;
+		g_mutex_unlock (mutex);
+		terminate = !dbus_connection_read_write_dispatch (bus, timeout);
+		g_mutex_lock (mutex);
+		g_cond_broadcast (cond);
+		waiting = FALSE;
+	} else
+		g_cond_wait (cond, mutex);
   }
+  g_mutex_unlock (mutex);
+
   return reply;
 }
 

Modified: branches/mail-dbus-remoting/mail/mail-dbus.c
==============================================================================
--- branches/mail-dbus-remoting/mail/mail-dbus.c	(original)
+++ branches/mail-dbus-remoting/mail/mail-dbus.c	Thu Aug 28 17:05:25 2008
@@ -135,6 +135,8 @@
 			buffer[i] = '_';
 	}
 
+	g_assert (g_utf8_validate (buffer, -1, NULL));
+
 	return buffer;
 }
 
@@ -170,6 +172,8 @@
 	/* End by NULL */
 	buffer[8] = 0;
 
+	g_assert (g_utf8_validate (buffer, -1, NULL));
+
 	return buffer;
 }
 



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