mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-05-17 19:21:58 +02:00
add g_timeout_add_seconds_once
Add a new call combing behaviors of g_timeout_add_seconds and g_timeout_add_once.
This commit is contained in:
parent
c86fde7e02
commit
3abf23b2a7
@ -586,6 +586,7 @@ g_timeout_add_once
|
|||||||
g_timeout_add_full
|
g_timeout_add_full
|
||||||
g_timeout_add_seconds
|
g_timeout_add_seconds
|
||||||
g_timeout_add_seconds_full
|
g_timeout_add_seconds_full
|
||||||
|
g_timeout_add_seconds_once
|
||||||
|
|
||||||
<SUBSECTION>
|
<SUBSECTION>
|
||||||
g_idle_source_new
|
g_idle_source_new
|
||||||
|
20
glib/gmain.c
20
glib/gmain.c
@ -5471,6 +5471,26 @@ g_timeout_add_seconds (guint interval,
|
|||||||
return g_timeout_add_seconds_full (G_PRIORITY_DEFAULT, interval, function, data, NULL);
|
return g_timeout_add_seconds_full (G_PRIORITY_DEFAULT, interval, function, data, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* g_timeout_add_seconds_once:
|
||||||
|
* @interval: the time after which the function will be called, in seconds
|
||||||
|
* @function: function to call
|
||||||
|
* @data: data to pass to @function
|
||||||
|
*
|
||||||
|
* This function behaves like g_timeout_add_once() but with a range in seconds.
|
||||||
|
*
|
||||||
|
* Returns: the ID (greater than 0) of the event source
|
||||||
|
*
|
||||||
|
* Since: 2.78
|
||||||
|
*/
|
||||||
|
guint
|
||||||
|
g_timeout_add_seconds_once (guint interval,
|
||||||
|
GSourceOnceFunc function,
|
||||||
|
gpointer data)
|
||||||
|
{
|
||||||
|
return timeout_add_full (G_PRIORITY_DEFAULT, interval, TRUE, TRUE, (GSourceFunc) function, data, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
/* Child watch functions */
|
/* Child watch functions */
|
||||||
|
|
||||||
#ifdef G_OS_WIN32
|
#ifdef G_OS_WIN32
|
||||||
|
@ -800,6 +800,10 @@ GLIB_AVAILABLE_IN_ALL
|
|||||||
guint g_timeout_add_seconds (guint interval,
|
guint g_timeout_add_seconds (guint interval,
|
||||||
GSourceFunc function,
|
GSourceFunc function,
|
||||||
gpointer data);
|
gpointer data);
|
||||||
|
GLIB_AVAILABLE_IN_2_78
|
||||||
|
guint g_timeout_add_seconds_once (guint interval,
|
||||||
|
GSourceOnceFunc function,
|
||||||
|
gpointer data);
|
||||||
GLIB_AVAILABLE_IN_ALL
|
GLIB_AVAILABLE_IN_ALL
|
||||||
guint g_child_watch_add_full (gint priority,
|
guint g_child_watch_add_full (gint priority,
|
||||||
GPid pid,
|
GPid pid,
|
||||||
|
@ -19,6 +19,12 @@ unreachable_callback (gpointer data)
|
|||||||
return G_SOURCE_REMOVE;
|
return G_SOURCE_REMOVE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
unreachable_void_callback (gpointer data)
|
||||||
|
{
|
||||||
|
g_assert_not_reached ();
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
test_seconds (void)
|
test_seconds (void)
|
||||||
{
|
{
|
||||||
@ -51,6 +57,19 @@ test_seconds (void)
|
|||||||
g_source_remove (id);
|
g_source_remove (id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
test_seconds_once (void)
|
||||||
|
{
|
||||||
|
/* Use the same principle as in test_seconds() */
|
||||||
|
loop = g_main_loop_new (NULL, FALSE);
|
||||||
|
|
||||||
|
g_timeout_add_once (2100, stop_waiting, NULL);
|
||||||
|
g_timeout_add_seconds_once (21475, unreachable_void_callback, NULL);
|
||||||
|
|
||||||
|
g_main_loop_run (loop);
|
||||||
|
g_main_loop_unref (loop);
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
test_weeks_overflow (void)
|
test_weeks_overflow (void)
|
||||||
{
|
{
|
||||||
@ -192,6 +211,7 @@ main (int argc, char *argv[])
|
|||||||
g_test_init (&argc, &argv, NULL);
|
g_test_init (&argc, &argv, NULL);
|
||||||
|
|
||||||
g_test_add_func ("/timeout/seconds", test_seconds);
|
g_test_add_func ("/timeout/seconds", test_seconds);
|
||||||
|
g_test_add_func ("/timeout/seconds-once", test_seconds_once);
|
||||||
g_test_add_func ("/timeout/weeks-overflow", test_weeks_overflow);
|
g_test_add_func ("/timeout/weeks-overflow", test_weeks_overflow);
|
||||||
g_test_add_func ("/timeout/far-future-ready-time", test_far_future_ready_time);
|
g_test_add_func ("/timeout/far-future-ready-time", test_far_future_ready_time);
|
||||||
g_test_add_func ("/timeout/rounding", test_rounding);
|
g_test_add_func ("/timeout/rounding", test_rounding);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user