Merge branch 'master' into 'master'

Add g_timer_is_active

Closes #1794

See merge request GNOME/glib!929
This commit is contained in:
Philip Withnall 2019-06-21 10:22:42 +00:00
commit 1bd72404ba
4 changed files with 37 additions and 0 deletions

View File

@ -1265,6 +1265,7 @@ g_timer_continue
g_timer_elapsed
g_timer_reset
g_timer_destroy
g_timer_is_active
</SECTION>
<SECTION>

View File

@ -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

View File

@ -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);

View File

@ -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);