[glib/ebassi/source-once: 2/3] Port various timeout/idle callbacks to the once API




commit 50c316ef36412ff6b3e55f381879645dd02ee3d9
Author: Emmanuele Bassi <ebassi gnome org>
Date:   Tue May 24 17:10:32 2022 +0100

    Port various timeout/idle callbacks to the once API
    
    So we excercise it in our test coverage.

 glib/tests/mapping.c | 5 ++---
 glib/tests/timeout.c | 8 +++-----
 glib/tests/utils.c   | 7 +++----
 3 files changed, 8 insertions(+), 12 deletions(-)
---
diff --git a/glib/tests/mapping.c b/glib/tests/mapping.c
index 2ad63d296c..ea3495cd0f 100644
--- a/glib/tests/mapping.c
+++ b/glib/tests/mapping.c
@@ -85,13 +85,12 @@ map_or_die (const gchar *filename,
   return map;
 }
 
-static gboolean
+static void
 signal_parent (gpointer data)
 {
 #ifndef G_OS_WIN32
   kill (parent_pid, SIGUSR1);
 #endif
-  return G_SOURCE_REMOVE;
 }
 
 static void
@@ -113,7 +112,7 @@ child_main (void)
 #endif
   loop = g_main_loop_new (NULL, FALSE);
   g_idle_add (check_stop, loop);
-  g_idle_add (signal_parent, NULL);
+  g_idle_add_once (signal_parent, NULL);
   g_main_loop_run (loop);
 
   g_test_message ("test_child_private: received parent signal");
diff --git a/glib/tests/timeout.c b/glib/tests/timeout.c
index 9e4d047a60..acbb8f3e16 100644
--- a/glib/tests/timeout.c
+++ b/glib/tests/timeout.c
@@ -5,12 +5,10 @@
 
 static GMainLoop *loop;
 
-static gboolean
+static void
 stop_waiting (gpointer data)
 {
   g_main_loop_quit (loop);
-
-  return G_SOURCE_REMOVE;
 }
 
 static gboolean
@@ -44,7 +42,7 @@ test_seconds (void)
   g_test_bug ("https://bugzilla.gnome.org/show_bug.cgi?id=642052";);
   loop = g_main_loop_new (NULL, FALSE);
 
-  g_timeout_add (2100, stop_waiting, NULL);
+  g_timeout_add_once (2100, stop_waiting, NULL);
   id = g_timeout_add_seconds (21475, unreachable_callback, NULL);
 
   g_main_loop_run (loop);
@@ -81,7 +79,7 @@ test_weeks_overflow (void)
   g_test_bug ("https://gitlab.gnome.org/GNOME/glib/issues/1600";);
   loop = g_main_loop_new (NULL, FALSE);
 
-  g_timeout_add (2100, stop_waiting, NULL);
+  g_timeout_add_once (2100, stop_waiting, NULL);
   interval_seconds = 1 + G_MAXUINT / 1000;
   id = g_timeout_add_seconds (interval_seconds, unreachable_callback, NULL);
 
diff --git a/glib/tests/utils.c b/glib/tests/utils.c
index 11fed555ad..6318e19161 100644
--- a/glib/tests/utils.c
+++ b/glib/tests/utils.c
@@ -767,11 +767,10 @@ test_os_info (void)
   g_free (contents);
 }
 
-static gboolean
+static void
 source_test (gpointer data)
 {
   g_assert_not_reached ();
-  return G_SOURCE_REMOVE;
 }
 
 static void
@@ -779,13 +778,13 @@ test_clear_source (void)
 {
   guint id;
 
-  id = g_idle_add (source_test, NULL);
+  id = g_idle_add_once (source_test, NULL);
   g_assert_cmpuint (id, >, 0);
 
   g_clear_handle_id (&id, g_source_remove);
   g_assert_cmpuint (id, ==, 0);
 
-  id = g_timeout_add (100, source_test, NULL);
+  id = g_timeout_add_once (100, source_test, NULL);
   g_assert_cmpuint (id, >, 0);
 
   g_clear_handle_id (&id, g_source_remove);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]