mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-07-06 18:57:01 +02:00
gdbusconnection: Tidy up unsubscription code
This just removes a now-redundant intermediate array. This means that the `SignalSubscriber` instances are now potentially freed a little sooner, inside the locked segment, but they are already careful to only call their `user_data_free_func` in the right thread. So that should not deadlock. Signed-off-by: Philip Withnall <withnall@endlessm.com> Helps: #978
This commit is contained in:
parent
130455bbb2
commit
4ec2175d21
@ -3600,15 +3600,16 @@ g_dbus_connection_signal_subscribe (GDBusConnection *connection,
|
|||||||
/* ---------------------------------------------------------------------------------------------------- */
|
/* ---------------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
/* called in any thread */
|
/* called in any thread */
|
||||||
/* must hold lock when calling this (except if connection->finalizing is TRUE) */
|
/* must hold lock when calling this (except if connection->finalizing is TRUE)
|
||||||
static void
|
* returns the number of removed subscribers */
|
||||||
|
static guint
|
||||||
unsubscribe_id_internal (GDBusConnection *connection,
|
unsubscribe_id_internal (GDBusConnection *connection,
|
||||||
guint subscription_id,
|
guint subscription_id)
|
||||||
GPtrArray *out_removed_subscribers)
|
|
||||||
{
|
{
|
||||||
SignalData *signal_data;
|
SignalData *signal_data;
|
||||||
GPtrArray *signal_data_array;
|
GPtrArray *signal_data_array;
|
||||||
guint n;
|
guint n;
|
||||||
|
guint n_removed = 0;
|
||||||
|
|
||||||
signal_data = g_hash_table_lookup (connection->map_id_to_signal_data,
|
signal_data = g_hash_table_lookup (connection->map_id_to_signal_data,
|
||||||
GUINT_TO_POINTER (subscription_id));
|
GUINT_TO_POINTER (subscription_id));
|
||||||
@ -3631,7 +3632,7 @@ unsubscribe_id_internal (GDBusConnection *connection,
|
|||||||
* guaranteed to be unique. */
|
* guaranteed to be unique. */
|
||||||
g_warn_if_fail (g_hash_table_remove (connection->map_id_to_signal_data,
|
g_warn_if_fail (g_hash_table_remove (connection->map_id_to_signal_data,
|
||||||
GUINT_TO_POINTER (subscription_id)));
|
GUINT_TO_POINTER (subscription_id)));
|
||||||
g_ptr_array_add (out_removed_subscribers, signal_subscriber_ref (subscriber));
|
n_removed++;
|
||||||
g_ptr_array_remove_index_fast (signal_data->subscribers, n);
|
g_ptr_array_remove_index_fast (signal_data->subscribers, n);
|
||||||
|
|
||||||
if (signal_data->subscribers->len == 0)
|
if (signal_data->subscribers->len == 0)
|
||||||
@ -3673,7 +3674,7 @@ unsubscribe_id_internal (GDBusConnection *connection,
|
|||||||
g_assert_not_reached ();
|
g_assert_not_reached ();
|
||||||
|
|
||||||
out:
|
out:
|
||||||
;
|
return n_removed;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -3690,23 +3691,17 @@ void
|
|||||||
g_dbus_connection_signal_unsubscribe (GDBusConnection *connection,
|
g_dbus_connection_signal_unsubscribe (GDBusConnection *connection,
|
||||||
guint subscription_id)
|
guint subscription_id)
|
||||||
{
|
{
|
||||||
GPtrArray *subscribers;
|
guint n_subscribers_removed G_GNUC_UNUSED /* when compiling with G_DISABLE_ASSERT */;
|
||||||
|
|
||||||
g_return_if_fail (G_IS_DBUS_CONNECTION (connection));
|
g_return_if_fail (G_IS_DBUS_CONNECTION (connection));
|
||||||
g_return_if_fail (check_initialized (connection));
|
g_return_if_fail (check_initialized (connection));
|
||||||
|
|
||||||
subscribers = g_ptr_array_new_with_free_func ((GDestroyNotify) signal_subscriber_unref);
|
|
||||||
|
|
||||||
CONNECTION_LOCK (connection);
|
CONNECTION_LOCK (connection);
|
||||||
unsubscribe_id_internal (connection,
|
n_subscribers_removed = unsubscribe_id_internal (connection, subscription_id);
|
||||||
subscription_id,
|
|
||||||
subscribers);
|
|
||||||
CONNECTION_UNLOCK (connection);
|
CONNECTION_UNLOCK (connection);
|
||||||
|
|
||||||
/* invariant */
|
/* invariant */
|
||||||
g_assert (subscribers->len == 0 || subscribers->len == 1);
|
g_assert (n_subscribers_removed == 0 || n_subscribers_removed == 1);
|
||||||
|
|
||||||
g_ptr_array_unref (subscribers);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ---------------------------------------------------------------------------------------------------- */
|
/* ---------------------------------------------------------------------------------------------------- */
|
||||||
@ -3969,7 +3964,6 @@ purge_all_signal_subscriptions (GDBusConnection *connection)
|
|||||||
GHashTableIter iter;
|
GHashTableIter iter;
|
||||||
gpointer key;
|
gpointer key;
|
||||||
GArray *ids;
|
GArray *ids;
|
||||||
GPtrArray *subscribers;
|
|
||||||
guint n;
|
guint n;
|
||||||
|
|
||||||
ids = g_array_new (FALSE, FALSE, sizeof (guint));
|
ids = g_array_new (FALSE, FALSE, sizeof (guint));
|
||||||
@ -3980,17 +3974,12 @@ purge_all_signal_subscriptions (GDBusConnection *connection)
|
|||||||
g_array_append_val (ids, subscription_id);
|
g_array_append_val (ids, subscription_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
subscribers = g_ptr_array_new_with_free_func ((GDestroyNotify) signal_subscriber_unref);
|
|
||||||
for (n = 0; n < ids->len; n++)
|
for (n = 0; n < ids->len; n++)
|
||||||
{
|
{
|
||||||
guint subscription_id = g_array_index (ids, guint, n);
|
guint subscription_id = g_array_index (ids, guint, n);
|
||||||
unsubscribe_id_internal (connection,
|
unsubscribe_id_internal (connection, subscription_id);
|
||||||
subscription_id,
|
|
||||||
subscribers);
|
|
||||||
}
|
}
|
||||||
g_array_free (ids, TRUE);
|
g_array_free (ids, TRUE);
|
||||||
|
|
||||||
g_ptr_array_unref (subscribers);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ---------------------------------------------------------------------------------------------------- */
|
/* ---------------------------------------------------------------------------------------------------- */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user