summaryrefslogtreecommitdiffstats
path: root/bus/dispatch.c
diff options
context:
space:
mode:
authorHavoc Pennington <hp@redhat.com>2003-06-22 19:39:47 +0000
committerHavoc Pennington <hp@redhat.com>2003-06-22 19:39:47 +0000
commit6843ad31769c088ca259020fd9ea8dfb3a51f68e (patch)
tree208e287bc200298da5514f4d32704f3e8ef42423 /bus/dispatch.c
parent8a71cf33ef8f35669dbdb39ef2f12c5a3dfebf33 (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 'bus/dispatch.c')
-rw-r--r--bus/dispatch.c47
1 files changed, 6 insertions, 41 deletions
diff --git a/bus/dispatch.c b/bus/dispatch.c
index 8b2ba08e..d43e8121 100644
--- a/bus/dispatch.c
+++ b/bus/dispatch.c
@@ -32,8 +32,7 @@
#include <dbus/dbus-internals.h>
#include <string.h>
-static int message_handler_slot = -1;
-static int message_handler_slot_refcount;
+static dbus_int32_t message_handler_slot = -1;
typedef struct
{
@@ -309,48 +308,15 @@ bus_dispatch_message_handler (DBusMessageHandler *handler,
return DBUS_HANDLER_RESULT_ALLOW_MORE_HANDLERS;
}
-static dbus_bool_t
-message_handler_slot_ref (void)
-{
- if (message_handler_slot < 0)
- {
- message_handler_slot = dbus_connection_allocate_data_slot ();
-
- if (message_handler_slot < 0)
- return FALSE;
-
- _dbus_assert (message_handler_slot_refcount == 0);
- }
-
- message_handler_slot_refcount += 1;
-
- return TRUE;
-}
-
-static void
-message_handler_slot_unref (void)
-{
- _dbus_assert (message_handler_slot_refcount > 0);
-
- message_handler_slot_refcount -= 1;
-
- if (message_handler_slot_refcount == 0)
- {
- dbus_connection_free_data_slot (message_handler_slot);
- message_handler_slot = -1;
- }
-}
-
static void
free_message_handler (void *data)
{
DBusMessageHandler *handler = data;
_dbus_assert (message_handler_slot >= 0);
- _dbus_assert (message_handler_slot_refcount > 0);
dbus_message_handler_unref (handler);
- message_handler_slot_unref ();
+ dbus_connection_free_data_slot (&message_handler_slot);
}
dbus_bool_t
@@ -358,26 +324,25 @@ bus_dispatch_add_connection (DBusConnection *connection)
{
DBusMessageHandler *handler;
- if (!message_handler_slot_ref ())
+ if (!dbus_connection_allocate_data_slot (&message_handler_slot))
return FALSE;
handler = dbus_message_handler_new (bus_dispatch_message_handler, NULL, NULL);
if (handler == NULL)
{
- message_handler_slot_unref ();
+ dbus_connection_free_data_slot (&message_handler_slot);
return FALSE;
}
if (!dbus_connection_add_filter (connection, handler))
{
dbus_message_handler_unref (handler);
- message_handler_slot_unref ();
+ dbus_connection_free_data_slot (&message_handler_slot);
return FALSE;
}
_dbus_assert (message_handler_slot >= 0);
- _dbus_assert (message_handler_slot_refcount > 0);
if (!dbus_connection_set_data (connection,
message_handler_slot,
@@ -385,7 +350,7 @@ bus_dispatch_add_connection (DBusConnection *connection)
free_message_handler))
{
dbus_message_handler_unref (handler);
- message_handler_slot_unref ();
+ dbus_connection_free_data_slot (&message_handler_slot);
return FALSE;
}