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 --- dbus/dbus-bus.c | 61 +++++++-------------------------------------------------- 1 file changed, 7 insertions(+), 54 deletions(-) (limited to 'dbus/dbus-bus.c') diff --git a/dbus/dbus-bus.c b/dbus/dbus-bus.c index dee9b9f7..6ab1eccc 100644 --- a/dbus/dbus-bus.c +++ b/dbus/dbus-bus.c @@ -56,12 +56,9 @@ typedef struct unsigned int is_well_known : 1; /**< Is one of the well-known connections in our global array */ } BusData; -/** The slot we have reserved to store BusData +/** The slot we have reserved to store BusData. */ -static int bus_data_slot = -1; -/** Number of connections using the slot - */ -static int bus_data_slot_refcount = 0; +static dbus_int32_t bus_data_slot = -1; /** Number of bus types */ #define N_BUS_TYPES 3 @@ -194,50 +191,6 @@ init_connections_unlocked (void) return initialized; } -static dbus_bool_t -data_slot_ref (void) -{ - _DBUS_LOCK (bus); - - if (bus_data_slot < 0) - { - bus_data_slot = dbus_connection_allocate_data_slot (); - - if (bus_data_slot < 0) - { - _DBUS_UNLOCK (bus); - return FALSE; - } - - _dbus_assert (bus_data_slot_refcount == 0); - } - - bus_data_slot_refcount += 1; - - _DBUS_UNLOCK (bus); - - return TRUE; -} - -static void -data_slot_unref (void) -{ - _DBUS_LOCK (bus); - - _dbus_assert (bus_data_slot_refcount > 0); - _dbus_assert (bus_data_slot >= 0); - - bus_data_slot_refcount -= 1; - - if (bus_data_slot_refcount == 0) - { - dbus_connection_free_data_slot (bus_data_slot); - bus_data_slot = -1; - } - - _DBUS_UNLOCK (bus); -} - static void bus_data_free (void *data) { @@ -262,7 +215,7 @@ bus_data_free (void *data) dbus_free (bd->base_service); dbus_free (bd); - data_slot_unref (); + dbus_connection_free_data_slot (&bus_data_slot); } static BusData* @@ -270,7 +223,7 @@ ensure_bus_data (DBusConnection *connection) { BusData *bd; - if (!data_slot_ref ()) + if (!dbus_connection_allocate_data_slot (&bus_data_slot)) return NULL; bd = dbus_connection_get_data (connection, bus_data_slot); @@ -279,7 +232,7 @@ ensure_bus_data (DBusConnection *connection) bd = dbus_new0 (BusData, 1); if (bd == NULL) { - data_slot_unref (); + dbus_connection_free_data_slot (&bus_data_slot); return NULL; } @@ -289,7 +242,7 @@ ensure_bus_data (DBusConnection *connection) bus_data_free)) { dbus_free (bd); - data_slot_unref (); + dbus_connection_free_data_slot (&bus_data_slot); return NULL; } @@ -297,7 +250,7 @@ ensure_bus_data (DBusConnection *connection) } else { - data_slot_unref (); + dbus_connection_free_data_slot (&bus_data_slot); } return bd; -- cgit