diff options
author | Havoc Pennington <hp@redhat.com> | 2003-06-22 19:39:47 +0000 |
---|---|---|
committer | Havoc Pennington <hp@redhat.com> | 2003-06-22 19:39:47 +0000 |
commit | 6843ad31769c088ca259020fd9ea8dfb3a51f68e (patch) | |
tree | 208e287bc200298da5514f4d32704f3e8ef42423 /dbus/dbus-bus.c | |
parent | 8a71cf33ef8f35669dbdb39ef2f12c5a3dfebf33 (diff) |
2003-06-22 Havoc Pennington <hp@pobox.com>
* 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
Diffstat (limited to 'dbus/dbus-bus.c')
-rw-r--r-- | dbus/dbus-bus.c | 61 |
1 files changed, 7 insertions, 54 deletions
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; |