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-server.c | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) (limited to 'dbus/dbus-server.c') diff --git a/dbus/dbus-server.c b/dbus/dbus-server.c index 4007d7a5..1c9d53f0 100644 --- a/dbus/dbus-server.c +++ b/dbus/dbus-server.c @@ -666,17 +666,22 @@ _DBUS_DEFINE_GLOBAL_LOCK (server_slots); * Allocates an integer ID to be used for storing application-specific * data on any DBusServer. The allocated ID may then be used * with dbus_server_set_data() and dbus_server_get_data(). - * If allocation fails, -1 is returned. Again, the allocated - * slot is global, i.e. all DBusServer objects will - * have a slot with the given integer ID reserved. - * - * @returns -1 on failure, otherwise the data slot ID + * The slot must be initialized with -1. If a nonnegative + * slot is passed in, the refcount is incremented on that + * slot, rather than creating a new slot. + * + * The allocated slot is global, i.e. all DBusServer objects will have + * a slot with the given integer ID reserved. + * + * @param slot_p address of global variable storing the slot ID + * @returns #FALSE on no memory */ -int -dbus_server_allocate_data_slot (void) +dbus_bool_t +dbus_server_allocate_data_slot (dbus_int32_t *slot_p) { return _dbus_data_slot_allocator_alloc (&slot_allocator, - _DBUS_LOCK_NAME (server_slots)); + _DBUS_LOCK_NAME (server_slots), + slot_p); } /** @@ -688,14 +693,14 @@ dbus_server_allocate_data_slot (void) * but may not be retrieved (and may only be replaced * if someone else reallocates the slot). * - * @param slot the slot to deallocate + * @param slot_p address of the slot to deallocate */ void -dbus_server_free_data_slot (int slot) +dbus_server_free_data_slot (dbus_int32_t *slot_p) { - _dbus_return_if_fail (slot >= 0); + _dbus_return_if_fail (*slot_p >= 0); - _dbus_data_slot_allocator_free (&slot_allocator, slot); + _dbus_data_slot_allocator_free (&slot_allocator, slot_p); } /** -- cgit