From fe4018941190f8bf020e4a8ed2999c212e0e113d Mon Sep 17 00:00:00 2001 From: Alexander Larsson Date: Sat, 15 Feb 2003 16:25:08 +0000 Subject: 2003-02-15 Alexander Larsson * dbus/dbus-threads.c: * dbus/dbus-threads.h: Add condvars. Remove static mutext from API. Implement static mutexes by initializing them from threads_init. * glib/dbus-gthread.c: * qt/dbus-qthread.cpp: Update with the thread api changes. * dbus/dbus-list.c: * dbus/dbus-list.h: Turn StaticMutex into normal mutex + init function. Export new functions _dbus_list_alloc_link, _dbus_list_free_link, _dbus_list_append_link, _dbus_list_prepend_link * dbus/dbus-sysdeps.c: * dbus/dbus-sysdeps.h: New type dbus_atomic_t, and new functions _dbus_atomic_inc, _dbus_atomic_dec. Only slow fallback implementation at the moment. * dbus/dbus-protocol.h: Add DBUS_MESSAGE_LOCAL_DISCONNECT define * dbus/dbus-message.c: Make ref/unref atomic. Fix some docs. * dbus/dbus-connection-internal.h: * dbus/dbus-connection.c: * dbus/dbus-connection.h: Make threadsafe. Change _peek to _borrow,_return & _steal_borrowed. Change disconnect callback to event. Make dbus_connection_dispatch_messages reentrant. * dbus/dbus-transport.c: Don't ref the connection on calls to the transport implementation. * dbus/dbus-message-handler.c: Make threadsafe. * glib/dbus-gmain.c: Don't use peek_message anymore * test/Makefile.am: * test/debug-thread.c: * test/debug-thread.h: Simple thread implementation that asserts() on deadlocks in single-threaded code. * test/bus-test.c: (main) Call debug_threads_init. * test/watch.c: Use disconnect message instead of disconnect callback. * bus/connection.c: * bus/connection.h: Don't call dbus_connection_set_disconnect_function. Instead export bus_connection_disconnect. * bus/dispatch.c: Call bus_connection_disconnect when we get a disconnected message. --- dbus/dbus-transport.c | 42 ++++++++++++------------------------------ 1 file changed, 12 insertions(+), 30 deletions(-) (limited to 'dbus/dbus-transport.c') diff --git a/dbus/dbus-transport.c b/dbus/dbus-transport.c index a9860819..5a25a675 100644 --- a/dbus/dbus-transport.c +++ b/dbus/dbus-transport.c @@ -52,31 +52,13 @@ * or encryption schemes. */ -/** - * Refs a transport and associated connection for reentrancy. - * - * @todo this macro reflects a design mistake, which is that the - * transport has a pointer to its connection. Ownership should move in - * only one direction; the connection should push/pull from the - * transport, rather than vice versa. Then the connection would take - * care of referencing itself when needed. - */ -#define DBUS_TRANSPORT_HOLD_REF(t) \ - _dbus_transport_ref (t); if ((t)->connection) dbus_connection_ref ((t)->connection) - -/** - * Inverse of DBUS_TRANSPORT_HOLD_REF(). - */ -#define DBUS_TRANSPORT_RELEASE_REF(t) \ - if ((t)->connection) dbus_connection_unref ((t)->connection); _dbus_transport_unref (t) - static void live_messages_size_notify (DBusCounter *counter, void *user_data) { DBusTransport *transport = user_data; - DBUS_TRANSPORT_HOLD_REF (transport); + _dbus_transport_ref (transport); #if 0 _dbus_verbose ("Counter value is now %d\n", @@ -89,7 +71,7 @@ live_messages_size_notify (DBusCounter *counter, if (* transport->vtable->live_messages_changed) (* transport->vtable->live_messages_changed) (transport); - DBUS_TRANSPORT_RELEASE_REF (transport); + _dbus_transport_unref (transport); } /** @@ -294,14 +276,14 @@ _dbus_transport_disconnect (DBusTransport *transport) if (transport->disconnected) return; - DBUS_TRANSPORT_HOLD_REF (transport); + _dbus_transport_ref (transport); (* transport->vtable->disconnect) (transport); transport->disconnected = TRUE; _dbus_connection_notify_disconnected (transport->connection); - DBUS_TRANSPORT_RELEASE_REF (transport); + _dbus_transport_unref (transport); } /** @@ -401,11 +383,11 @@ _dbus_transport_handle_watch (DBusTransport *transport, _dbus_watch_sanitize_condition (watch, &condition); - DBUS_TRANSPORT_HOLD_REF (transport); + _dbus_transport_ref (transport); _dbus_watch_ref (watch); (* transport->vtable->handle_watch) (transport, watch, condition); _dbus_watch_unref (watch); - DBUS_TRANSPORT_RELEASE_REF (transport); + _dbus_transport_unref (transport); } /** @@ -425,9 +407,9 @@ _dbus_transport_set_connection (DBusTransport *transport, transport->connection = connection; - DBUS_TRANSPORT_HOLD_REF (transport); + _dbus_transport_ref (transport); (* transport->vtable->connection_set) (transport); - DBUS_TRANSPORT_RELEASE_REF (transport); + _dbus_transport_unref (transport); } /** @@ -450,10 +432,10 @@ _dbus_transport_messages_pending (DBusTransport *transport, transport->messages_need_sending = queue_length > 0; - DBUS_TRANSPORT_HOLD_REF (transport); + _dbus_transport_ref (transport); (* transport->vtable->messages_pending) (transport, queue_length); - DBUS_TRANSPORT_RELEASE_REF (transport); + _dbus_transport_unref (transport); } /** @@ -481,10 +463,10 @@ _dbus_transport_do_iteration (DBusTransport *transport, if (transport->disconnected) return; - DBUS_TRANSPORT_HOLD_REF (transport); + _dbus_transport_ref (transport); (* transport->vtable->do_iteration) (transport, flags, timeout_milliseconds); - DBUS_TRANSPORT_RELEASE_REF (transport); + _dbus_transport_unref (transport); } /** -- cgit