]> git.ipfire.org Git - thirdparty/dbus.git/commitdiff
2003-02-20 Alexander Larsson <alexl@redhat.com>
authorAlexander Larsson <alexl@redhat.com>
Thu, 20 Feb 2003 10:00:48 +0000 (10:00 +0000)
committerAlexander Larsson <alexl@redhat.com>
Thu, 20 Feb 2003 10:00:48 +0000 (10:00 +0000)
* dbus/dbus-transport-unix.c (unix_do_iteration):
Unlock the connection mutex during a blocking select call.
Add todo about how we need a way to wake up the select.

* dbus/dbus-connection-internal.h:
* dbus/dbus-connection.c:
Add _dbus_connection_lock and _dbus_connection_unlock.

ChangeLog
dbus/dbus-connection-internal.h
dbus/dbus-connection.c
dbus/dbus-transport-unix.c

index 4404bdf32e5d67bf83e8ca06ee319b47dd0b702c..070196df3ba1f89d45b1b3254b935b52f6e4a4a0 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2003-02-20  Alexander Larsson  <alexl@redhat.com>
+
+       * dbus/dbus-transport-unix.c (unix_do_iteration):
+       Unlock the connection mutex during a blocking select call.
+       Add todo about how we need a way to wake up the select.
+
+       * dbus/dbus-connection-internal.h: 
+       * dbus/dbus-connection.c:
+       Add _dbus_connection_lock and _dbus_connection_unlock.
+
 2003-02-19  Havoc Pennington  <hp@pobox.com>
 
        * Doxyfile.in (PREDEFINED): put DOXYGEN_SHOULD_SKIP_THIS in
index 0606d1bd78184b7f21ceb2428bcb5e89171ebb94..64c4cf39a79998effeef93f6f02b04ec6e21afae 100644 (file)
@@ -38,6 +38,9 @@ typedef enum
   DBUS_ITERATION_BLOCK      = 1 << 2  /**< Block if nothing to do. */
 } DBusIterationFlags;
 
+void             _dbus_connection_lock                  (DBusConnection *connection);
+void             _dbus_connection_unlock                (DBusConnection *connection);
+
 void             _dbus_connection_ref_unlocked          (DBusConnection *connection);
 
 dbus_bool_t     _dbus_connection_queue_received_message (DBusConnection *connection,
index 7da89bdc6bf77f190590ad73f603c29bec9eb6da..64e83d110d7458e66f7687bb97aab7b35c686f52 100644 (file)
@@ -134,6 +134,27 @@ static void _dbus_connection_free_data_slots_nolock (DBusConnection *connection)
 static void _dbus_connection_remove_timeout_locked (DBusConnection *connection,
                                                    DBusTimeout    *timeout);
 
+/**
+ * Acquires the connection lock.
+ *
+ * @param connection the connection.
+ */
+void
+_dbus_connection_lock (DBusConnection *connection)
+{
+  dbus_mutex_lock (connection->mutex);
+}
+
+/**
+ * Releases the connection lock.
+ *
+ * @param connection the connection.
+ */
+void
+_dbus_connection_unlock (DBusConnection *connection)
+{
+  dbus_mutex_unlock (connection->mutex);
+}
 
 
 /**
@@ -336,9 +357,9 @@ static void
 _dbus_connection_remove_timeout_locked (DBusConnection *connection,
                                        DBusTimeout    *timeout)
 {
-    dbus_mutex_lock (connection->mutex);
-    _dbus_connection_remove_timeout (connection, timeout);
-    dbus_mutex_unlock (connection->mutex);
+  dbus_mutex_lock (connection->mutex);
+  _dbus_connection_remove_timeout (connection, timeout);
+  dbus_mutex_unlock (connection->mutex);
 }
 
 
index c5dce8d7754284f3372dd0ca75de2e0741202282..b30dc1d6d0d96895d7b99f0a13ac4065b1faf883 100644 (file)
@@ -884,6 +884,13 @@ unix_messages_pending (DBusTransport *transport,
 }
 
 /* FIXME use _dbus_poll(), not select() */
+/**
+ * @todo We need to have a way to wake up the select sleep if
+ * a new iteration request comes in with a flag (read/write) that
+ * we're not currently serving. Otherwise a call that just reads
+ * could block a write call forever (if there are no incoming
+ * messages).
+ */
 static  void
 unix_do_iteration (DBusTransport *transport,
                    unsigned int   flags,
@@ -893,6 +900,7 @@ unix_do_iteration (DBusTransport *transport,
   fd_set read_set;
   fd_set write_set;
   dbus_bool_t do_select;
+  int select_res;
 
   _dbus_verbose (" iteration flags = %s%s timeout = %d\n",
                  flags & DBUS_ITERATION_DO_READING ? "read" : "",
@@ -984,9 +992,24 @@ unix_do_iteration (DBusTransport *transport,
           timeout.tv_usec = 0;
           use_timeout = TRUE;
         }
+
+      /* For blocking selects we drop the connection lock here
+       * to avoid blocking out connection access during a potentially
+       * indefinite blocking call. The io path is still protected
+       * by the io_path_cond condvar, so we won't reenter this.
+       */
+      if (flags & DBUS_ITERATION_BLOCK)
+       _dbus_connection_unlock (transport->connection);
+      
+      select_res = select (unix_transport->fd + 1,
+                          &read_set, &write_set, &err_set,
+                          use_timeout ? &timeout : NULL);
+
+      if (flags & DBUS_ITERATION_BLOCK)
+       _dbus_connection_lock (transport->connection);
+      
       
-      if (select (unix_transport->fd + 1, &read_set, &write_set, &err_set,
-                  use_timeout ? &timeout : NULL) >= 0)
+      if (select_res >= 0)
         {
           if (FD_ISSET (unix_transport->fd, &err_set))
             do_io_error (transport);