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-connection.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-connection.c')
-rw-r--r-- | dbus/dbus-connection.c | 41 |
1 files changed, 24 insertions, 17 deletions
diff --git a/dbus/dbus-connection.c b/dbus/dbus-connection.c index d877a0b4..01b2a7bf 100644 --- a/dbus/dbus-connection.c +++ b/dbus/dbus-connection.c @@ -2933,34 +2933,41 @@ _DBUS_DEFINE_GLOBAL_LOCK (connection_slots); * Allocates an integer ID to be used for storing application-specific * data on any DBusConnection. The allocated ID may then be used * with dbus_connection_set_data() and dbus_connection_get_data(). - * If allocation fails, -1 is returned. Again, the allocated - * slot is global, i.e. all DBusConnection objects will + * The passed-in slot must be initialized to -1, and is filled in + * with the slot ID. If the passed-in slot is not -1, it's assumed + * to be already allocated, and its refcount is incremented. + * + * The allocated slot is global, i.e. all DBusConnection objects will * have a slot with the given integer ID reserved. * - * @returns -1 on failure, otherwise the data slot ID + * @param slot_p address of a global variable storing the slot + * @returns #FALSE on failure (no memory) */ -int -dbus_connection_allocate_data_slot (void) +dbus_bool_t +dbus_connection_allocate_data_slot (dbus_int32_t *slot_p) { return _dbus_data_slot_allocator_alloc (&slot_allocator, - _DBUS_LOCK_NAME (connection_slots)); + _DBUS_LOCK_NAME (connection_slots), + slot_p); } /** * Deallocates a global ID for connection data slots. - * dbus_connection_get_data() and dbus_connection_set_data() - * may no longer be used with this slot. - * Existing data stored on existing DBusConnection objects - * will be freed when the connection is finalized, - * but may not be retrieved (and may only be replaced - * if someone else reallocates the slot). + * dbus_connection_get_data() and dbus_connection_set_data() may no + * longer be used with this slot. Existing data stored on existing + * DBusConnection objects will be freed when the connection is + * finalized, but may not be retrieved (and may only be replaced if + * someone else reallocates the slot). When the refcount on the + * passed-in slot reaches 0, it is set to -1. * - * @param slot the slot to deallocate + * @param slot_p address storing the slot to deallocate */ void -dbus_connection_free_data_slot (int slot) +dbus_connection_free_data_slot (dbus_int32_t *slot_p) { - _dbus_data_slot_allocator_free (&slot_allocator, slot); + _dbus_return_if_fail (*slot_p >= 0); + + _dbus_data_slot_allocator_free (&slot_allocator, slot_p); } /** @@ -2978,7 +2985,7 @@ dbus_connection_free_data_slot (int slot) */ dbus_bool_t dbus_connection_set_data (DBusConnection *connection, - int slot, + dbus_int32_t slot, void *data, DBusFreeFunction free_data_func) { @@ -3018,7 +3025,7 @@ dbus_connection_set_data (DBusConnection *connection, */ void* dbus_connection_get_data (DBusConnection *connection, - int slot) + dbus_int32_t slot) { void *res; |