From 6843ad31769c088ca259020fd9ea8dfb3a51f68e Mon Sep 17 00:00:00 2001 From: Havoc Pennington Date: Sun, 22 Jun 2003 19:39:47 +0000 Subject: 2003-06-22 Havoc Pennington * dbus/dbus-dataslot.c (_dbus_data_slot_allocator_unref) (_dbus_data_slot_allocator_alloc): rework these to keep a reference count on each slot and automatically manage a global slot ID variable passed in by address * bus/bus.c: convert to new dataslot API * dbus/dbus-bus.c: convert to new dataslot API * dbus/dbus-connection.c: convert to new dataslot API * dbus/dbus-server.c: convert to new dataslot API * glib/dbus-gmain.c: ditto * bus/test.c: ditto * bus/connection.c: ditto --- glib/dbus-gmain.c | 24 ++++++++++-------------- glib/test-thread-server.c | 5 +++-- 2 files changed, 13 insertions(+), 16 deletions(-) (limited to 'glib') diff --git a/glib/dbus-gmain.c b/glib/dbus-gmain.c index c120a6c1..9b14049d 100644 --- a/glib/dbus-gmain.c +++ b/glib/dbus-gmain.c @@ -60,10 +60,8 @@ struct DBusGSource void *connection_or_server; /**< DBusConnection or DBusServer */ }; -static GStaticMutex connection_slot_lock = G_STATIC_MUTEX_INIT; -static int connection_slot = -1; -static GStaticMutex server_slot_lock = G_STATIC_MUTEX_INIT; -static int server_slot = -1; +static dbus_int32_t connection_slot = -1; +static dbus_int32_t server_slot = -1; static gboolean gsource_connection_prepare (GSource *source, gint *timeout); @@ -428,11 +426,10 @@ dbus_connection_setup_with_g_main (DBusConnection *connection, g_source_attach (source, context); - g_static_mutex_lock (&connection_slot_lock); - if (connection_slot == -1 ) - connection_slot = dbus_connection_allocate_data_slot (); - g_static_mutex_unlock (&connection_slot_lock); - + /* FIXME we never free the slot, so its refcount just keeps growing, + * which is kind of broken. + */ + dbus_connection_allocate_data_slot (&connection_slot); if (connection_slot < 0) goto nomem; @@ -476,11 +473,10 @@ dbus_server_setup_with_g_main (DBusServer *server, g_source_attach (source, context); - g_static_mutex_lock (&server_slot_lock); - if (server_slot == -1 ) - server_slot = dbus_server_allocate_data_slot (); - g_static_mutex_unlock (&server_slot_lock); - + /* FIXME we never free the slot, so its refcount just keeps growing, + * which is kind of broken. + */ + dbus_server_allocate_data_slot (&server_slot); if (server_slot < 0) goto nomem; diff --git a/glib/test-thread-server.c b/glib/test-thread-server.c index a92febf3..00044a79 100644 --- a/glib/test-thread-server.c +++ b/glib/test-thread-server.c @@ -27,7 +27,7 @@ thread_test_data_free (ThreadTestData *data) static DBusMessageHandler *disconnect_handler; static DBusMessageHandler *filter_handler; -static int handler_slot; +static dbus_int32_t handler_slot = -1; static DBusHandlerResult handle_test_message (DBusMessageHandler *handler, @@ -222,7 +222,8 @@ main (int argc, char *argv[]) return 1; } - handler_slot = dbus_connection_allocate_data_slot (); + if (!dbus_connection_allocate_data_slot (&handler_slot)) + g_error ("no memory for data slot"); filter_handler = dbus_message_handler_new (handle_filter, NULL, NULL); -- cgit