mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-02-26 12:12:10 +01:00
use g_timeout_add_seconds_once()
Use the newly added g_timeout_add_seconds_once() where appropriate.
This commit is contained in:
parent
467b917719
commit
e25a4f995f
@ -62,13 +62,12 @@ typedef struct
|
||||
gboolean timed_out;
|
||||
} WeakNotifyData;
|
||||
|
||||
static gboolean
|
||||
static void
|
||||
on_weak_notify_timeout (gpointer user_data)
|
||||
{
|
||||
WeakNotifyData *data = user_data;
|
||||
data->timed_out = TRUE;
|
||||
g_main_loop_quit (data->loop);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
@ -95,7 +94,7 @@ _g_object_unref_and_wait_weak_notify (gpointer object)
|
||||
g_idle_add (unref_on_idle, object);
|
||||
|
||||
/* Make sure we don't block forever */
|
||||
timeout_id = g_timeout_add_seconds (30, on_weak_notify_timeout, &data);
|
||||
timeout_id = g_timeout_add_seconds_once (30, on_weak_notify_timeout, &data);
|
||||
|
||||
g_main_loop_run (data.loop);
|
||||
|
||||
|
@ -452,15 +452,13 @@ created_cb (GObject *source,
|
||||
data);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
static void
|
||||
stop_timeout (gpointer user_data)
|
||||
{
|
||||
CreateDeleteData *data = user_data;
|
||||
|
||||
data->timed_out = TRUE;
|
||||
g_main_context_wakeup (data->context);
|
||||
|
||||
return G_SOURCE_REMOVE;
|
||||
}
|
||||
|
||||
/*
|
||||
@ -518,7 +516,7 @@ test_create_delete (gconstpointer d)
|
||||
|
||||
/* Use the global default main context */
|
||||
data->context = NULL;
|
||||
data->timeout = g_timeout_add_seconds (10, stop_timeout, data);
|
||||
data->timeout = g_timeout_add_seconds_once (10, stop_timeout, data);
|
||||
|
||||
g_file_create_async (data->file, 0, 0, NULL, created_cb, data);
|
||||
|
||||
|
@ -1117,15 +1117,13 @@ activate (gpointer data)
|
||||
/* GApplication complains if we don't connect to ::activate */
|
||||
}
|
||||
|
||||
static gboolean
|
||||
static void
|
||||
quit_already (gpointer user_data)
|
||||
{
|
||||
TestReplaceData *data = user_data;
|
||||
|
||||
g_application_quit (data->app);
|
||||
data->timeout_id = 0;
|
||||
|
||||
return G_SOURCE_REMOVE;
|
||||
}
|
||||
|
||||
static void
|
||||
@ -1177,7 +1175,7 @@ test_replace (gconstpointer data)
|
||||
g_signal_connect (app, "activate", G_CALLBACK (activate), NULL);
|
||||
|
||||
if (!allow)
|
||||
data.timeout_id = g_timeout_add_seconds (1, quit_already, &data);
|
||||
data.timeout_id = g_timeout_add_seconds_once (1, quit_already, &data);
|
||||
|
||||
g_application_run (app, G_N_ELEMENTS (argv) - 1, argv);
|
||||
|
||||
|
@ -128,14 +128,12 @@ test_connection_flush (void)
|
||||
/* the test will fail if the service name has not appeared after this amount of seconds */
|
||||
#define LARGE_MESSAGE_TIMEOUT_SECONDS 10
|
||||
|
||||
static gboolean
|
||||
static void
|
||||
large_message_timeout_cb (gpointer data)
|
||||
{
|
||||
(void)data;
|
||||
|
||||
g_error ("Error: timeout waiting for dbus name to appear");
|
||||
|
||||
return G_SOURCE_REMOVE;
|
||||
}
|
||||
|
||||
static void
|
||||
@ -200,9 +198,9 @@ test_connection_large_message (void)
|
||||
/* this is safe; testserver will exit once the bus goes away */
|
||||
g_assert (g_spawn_command_line_async (g_test_get_filename (G_TEST_BUILT, "gdbus-testserver", NULL), NULL));
|
||||
|
||||
timeout_id = g_timeout_add_seconds (LARGE_MESSAGE_TIMEOUT_SECONDS,
|
||||
large_message_timeout_cb,
|
||||
NULL);
|
||||
timeout_id = g_timeout_add_seconds_once (LARGE_MESSAGE_TIMEOUT_SECONDS,
|
||||
large_message_timeout_cb,
|
||||
NULL);
|
||||
|
||||
watcher_id = g_bus_watch_name (G_BUS_TYPE_SESSION,
|
||||
"com.example.TestService",
|
||||
|
@ -7,12 +7,10 @@
|
||||
|
||||
#include "glib/glib-private.h"
|
||||
|
||||
static gboolean
|
||||
static void
|
||||
time_out (gpointer unused G_GNUC_UNUSED)
|
||||
{
|
||||
g_error ("Timed out");
|
||||
/* not reached */
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static guint
|
||||
@ -22,7 +20,7 @@ add_timeout (guint seconds)
|
||||
/* Safety-catch against the main loop having blocked */
|
||||
alarm (seconds + 5);
|
||||
#endif
|
||||
return g_timeout_add_seconds (seconds, time_out, NULL);
|
||||
return g_timeout_add_seconds_once (seconds, time_out, NULL);
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -1288,14 +1288,12 @@ test_communicate_utf8_invalid (void)
|
||||
g_object_unref (proc);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
static void
|
||||
send_terminate (gpointer user_data)
|
||||
{
|
||||
GSubprocess *proc = user_data;
|
||||
|
||||
g_subprocess_force_exit (proc);
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static void
|
||||
@ -1341,7 +1339,7 @@ test_terminate (void)
|
||||
|
||||
g_subprocess_wait_async (proc, NULL, on_request_quit_exited, loop);
|
||||
|
||||
g_timeout_add_seconds (3, send_terminate, proc);
|
||||
g_timeout_add_seconds_once (3, send_terminate, proc);
|
||||
|
||||
g_main_loop_run (loop);
|
||||
|
||||
@ -1350,14 +1348,12 @@ test_terminate (void)
|
||||
}
|
||||
|
||||
#ifdef G_OS_UNIX
|
||||
static gboolean
|
||||
static void
|
||||
send_signal (gpointer user_data)
|
||||
{
|
||||
GSubprocess *proc = user_data;
|
||||
|
||||
g_subprocess_send_signal (proc, SIGKILL);
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static void
|
||||
@ -1378,7 +1374,7 @@ test_signal (void)
|
||||
|
||||
g_subprocess_wait_async (proc, NULL, on_request_quit_exited, loop);
|
||||
|
||||
g_timeout_add_seconds (3, send_signal, proc);
|
||||
g_timeout_add_seconds_once (3, send_signal, proc);
|
||||
|
||||
g_main_loop_run (loop);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user