diff --git a/docs/reference/glib/glib-sections.txt b/docs/reference/glib/glib-sections.txt index 882ce1e25..888886aba 100644 --- a/docs/reference/glib/glib-sections.txt +++ b/docs/reference/glib/glib-sections.txt @@ -1265,6 +1265,7 @@ g_timer_continue g_timer_elapsed g_timer_reset g_timer_destroy +g_timer_is_active
diff --git a/glib/gtimer.c b/glib/gtimer.c index 4f66826ae..6b012549b 100644 --- a/glib/gtimer.c +++ b/glib/gtimer.c @@ -236,6 +236,23 @@ g_timer_elapsed (GTimer *timer, return total; } +/** + * g_timer_is_active: + * @timer: a #GTimer. + * + * Exposes whether the timer is currently active. + * + * Returns: %TRUE if the timer is running, %FALSE otherwise + * Since: 2.62 + **/ +gboolean +g_timer_is_active (GTimer *timer) +{ + g_return_val_if_fail (timer != NULL, FALSE); + + return timer->active; +} + /** * g_usleep: * @microseconds: number of microseconds to pause diff --git a/glib/gtimer.h b/glib/gtimer.h index 5699b6964..25679f331 100644 --- a/glib/gtimer.h +++ b/glib/gtimer.h @@ -56,6 +56,8 @@ void g_timer_continue (GTimer *timer); GLIB_AVAILABLE_IN_ALL gdouble g_timer_elapsed (GTimer *timer, gulong *microseconds); +GLIB_AVAILABLE_IN_2_62 +gboolean g_timer_is_active (GTimer *timer); GLIB_AVAILABLE_IN_ALL void g_usleep (gulong microseconds); diff --git a/glib/tests/timer.c b/glib/tests/timer.c index 5b2e71144..01e4dc3dd 100644 --- a/glib/tests/timer.c +++ b/glib/tests/timer.c @@ -98,6 +98,22 @@ test_timer_reset (void) g_timer_destroy (timer); } +static void +test_timer_is_active (void) +{ + GTimer *timer; + gboolean is_active; + + timer = g_timer_new (); + is_active = g_timer_is_active (timer); + g_assert_true (is_active); + g_timer_stop (timer); + is_active = g_timer_is_active (timer); + g_assert_false (is_active); + + g_timer_destroy (timer); +} + static void test_timeval_add (void) { @@ -282,6 +298,7 @@ main (int argc, char *argv[]) g_test_add_func ("/timer/stop", test_timer_stop); g_test_add_func ("/timer/continue", test_timer_continue); g_test_add_func ("/timer/reset", test_timer_reset); + g_test_add_func ("/timer/is_active", test_timer_is_active); g_test_add_func ("/timeval/add", test_timeval_add); g_test_add_func ("/timeval/from-iso8601", test_timeval_from_iso8601); g_test_add_func ("/timeval/to-iso8601", test_timeval_to_iso8601);