From f9668b92e4ca2b3623b7b4af8ba78df546f7eadc Mon Sep 17 00:00:00 2001 From: Philip Withnall Date: Sun, 25 Aug 2024 17:39:50 +0100 Subject: [PATCH] Revert "gio/tests: Ensure that a GCancellableSource can be used muliple times" This reverts commit 0a8cb10f224ff2dfed14f6500e77cee68ae7d4c4. Merge request !2765 has caused a thread safety regression in `GCancellableSource` disposal. It landed too late in the cycle to fix with any confidence before the 2.82 release, so the changes are being reverted for the `glib-2-82` branch and 2.82.0 release. Fixes: #3448 Re-opens: #774, #2309, #2313 --- gio/gcancellable.c | 8 ++---- gio/tests/cancellable.c | 64 ----------------------------------------- 2 files changed, 3 insertions(+), 69 deletions(-) diff --git a/gio/gcancellable.c b/gio/gcancellable.c index c3572910e..41ffab322 100644 --- a/gio/gcancellable.c +++ b/gio/gcancellable.c @@ -541,11 +541,9 @@ g_cancellable_cancel (GCancellable *cancellable) * signal. Also handles the race condition that may happen * if the cancellable is cancelled right before connecting. * - * @callback is called exactly once each time @cancellable is cancelled, - * either directly at the time of the connect if @cancellable is already - * cancelled, or when @cancellable is cancelled in some thread. - * In case the cancellable is reset via [method@Gio.Cancellable.reset] - * then the callback can be called again if the @cancellable is cancelled. + * @callback is called at most once, either directly at the + * time of the connect if @cancellable is already cancelled, + * or when @cancellable is cancelled in some thread. * * @data_destroy_func will be called when the handler is * disconnected, or immediately if the cancellable is already diff --git a/gio/tests/cancellable.c b/gio/tests/cancellable.c index aaf992792..b7be395bc 100644 --- a/gio/tests/cancellable.c +++ b/gio/tests/cancellable.c @@ -810,69 +810,6 @@ test_cancellable_cancel_reset_connect_races (void) g_object_unref (cancellable); } -static gboolean -source_cancelled_counter_cb (GCancellable *cancellable, - gpointer user_data) -{ - guint *n_calls = user_data; - - *n_calls = *n_calls + 1; - - return G_SOURCE_CONTINUE; -} - -static void -do_nothing (G_GNUC_UNUSED void *user_data) -{ - /* An empty timeout/idle once callback function */ -} - -static void -test_cancellable_source_can_be_fired_multiple_times (void) -{ - GCancellable *cancellable; - GSource *source; - guint n_calls = 0; - - g_test_summary ("Test a cancellable source callback can be called multiple times"); - g_test_bug ("https://gitlab.gnome.org/GNOME/glib/issues/774"); - - cancellable = g_cancellable_new (); - source = g_cancellable_source_new (cancellable); - - g_source_set_callback (source, G_SOURCE_FUNC (source_cancelled_counter_cb), - &n_calls, NULL); - g_source_attach (source, NULL); - - g_cancellable_cancel (cancellable); - g_assert_cmpuint (n_calls, ==, 0); - - while (g_main_context_pending (NULL)) - g_main_context_iteration (NULL, TRUE); - - g_assert_cmpuint (n_calls, ==, 1); - - g_cancellable_cancel (cancellable); - - g_timeout_add_once (100, do_nothing, NULL); - while (g_main_context_pending (NULL)) - g_main_context_iteration (NULL, TRUE); - - g_assert_cmpuint (n_calls, ==, 1); - - g_cancellable_reset (cancellable); - g_cancellable_cancel (cancellable); - g_assert_cmpuint (n_calls, ==, 1); - - while (g_main_context_pending (NULL)) - g_main_context_iteration (NULL, TRUE); - - g_assert_cmpuint (n_calls, ==, 2); - - g_source_unref (source); - g_object_unref (cancellable); -} - int main (int argc, char *argv[]) { @@ -888,7 +825,6 @@ main (int argc, char *argv[]) g_test_add_func ("/cancellable/cancel-reset-races", test_cancellable_cancel_reset_races); g_test_add_func ("/cancellable/cancel-reset-connect-races", test_cancellable_cancel_reset_connect_races); g_test_add_func ("/cancellable-source/threaded-dispose", test_cancellable_source_threaded_dispose); - g_test_add_func ("/cancellable-source/can-be-fired-multiple-times", test_cancellable_source_can_be_fired_multiple_times); return g_test_run (); }