[glib: 1/2] Add g_timer_is_active
- From: Philip Withnall <pwithnall src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib: 1/2] Add g_timer_is_active
- Date: Fri, 21 Jun 2019 10:22:58 +0000 (UTC)
commit b9988e5fc9fe6ace560874d6dfc7d6179ac81409
Author: Tristan Partin <tristan partin gmail com>
Date: Fri Jun 21 10:22:41 2019 +0000
Add g_timer_is_active
Helper function for exposing the internal state of a GTimer.
docs/reference/glib/glib-sections.txt | 1 +
glib/gtimer.c | 17 +++++++++++++++++
glib/gtimer.h | 2 ++
glib/tests/timer.c | 17 +++++++++++++++++
4 files changed, 37 insertions(+)
---
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
</SECTION>
<SECTION>
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);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]