Merge branch '2925-gdbus-threading-test' into 'main'

gdbusconnection: Explicitly destroy an idle source on cleanup

See merge request GNOME/glib!3296
This commit is contained in:
Simon McVittie 2023-03-02 12:35:21 +00:00
commit 6c22a5ee2b
2 changed files with 18 additions and 10 deletions

View File

@ -1750,6 +1750,7 @@ typedef struct
guint32 serial;
gulong cancellable_handler_id;
GSource *cancelled_idle_source; /* (owned) (nullable) */
GSource *timeout_source;
@ -1791,6 +1792,11 @@ send_message_with_reply_cleanup (GTask *task, gboolean remove)
g_cancellable_disconnect (g_task_get_cancellable (task), data->cancellable_handler_id);
data->cancellable_handler_id = 0;
}
if (data->cancelled_idle_source != NULL)
{
g_source_destroy (data->cancelled_idle_source);
g_clear_pointer (&data->cancelled_idle_source, g_source_unref);
}
if (remove)
{
@ -1857,7 +1863,7 @@ send_message_with_reply_cancelled_idle_cb (gpointer user_data)
send_message_data_deliver_error (task, G_IO_ERROR, G_IO_ERROR_CANCELLED,
_("Operation was cancelled"));
return FALSE;
return G_SOURCE_REMOVE;
}
/* Can be called from any thread with or without lock held */
@ -1866,15 +1872,17 @@ send_message_with_reply_cancelled_cb (GCancellable *cancellable,
gpointer user_data)
{
GTask *task = user_data;
GSource *idle_source;
SendMessageData *data = g_task_get_task_data (task);
/* postpone cancellation to idle handler since we may be called directly
* via g_cancellable_connect() (e.g. holding lock)
*/
idle_source = g_idle_source_new ();
g_source_set_static_name (idle_source, "[gio] send_message_with_reply_cancelled_idle_cb");
g_task_attach_source (task, idle_source, send_message_with_reply_cancelled_idle_cb);
g_source_unref (idle_source);
if (data->cancelled_idle_source != NULL)
return;
data->cancelled_idle_source = g_idle_source_new ();
g_source_set_static_name (data->cancelled_idle_source, "[gio] send_message_with_reply_cancelled_idle_cb");
g_task_attach_source (task, data->cancelled_idle_source, send_message_with_reply_cancelled_idle_cb);
}
/* ---------------------------------------------------------------------------------------------------- */

View File

@ -1469,7 +1469,7 @@ typedef struct
GCancellable *enumeration_parent_cancellable; /* (nullable) (owned) */
gulong enumeration_cancelled_id;
GSList *connection_attempts;
GSList *connection_attempts; /* (element-type ConnectionAttempt) (owned) */
GSList *successful_connections;
SocketClientErrorInfo *error_info;
@ -1874,7 +1874,7 @@ g_socket_client_connected_callback (GObject *source,
GAsyncResult *result,
gpointer user_data)
{
ConnectionAttempt *attempt = user_data;
ConnectionAttempt *attempt = g_steal_pointer (&user_data);
GSocketClientAsyncConnectData *data = attempt->data;
if (task_completed_or_cancelled (data) || g_cancellable_is_cancelled (attempt->cancellable))
@ -2032,7 +2032,7 @@ g_socket_client_enumerator_callback (GObject *object,
g_source_set_callback (attempt->timeout_source, on_connection_attempt_timeout, attempt, NULL);
g_source_attach (attempt->timeout_source, g_task_get_context (data->task));
data->connection_attempts = g_slist_append (data->connection_attempts, attempt);
data->connection_attempts = g_slist_append (data->connection_attempts, connection_attempt_ref (attempt));
if (g_task_get_cancellable (data->task))
{
@ -2048,7 +2048,7 @@ g_socket_client_enumerator_callback (GObject *object,
g_socket_connection_connect_async (G_SOCKET_CONNECTION (attempt->connection),
address,
attempt->cancellable,
g_socket_client_connected_callback, connection_attempt_ref (attempt));
g_socket_client_connected_callback, attempt /* transfer full */);
}
/**